]> git.mxchange.org Git - friendica.git/commitdiff
Issue 11309: Check if a post is wanted
authorMichael <heluecht@pirati.ca>
Fri, 11 Mar 2022 14:00:05 +0000 (14:00 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 11 Mar 2022 14:00:05 +0000 (14:00 +0000)
src/Protocol/ActivityPub/Processor.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php

index 79d24d16024538b997b0050d12ad08df90e72d33..2e2d18b3916a34e601c36b85b06297aca312f63d 100644 (file)
@@ -572,6 +572,53 @@ class Processor
                return $host_hash . '-'. hash('fnv164', $path) . '-'. hash('joaat', $path);
        }
 
+       /**
+        * Checks if an incoming message is wanted
+        *
+        * @param array $activity
+        * @param array $item
+        * @return boolean Is the message wanted?
+        */
+       private static function isSolicitedMessage(array $activity, array $item)
+       {
+               // The checks are split to improve the support when searching why a message was accepted.
+               if (count($activity['receiver']) != 1) {
+                       // The message has more than one receiver, so it is wanted.
+                       Logger::debug('Message has got several receivers - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]);
+                       return true;
+               }
+
+               if ($item['private'] == Item::PRIVATE) {
+                       // We only look at public posts here. Private posts are expected to be intentionally posted to the single receiver.
+                       Logger::debug('Message is private - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]);
+                       return true;
+               }
+               
+               if (!empty($activity['from-relay'])) {
+                       // We check relay posts at another place. When it arrived here, the message is already checked.
+                       Logger::debug('Message is a relay post that is already checked - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]);
+                       return true;
+               }
+
+               if (!empty($activity['thread-completion'])) {
+                       // The thread completion mode means that the post is fetched intentionally.
+                       // This can have several causes, in doubt we keep the message.
+                       // This can possibly be improved in the future.
+                       Logger::debug('Message is in completion mode - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]);
+                       return true;
+               }
+
+               if ($item['gravity'] != GRAVITY_PARENT) {
+                       // We cannot reliably check at this point if a comment or activity belongs to an accepted post or needs to be fetched
+                       // This can possibly be improved in the future.
+                       Logger::debug('Message is no parent - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]);
+                       return true;
+               }
+
+               $tags = array_column(Tag::getByURIId($item['uri-id'], [Tag::HASHTAG]), 'name');
+               return Relay::isSolicitedPost($tags, $item['body'], $item['author-id'], $item['uri'], Protocol::ACTIVITYPUB);
+       }
+
        /**
         * Creates an item post
         *
@@ -589,6 +636,11 @@ class Processor
                $stored = false;
                ksort($activity['receiver']);
 
+               if (!self::isSolicitedMessage($activity, $item)) {
+                       DBA::delete('item-uri', ['id' => $item['uri-id']]);
+                       return;
+               }
+
                foreach ($activity['receiver'] as $receiver) {
                        if ($receiver == -1) {
                                continue;
index 2be55b8a55dc70121c3c1a64d63e81897d409635..a20d54fb6454ce2896c6eba4d4e9bc5f0663d6c5 100644 (file)
@@ -1775,12 +1775,11 @@ class DFRN
        {
                if (DBA::exists('contact', ["`nurl` = ? AND `uid` != ? AND `rel` IN (?, ?)",
                        Strings::normaliseLink($item["author-link"]), 0, Contact::FRIEND, Contact::SHARING])) {
-                       Logger::info('Author has got followers - accepted', ['uri' => $item['uri'], 'author' => $item["author-link"]]);
+                       Logger::debug('Author has got followers - accepted', ['uri' => $item['uri'], 'author' => $item["author-link"]]);
                        return true;
                }
 
-               $taglist = Tag::getByURIId($item['uri-id'], [Tag::HASHTAG]);
-               $tags = array_column($taglist, 'name');
+               $tags = array_column(Tag::getByURIId($item['uri-id'], [Tag::HASHTAG]), 'name');
                return Relay::isSolicitedPost($tags, $item['body'], $item['author-id'], $item['uri'], Protocol::DFRN);
        }
 
index ad8e2bbef8d28d5c983ba9f2001c831e736e71cd..331a3bd9fe46d2fc3667843c12be48bb83a7143d 100644 (file)
@@ -2620,12 +2620,11 @@ class Diaspora
                $contact = Contact::getByURL($author);
                if (DBA::exists('contact', ["`nurl` = ? AND `uid` != ? AND `rel` IN (?, ?)",
                        $contact['nurl'], 0, Contact::FRIEND, Contact::SHARING])) {
-                       Logger::info('Author has got followers - accepted', ['url' => $url, 'author' => $author]);
+                       Logger::debug('Author has got followers - accepted', ['url' => $url, 'author' => $author]);
                        return true;
                }
 
-               $taglist = Tag::getByURIId($uriid, [Tag::HASHTAG]);
-               $tags = array_column($taglist, 'name');
+               $tags = array_column(Tag::getByURIId($uriid, [Tag::HASHTAG]), 'name');
                return Relay::isSolicitedPost($tags, $body, $contact['id'], $url, Protocol::DIASPORA);
        }