diff --git a/src/Model/Contact.php b/src/Model/Contact.php index cf90406e24..2d6bc716bb 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -155,6 +155,23 @@ class Contact extends BaseObject return PortableContact::detectServer($url); } + /** + * Returns the public contact id of the given user id + * + * @param integer $uid User ID + * + * @return integer|boolean Public contact id for given user id + * @throws Exception + */ + public static function getPublicIdByUserId($uid) + { + $self = DBA::selectFirst('contact', ['url'], ['self' => true, 'uid' => $uid]); + if (!DBA::isResult($self)) { + return false; + } + return self::getIdForURL($self['url'], 0, true); + } + /** * @brief Returns the contact id for the user and the public contact id for a given contact id * diff --git a/src/Model/Item.php b/src/Model/Item.php index 6a5ff01d59..54bd4a0ef7 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1315,6 +1315,8 @@ class Item extends BaseObject $item['gravity'] = GRAVITY_PARENT; } elseif (activity_match($item['verb'], ACTIVITY_POST)) { $item['gravity'] = GRAVITY_COMMENT; + } elseif (activity_match($item['verb'], ACTIVITY_FOLLOW)) { + $item['gravity'] = GRAVITY_ACTIVITY; } else { $item['gravity'] = GRAVITY_UNKNOWN; // Should not happen Logger::log('Unknown gravity for verb: ' . $item['verb'], Logger::DEBUG); @@ -1459,6 +1461,22 @@ class Item extends BaseObject return 0; } + if ($item['verb'] == ACTIVITY_FOLLOW) { + if (!$item['origin'] && ($item['author-id'] == Contact::getPublicIdByUserId($uid))) { + // Our own follow request can be relayed to us. We don't store it to avoid notification chaos. + Logger::log("Follow: 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('Follow: Found existing follow request from author ' . $item['author-id'] . ' for ' . $item['parent-uri'], Logger::DEBUG); + return 0; + } + } + // Check for hashtags in the body and repair or add hashtag links self::setHashtags($item);