Merge pull request #6627 from annando/check-follow

Don't store multiple follow request from a single person
This commit is contained in:
Hypolite Petovan 2019-02-10 13:01:52 -05:00 committed by GitHub
commit 3a9217049b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -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
*

View File

@ -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);