]> git.mxchange.org Git - friendica.git/commitdiff
Don't store multiple follow request from a single person
authorMichael <heluecht@pirati.ca>
Sun, 10 Feb 2019 11:28:17 +0000 (11:28 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 10 Feb 2019 11:28:17 +0000 (11:28 +0000)
src/Model/Item.php
src/Model/User.php

index 6a5ff01d596c32faa5ff6cd67ea42ffb5483d6cb..ead907f8b4c7f23e06145a1d82ebb6bc5811957d 100644 (file)
@@ -1451,6 +1451,23 @@ class Item extends BaseObject
                        Logger::log("Set network to " . $item["network"] . " for " . $item["uri"], Logger::DEBUG);
                }
 
+               if ($item['verb'] == ACTIVITY_FOLLOW) {
+                       Logger::log('Blubb: '.$item['uid'].' - '.$item['parent-uri']);
+                       if (!$item['origin'] && ($item['author-id'] == User::getPublicContactById($uid))) {
+                               // Our own follow request can be relayed to us. We don't store them to avoid notification chaos.
+                               Logger::log("Blubb: Don't store not origin follow request from us for " . $item['parent-uri'], Logger::DEBUG);
+                               return 0;
+                       }
+
+                       $condition = ['verb' => ACTIVITY_FOLLOW, 'uid' => $item['uid'],
+                               'parent-uri' => $item['parent-uri'], 'author-id' => $item['author-id']];
+                       if (self::exists($condition)) {
+                               // It happens that we receive multiple follow requests by the same author - we only store one.
+                               Logger::log('Blubb: Found existing follow request from author ' . $item['author-id'] . ' for ' . $item['parent-uri'], Logger::DEBUG);
+                               return 0;
+                       }
+               }
+
                // Checking if there is already an item with the same guid
                Logger::log('Checking for an item for user '.$item['uid'].' on network '.$item['network'].' with the guid '.$item['guid'], Logger::DEBUG);
                $condition = ['guid' => $item['guid'], 'network' => $item['network'], 'uid' => $item['uid']];
index 59ca4c90a40a3f6742c41cd0883babf94d13288f..841c81f741114a8707958b4d95e48d56ee8d5892 100644 (file)
@@ -99,6 +99,20 @@ class User
                return DBA::selectFirst('user', [], ['uid' => $uid]);
        }
 
+       /**
+        * @param  integer       $uid
+        * @return array|boolean User record if it exists, false otherwise
+        * @throws Exception
+        */
+       public static function getPublicContactById($uid)
+       {
+               $self = DBA::selectFirst('contact', ['url'], ['self' => true, 'uid' => $uid]);
+               if (!DBA::isResult($self)) {
+                       return false;
+               }
+               return Contact::getIdForURL($self['url'], 0, true);
+       }
+
        /**
         * @brief Returns the user id of a given profile URL
         *