Merge pull request #9174 from annando/issue-9167
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 9 Sep 2020 18:05:21 +0000 (14:05 -0400)
committerGitHub <noreply@github.com>
Wed, 9 Sep 2020 18:05:21 +0000 (14:05 -0400)
Issue 9167 - messages from non-followers

include/conversation.php
src/Protocol/ActivityPub/Receiver.php
view/theme/frio/templates/sub/direction.tpl
view/theme/vier/templates/sub/direction.tpl

index 1d374c5..4afc7c6 100644 (file)
@@ -741,13 +741,16 @@ function conversation_fetch_comments($thread_items, $pinned) {
                        $direction = ['direction' => 5, 'title' => DI::l10n()->t('%s commented on this.', $row['author-name'])];
                }
 
-               if (($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && ($row['author-id'] == $row['owner-id'])
-                       && !Contact::isSharing($row['author-id'], $row['uid'])) {
-                       if ($row['post-type'] == Item::PT_TAG) {
-                               $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')];
+               if (($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && ($row['author-id'] == $row['owner-id'])) {
+                       if (Contact::isSharing($row['author-id'], $row['uid'])) {
+                               $row['direction'] = ['direction' => 6, 'title' => DI::l10n()->t('You are following %s.', $row['author-name'])];
+                       } else {
+                               if ($row['post-type'] == Item::PT_TAG) {
+                                       $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')];
+                               }
+                               $parentlines[] = $lineno;
+                               
                        }
-               
-                       $parentlines[] = $lineno;
                }
 
                if ($row['gravity'] == GRAVITY_PARENT) {
index d59a5da..c7d3ac6 100644 (file)
@@ -207,8 +207,6 @@ class Receiver
                        $uid = self::getFirstUserFromReceivers($receivers);
                }
 
-               Logger::log('Receivers: ' . $uid . ' - ' . json_encode($receivers), Logger::DEBUG);
-
                $object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
                if (empty($object_id)) {
                        Logger::log('No object found', Logger::DEBUG);
@@ -539,19 +537,7 @@ class Receiver
                                        $receivers['uid:-1'] = -1;
                                }
 
-                               if (($receiver == self::PUBLIC_COLLECTION) && !empty($actor)) {
-                                       // This will most likely catch all OStatus connections to Mastodon
-                                       $condition = ['alias' => [$actor, Strings::normaliseLink($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND]
-                                               , 'archive' => false, 'pending' => false];
-                                       $contacts = DBA::select('contact', ['uid'], $condition);
-                                       while ($contact = DBA::fetch($contacts)) {
-                                               if ($contact['uid'] != 0) {
-                                                       $receivers['uid:' . $contact['uid']] = $contact['uid'];
-                                               }
-                                       }
-                                       DBA::close($contacts);
-                               }
-
+                               // Fetch the receivers for the public and the followers collection
                                if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) {
                                        $receivers = array_merge($receivers, self::getReceiverForActor($actor, $tags));
                                        continue;
@@ -599,12 +585,23 @@ class Receiver
         * @return array with receivers (user id)
         * @throws \Exception
         */
-       public static function getReceiverForActor($actor, $tags)
+       private static function getReceiverForActor($actor, $tags)
        {
                $receivers = [];
-               $networks = Protocol::FEDERATED;
-               $condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER],
-                       'network' => $networks, 'archive' => false, 'pending' => false];
+               $basecondition = ['rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER],
+                       'network' => Protocol::FEDERATED, 'archive' => false, 'pending' => false];
+
+               $condition = DBA::mergeConditions($basecondition, ['nurl' => Strings::normaliseLink($actor)]);
+               $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
+               while ($contact = DBA::fetch($contacts)) {
+                       if (self::isValidReceiverForActor($contact, $actor, $tags)) {
+                               $receivers['uid:' . $contact['uid']] = $contact['uid'];
+                       }
+               }
+               DBA::close($contacts);
+
+               // The queries are split because of performance issues
+               $condition = DBA::mergeConditions($basecondition, ["`alias` IN (?, ?)", Strings::normaliseLink($actor), $actor]);
                $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
                while ($contact = DBA::fetch($contacts)) {
                        if (self::isValidReceiverForActor($contact, $actor, $tags)) {
index 671272c..abcd517 100644 (file)
                <i class="fa fa-hashtag" aria-hidden="true" title="{{$direction.title}}"></i>
        {{elseif $direction.direction == 5}}
                <i class="fa fa-comment-o" aria-hidden="true" title="{{$direction.title}}"></i>
+       {{elseif $direction.direction == 6}}
+               <i class="fa fa-check" aria-hidden="true" title="{{$direction.title}}"></i>
+       {{elseif $direction.direction == 7}}
+               <i class="fa fa-at" aria-hidden="true" title="{{$direction.title}}"></i>
        {{/if}}
 </span>
 {{/if}}
index 08f40c3..939623c 100644 (file)
                <i class="icon-tag" aria-hidden="true" title="{{$direction.title}}"></i>
        {{elseif $direction.direction == 5}}
                <i class="icon-commenting" aria-hidden="true" title="{{$direction.title}}"></i>
+       {{elseif $direction.direction == 6}}
+               <i class="icon-ok-sign" aria-hidden="true" title="{{$direction.title}}"></i>
+       {{elseif $direction.direction == 7}}
+               <i class="icon-forward" aria-hidden="true" title="{{$direction.title}}"></i>
        {{/if}}
 </span>
 {{/if}}