Merge pull request #5284 from annando/item-content
The fetch function now centrally controls the content
This commit is contained in:
commit
258683b49a
14 changed files with 56 additions and 43 deletions
|
@ -2078,7 +2078,7 @@ function api_statuses_mentions($type)
|
|||
$start = ($page - 1) * $count;
|
||||
|
||||
$condition = ["`uid` = ? AND `verb` = ? AND `item`.`id` > ? AND `author-id` != ?
|
||||
AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `uid` = ? AND `mention` AND NOT `ignored`)",
|
||||
AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `thread`.`uid` = ? AND `thread`.`mention` AND NOT `thread`.`ignored`)",
|
||||
api_user(), ACTIVITY_POST, $since_id, $user_info['pid'], api_user()];
|
||||
|
||||
if ($max_id > 0) {
|
||||
|
|
|
@ -562,15 +562,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
|
|||
continue;
|
||||
}
|
||||
|
||||
if ($item['network'] == NETWORK_FEED) {
|
||||
$item['author-avatar'] = $item['contact-avatar'];
|
||||
$item['author-name'] = $item['contact-name'];
|
||||
$item['owner-avatar'] = $item['contact-avatar'];
|
||||
$item['owner-name'] = $item['contact-name'];
|
||||
}
|
||||
|
||||
$profile_name = (strlen($item['author-name']) ? $item['author-name'] : $item['name']);
|
||||
if ($item['author-link'] && !$item['author-name']) {
|
||||
$profile_name = $item['author-name'];
|
||||
if (!empty($item['author-link']) && empty($item['author-name'])) {
|
||||
$profile_name = $item['author-link'];
|
||||
}
|
||||
|
||||
|
|
|
@ -260,7 +260,7 @@ function acl_content(App $a)
|
|||
$params = ['order' => ['author-name' => true]];
|
||||
$authors = Item::selectForUser(local_user(), ['author-link'], $condition, $params);
|
||||
$item_authors = [];
|
||||
while ($author = dba::fetch($authors)) {
|
||||
while ($author = Item::fetch($authors)) {
|
||||
$item_authors[$author['author-link']] = $author['author-link'];
|
||||
}
|
||||
dba::close($authors);
|
||||
|
|
|
@ -347,7 +347,7 @@ function display_content(App $a, $update = false, $update_uid = 0)
|
|||
Item::update(['unseen' => false], $condition);
|
||||
}
|
||||
|
||||
$items = conv_sort(dba::inArray($items_obj), "`commented`");
|
||||
$items = conv_sort(Item::inArray($items_obj), "`commented`");
|
||||
|
||||
if (!$update) {
|
||||
$o .= "<script> var netargs = '?f=&item_id=" . $item_id . "'; </script>";
|
||||
|
|
|
@ -456,7 +456,7 @@ function networkFlatView(App $a, $update = 0)
|
|||
|
||||
$params = ['order' => ['id' => true], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
|
||||
$result = Item::selectForUser(local_user(), [], $condition, $params);
|
||||
$items = dba::inArray($result);
|
||||
$items = Item::inArray($result);
|
||||
|
||||
$condition = ['unseen' => true, 'uid' => local_user()];
|
||||
networkSetSeen($condition);
|
||||
|
|
|
@ -73,7 +73,7 @@ function notes_content(App $a, $update = false)
|
|||
if (DBM::is_result($r)) {
|
||||
$parents_arr = [];
|
||||
|
||||
while ($rr = dba::fetch($r)) {
|
||||
while ($rr = Item::fetch($r)) {
|
||||
$parents_arr[] = $rr['item_id'];
|
||||
}
|
||||
dba::close($r);
|
||||
|
@ -81,7 +81,7 @@ function notes_content(App $a, $update = false)
|
|||
$condition = ['uid' => local_user(), 'parent' => $parents_arr];
|
||||
$result = Item::selectForUser(local_user(), [], $condition);
|
||||
if (DBM::is_result($result)) {
|
||||
$items = conv_sort(dba::inArray($result), 'commented');
|
||||
$items = conv_sort(Item::inArray($result), 'commented');
|
||||
$o .= conversation($a, $items, 'notes', $update);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ function ping_init(App $a)
|
|||
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
|
||||
|
||||
if (DBM::is_result($items)) {
|
||||
$items_unseen = dba::inArray($items);
|
||||
$items_unseen = Item::inArray($items);
|
||||
$arr = ['items' => $items_unseen];
|
||||
Addon::callHooks('network_ping', $arr);
|
||||
|
||||
|
|
|
@ -339,7 +339,7 @@ function profile_content(App $a, $update = 0)
|
|||
|
||||
$condition = ['uid' => $a->profile['profile_uid'], 'parent' => $parents_arr];
|
||||
$result = Item::selectForUser($a->profile['profile_uid'], [], $condition);
|
||||
$items = conv_sort(dba::inArray($result), 'created');
|
||||
$items = conv_sort(Item::inArray($result), 'created');
|
||||
} else {
|
||||
$items = [];
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ function search_content(App $a) {
|
|||
if (!empty($itemids)) {
|
||||
$params = ['order' => ['id' => true]];
|
||||
$items = Item::selectForUser(local_user(), [], ['id' => $itemids], $params);
|
||||
$r = dba::inArray($items);
|
||||
$r = Item::inArray($items);
|
||||
} else {
|
||||
$r = [];
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ function search_content(App $a) {
|
|||
$params = ['order' => ['id' => true],
|
||||
'limit' => [$a->pager['start'], $a->pager['itemspage']]];
|
||||
$items = Item::selectForUser(local_user(), [], $condition, $params);
|
||||
$r = dba::inArray($items);
|
||||
$r = Item::inArray($items);
|
||||
}
|
||||
|
||||
if (!DBM::is_result($r)) {
|
||||
|
|
|
@ -21,7 +21,7 @@ function starred_init(App $a) {
|
|||
killme();
|
||||
}
|
||||
|
||||
$item = Item::selectForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $message_id]);
|
||||
$item = Item::selectFirstForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $message_id]);
|
||||
if (!DBM::is_result($item)) {
|
||||
killme();
|
||||
}
|
||||
|
|
|
@ -410,7 +410,7 @@ class NotificationsManager extends BaseObject
|
|||
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
|
||||
|
||||
if (DBM::is_result($items)) {
|
||||
$notifs = $this->formatNotifs(dba::inArray($items), $ident);
|
||||
$notifs = $this->formatNotifs(Item::inArray($items), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
|
@ -495,7 +495,7 @@ class NotificationsManager extends BaseObject
|
|||
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
|
||||
|
||||
if (DBM::is_result($items)) {
|
||||
$notifs = $this->formatNotifs(dba::inArray($items), $ident);
|
||||
$notifs = $this->formatNotifs(Item::inArray($items), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
|
@ -535,7 +535,7 @@ class NotificationsManager extends BaseObject
|
|||
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
|
||||
|
||||
if (DBM::is_result($items)) {
|
||||
$notifs = $this->formatNotifs(dba::inArray($items), $ident);
|
||||
$notifs = $this->formatNotifs(Item::inArray($items), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
|
|
|
@ -1070,7 +1070,7 @@ class Contact extends BaseObject
|
|||
'limit' => [$a->pager['start'], $a->pager['itemspage']]];
|
||||
$r = Item::selectForUser(local_user(), [], $condition, $params);
|
||||
|
||||
$items = dba::inArray($r);
|
||||
$items = Item::inArray($r);
|
||||
|
||||
$o = conversation($a, $items, 'contact-posts', false);
|
||||
|
||||
|
|
|
@ -34,15 +34,15 @@ require_once 'include/text.php';
|
|||
class Item extends BaseObject
|
||||
{
|
||||
// Field list that is used to display the items
|
||||
const DISPLAY_FIELDLIST = ['uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid',
|
||||
const DISPLAY_FIELDLIST = ['uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid', 'network',
|
||||
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
|
||||
'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'attach',
|
||||
'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object',
|
||||
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'item_id',
|
||||
'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
|
||||
'author-id', 'author-link', 'author-name', 'author-avatar',
|
||||
'owner-id', 'owner-link', 'owner-name', 'owner-avatar',
|
||||
'contact-id', 'contact-link', 'contact-name', 'contact-avatar',
|
||||
'network', 'url', 'name', 'writable', 'self', 'cid', 'alias',
|
||||
'writable', 'self', 'cid', 'alias',
|
||||
'event-id', 'event-created', 'event-edited', 'event-start', 'event-finish',
|
||||
'event-summary', 'event-desc', 'event-location', 'event-type',
|
||||
'event-nofinish', 'event-adjust', 'event-ignore', 'event-id'];
|
||||
|
@ -66,6 +66,33 @@ class Item extends BaseObject
|
|||
{
|
||||
$row = dba::fetch($stmt);
|
||||
|
||||
// We prefer the data from the user's contact over the public one
|
||||
if (!empty($row['author-link']) && !empty($row['contact-link']) &&
|
||||
($row['author-link'] == $row['contact-link'])) {
|
||||
if (isset($row['author-avatar']) && !empty($row['contact-avatar'])) {
|
||||
$row['author-avatar'] = $row['contact-avatar'];
|
||||
}
|
||||
if (isset($row['author-name']) && !empty($row['contact-name'])) {
|
||||
$row['author-name'] = $row['contact-name'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($row['owner-link']) && !empty($row['contact-link']) &&
|
||||
($row['owner-link'] == $row['contact-link'])) {
|
||||
if (isset($row['owner-avatar']) && !empty($row['contact-avatar'])) {
|
||||
$row['owner-avatar'] = $row['contact-avatar'];
|
||||
}
|
||||
if (isset($row['owner-name']) && !empty($row['contact-name'])) {
|
||||
$row['owner-name'] = $row['contact-name'];
|
||||
}
|
||||
}
|
||||
|
||||
// We can always comment on posts from these networks
|
||||
if (isset($row['writable']) && !empty($row['network']) &&
|
||||
in_array($row['network'], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS])) {
|
||||
$row['writable'] = true;
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
|
@ -334,14 +361,14 @@ class Item extends BaseObject
|
|||
'id' => 'item_id', 'network'];
|
||||
|
||||
$fields['author'] = ['url' => 'author-link', 'name' => 'author-name',
|
||||
'thumb' => 'author-avatar', 'nick' => 'author-nick', 'network' => 'author-network'];
|
||||
'thumb' => 'author-avatar', 'nick' => 'author-nick'];
|
||||
|
||||
$fields['owner'] = ['url' => 'owner-link', 'name' => 'owner-name',
|
||||
'thumb' => 'owner-avatar', 'nick' => 'owner-nick', 'network' => 'owner-network'];
|
||||
'thumb' => 'owner-avatar', 'nick' => 'owner-nick'];
|
||||
|
||||
$fields['contact'] = ['url' => 'contact-link', 'name' => 'contact-name', 'thumb' => 'contact-avatar',
|
||||
'url', 'name', 'writable', 'self', 'id' => 'cid', 'alias', 'uid' => 'contact-uid',
|
||||
'photo', 'name-date', 'uri-date', 'avatar-date', 'thumb', 'dfrn-id', 'network' => 'contact-network'];
|
||||
'writable', 'self', 'id' => 'cid', 'alias', 'uid' => 'contact-uid',
|
||||
'photo', 'name-date', 'uri-date', 'avatar-date', 'thumb', 'dfrn-id'];
|
||||
|
||||
$fields['parent-item'] = ['guid' => 'parent-guid', 'network' => 'parent-network'];
|
||||
|
||||
|
@ -1126,8 +1153,9 @@ class Item extends BaseObject
|
|||
$user = dba::selectFirst('user', ['nickname'], ['uid' => $item['uid']]);
|
||||
if (DBM::is_result($user)) {
|
||||
$self = normalise_link(System::baseUrl() . '/profile/' . $user['nickname']);
|
||||
logger("'myself' is ".$self." for parent ".$parent_id." checking against ".$item['author-link']." and ".$item['owner-link'], LOGGER_DEBUG);
|
||||
if ((normalise_link($item['author-link']) == $self) || (normalise_link($item['owner-link']) == $self)) {
|
||||
$self_id = Contact::getIdForURL($self, 0, true);
|
||||
logger("'myself' is ".$self_id." for parent ".$parent_id." checking against ".$item['author-id']." and ".$item['owner-id'], LOGGER_DEBUG);
|
||||
if (($item['author-id'] == $self_id) || ($item['owner-id'] == $self_id)) {
|
||||
dba::update('thread', ['mention' => true], ['iid' => $parent_id]);
|
||||
logger("tagged thread ".$parent_id." as mention for user ".$self, LOGGER_DEBUG);
|
||||
}
|
||||
|
|
|
@ -198,16 +198,8 @@ class Post extends BaseObject
|
|||
|
||||
$filer = (($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) ? L10n::t("save to folder") : false);
|
||||
|
||||
if ($item['network'] == NETWORK_FEED) {
|
||||
$item['author-avatar'] = $item['contact-avatar'];
|
||||
$item['author-name'] = $item['contact-name'];
|
||||
$item['owner-avatar'] = $item['contact-avatar'];
|
||||
$item['owner-name'] = $item['contact-name'];
|
||||
}
|
||||
|
||||
$diff_author = !link_compare($item['url'], $item['author-link']);
|
||||
$profile_name = htmlentities(((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
|
||||
if ($item['author-link'] && (!$item['author-name'])) {
|
||||
$profile_name = htmlentities($item['author-name']);
|
||||
if (!empty($item['author-link']) && empty($item['author-name'])) {
|
||||
$profile_name = $item['author-link'];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue