]> git.mxchange.org Git - friendica.git/commitdiff
Issue 9264: Ensure that "pt_follower" is only set when its a real follower
authorMichael <heluecht@pirati.ca>
Thu, 24 Sep 2020 10:26:28 +0000 (10:26 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 24 Sep 2020 10:26:28 +0000 (10:26 +0000)
src/Model/Item.php
src/Protocol/ActivityPub/Receiver.php

index d03e9ec3547e00795fce16513c223ed70cdd8591..62f5c714846d970f2e691c2e7ed6f425470150af 100644 (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;
                }
 
index aaf5d9b0ff2d781a3f3425aa29a7e68690be3f21..00e6d5c31417b69ccab333f1a3c4b2b6a20fa5d9 100644 (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;
                        }
                }