diff --git a/include/api.php b/include/api.php index a5088756ae..819d2c75a0 100644 --- a/include/api.php +++ b/include/api.php @@ -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) { diff --git a/include/conversation.php b/include/conversation.php index 08220d4bb2..1112447d50 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -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']; } diff --git a/mod/acl.php b/mod/acl.php index ede6940329..c16b3bab6e 100644 --- a/mod/acl.php +++ b/mod/acl.php @@ -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); diff --git a/mod/display.php b/mod/display.php index 6a07fa1762..919b12fbc3 100644 --- a/mod/display.php +++ b/mod/display.php @@ -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 .= ""; diff --git a/mod/network.php b/mod/network.php index 61d957e1ad..61e4e779ed 100644 --- a/mod/network.php +++ b/mod/network.php @@ -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); diff --git a/mod/notes.php b/mod/notes.php index 69b544472f..99114add8c 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -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); } } diff --git a/mod/ping.php b/mod/ping.php index 06d83a1d9a..8028d69ed2 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -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); diff --git a/mod/profile.php b/mod/profile.php index 49d6fe261d..a6075b01cf 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -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 = []; } diff --git a/mod/search.php b/mod/search.php index d64ce7d0e1..974680d2a0 100644 --- a/mod/search.php +++ b/mod/search.php @@ -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)) { diff --git a/mod/starred.php b/mod/starred.php index 78ba4ce61e..443308c277 100644 --- a/mod/starred.php +++ b/mod/starred.php @@ -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(); } diff --git a/src/Core/NotificationsManager.php b/src/Core/NotificationsManager.php index 8020a281b0..507d4db131 100644 --- a/src/Core/NotificationsManager.php +++ b/src/Core/NotificationsManager.php @@ -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 = [ diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 6a24b7da9f..973e5b5a21 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -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); diff --git a/src/Model/Item.php b/src/Model/Item.php index d4c5e81704..d6bfef39fb 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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); } diff --git a/src/Object/Post.php b/src/Object/Post.php index bceee38444..594b18af88 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -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']; }