Merge pull request #9149 from annando/issue-9099

Issue 9099: Improve mentions from non followers
This commit is contained in:
Hypolite Petovan 2020-09-06 16:16:20 -04:00 committed by GitHub
commit e92904c3f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -51,8 +51,8 @@ class UserItem
*/ */
public static function setNotification(int $iid) public static function setNotification(int $iid)
{ {
$fields = ['id', 'uri-id', 'uid', 'body', 'parent', 'gravity', 'tag', $fields = ['id', 'uri-id', 'parent-uri-id', 'uid', 'body', 'parent', 'gravity', 'tag',
'contact-id', 'thr-parent', 'parent-uri', 'author-id', 'verb']; 'private', 'contact-id', 'thr-parent', 'parent-uri', 'author-id', 'verb'];
$item = Item::selectFirst($fields, ['id' => $iid, 'origin' => false]); $item = Item::selectFirst($fields, ['id' => $iid, 'origin' => false]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
return; return;
@ -64,13 +64,36 @@ class UserItem
} }
// fetch all users in the thread // fetch all users in the thread
$uids = [];
$users = DBA::p("SELECT DISTINCT(`contact`.`uid`) FROM `item` $users = DBA::p("SELECT DISTINCT(`contact`.`uid`) FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` != 0 INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` != 0
WHERE `parent` IN (SELECT `parent` FROM `item` WHERE `id`=?)", $iid); WHERE `parent` IN (SELECT `parent` FROM `item` WHERE `id`=?)", $iid);
while ($user = DBA::fetch($users)) { while ($user = DBA::fetch($users)) {
self::setNotificationForUser($item, $user['uid']); $uids[] = $user['uid'];
} }
DBA::close($users); DBA::close($users);
// Add item users
$users = Item::select(['uid'], ["`parent-uri-id` = ? AND `uid` != ?", $item['parent-uri-id'], 0], ['group_by' => ['uid']]);
while ($user = DBA::fetch($users)) {
$uids[] = $user['uid'];
}
DBA::close($users);
// Check for mentions to local users
if (in_array($item['private'], [Item::PUBLIC, Item::UNLISTED])) {
$mentions = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION]);
foreach ($mentions as $mention) {
$uid = User::getIdForURL($mention['url']);
if (!empty($uid)) {
$uids[] = $uid;
}
}
}
foreach (array_unique($uids) as $uid) {
self::setNotificationForUser($item, $uid);
}
} }
/** /**