Merge pull request #9267 from annando/follower-indicator

Issue 9264: Ensure that "pt_follower" is only set when its a real follower
This commit is contained in:
Hypolite Petovan 2020-09-24 08:41:50 -04:00 committed by GitHub
commit 9cfd4ef868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View File

@ -1712,7 +1712,8 @@ class Item
$item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, null, $default);
$actor = ($item['gravity'] == GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id'];
if (!$item['origin'] && in_array($item['post-type'], [self::PT_ARTICLE, self::PT_COMMENT, self::PT_RELAY, self::PT_GLOBAL]) && Contact::isSharing($actor, $item['uid'])) {
if (in_array($item['post-type'], [self::PT_ARTICLE, self::PT_COMMENT, self::PT_RELAY, self::PT_GLOBAL])
&& !$item['origin'] && ($item['uid'] != 0) && Contact::isSharing($actor, $item['uid'])) {
$item['post-type'] = self::PT_FOLLOWER;
}

View File

@ -734,20 +734,20 @@ class Receiver
$basecondition = ['rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER],
'network' => Protocol::FEDERATED, 'archive' => false, 'pending' => false];
$condition = DBA::mergeConditions($basecondition, ['nurl' => Strings::normaliseLink($actor)]);
$condition = DBA::mergeConditions($basecondition, ["`nurl` = ? AND `uid` != ?", Strings::normaliseLink($actor), 0]);
$contacts = DBA::select('contact', ['uid', 'rel'], $condition);
while ($contact = DBA::fetch($contacts)) {
if (empty($receivers['uid:' . $contact['uid']]) && self::isValidReceiverForActor($contact, $actor, $tags)) {
if (empty($receivers['uid:' . $contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) {
$receivers['uid:' . $contact['uid']] = ['uid' => $contact['uid'], 'type' => self::TARGET_FOLLOWER];
}
}
DBA::close($contacts);
// The queries are split because of performance issues
$condition = DBA::mergeConditions($basecondition, ["`alias` IN (?, ?)", Strings::normaliseLink($actor), $actor]);
$condition = DBA::mergeConditions($basecondition, ["`alias` IN (?, ?) AND `uid` != ?", Strings::normaliseLink($actor), $actor, 0]);
$contacts = DBA::select('contact', ['uid', 'rel'], $condition);
while ($contact = DBA::fetch($contacts)) {
if (empty($receivers['uid:' . $contact['uid']]) && self::isValidReceiverForActor($contact, $actor, $tags)) {
if (empty($receivers['uid:' . $contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) {
$receivers['uid:' . $contact['uid']] = ['uid' => $contact['uid'], 'type' => self::TARGET_FOLLOWER];
}
}
@ -765,13 +765,8 @@ class Receiver
* @return bool with receivers (user id)
* @throws \Exception
*/
private static function isValidReceiverForActor($contact, $actor, $tags)
private static function isValidReceiverForActor($contact, $tags)
{
// Public contacts are no valid receiver
if ($contact['uid'] == 0) {
return false;
}
// Are we following the contact? Then this is a valid receiver
if (in_array($contact['rel'], [Contact::SHARING, Contact::FRIEND])) {
return true;
@ -789,7 +784,7 @@ class Receiver
continue;
}
if ($tag['href'] == $owner['url']) {
if (Strings::compareLink($tag['href'], $owner['url'])) {
return true;
}
}