Merge pull request #6632 from annando/check-follow

Prevent multiple send follow requests
This commit is contained in:
Hypolite Petovan 2019-02-10 21:19:31 -05:00 committed by GitHub
commit b5dcca995c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View file

@ -343,6 +343,8 @@ class Processor
$item['body'] = $activity['source']; $item['body'] = $activity['source'];
} }
$stored = false;
foreach ($activity['receiver'] as $receiver) { foreach ($activity['receiver'] as $receiver) {
$item['uid'] = $receiver; $item['uid'] = $receiver;
$item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver, true); $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver, true);
@ -357,13 +359,18 @@ class Processor
$item_id = Item::insert($item); $item_id = Item::insert($item);
Logger::log('Storing for user ' . $item['uid'] . ': ' . $item_id); Logger::log('Storing for user ' . $item['uid'] . ': ' . $item_id);
if ($item['uid'] == 0) {
$stored = $item_id;
}
} }
if (!$item['private'] && ($item['gravity'] == GRAVITY_PARENT) && ($item['author-link'] != $item['owner-link'])) { // Store send a follow request for every reshare - but only when the item had been stored
if ($stored && !$item['private'] && ($item['gravity'] == GRAVITY_PARENT) && ($item['author-link'] != $item['owner-link'])) {
$author = APContact::getByURL($item['owner-link'], false); $author = APContact::getByURL($item['owner-link'], false);
// We send automatic follow requests for reshared messages. (We don't need though for forum posts) // We send automatic follow requests for reshared messages. (We don't need though for forum posts)
if ($author['type'] != 'Group') { if ($author['type'] != 'Group') {
Logger::log('Send follow request for ' . $item['uri'] . ' to ' . $item['author-link'], Logger::DEBUG); Logger::log('Send follow request for ' . $item['uri'] . ' (' . $stored . ') to ' . $item['author-link'], Logger::DEBUG);
ActivityPub\Transmitter::sendFollowObject($item['uri'], $item['author-link']); ActivityPub\Transmitter::sendFollowObject($item['uri'], $item['author-link']);
} }
} }
@ -662,11 +669,12 @@ class Processor
} }
foreach ($parent_terms as $term) { foreach ($parent_terms as $term) {
$contact = Contact::getDetailsByURL($term['url']); $contact = Contact::getDetailsByURL($term['url'], 0);
if (!empty($contact)) {
$implicit_mentions[] = $contact['url']; $implicit_mentions[] = $contact['url'];
$implicit_mentions[] = $contact['nurl']; $implicit_mentions[] = $contact['nurl'];
$implicit_mentions[] = $contact['alias']; $implicit_mentions[] = $contact['alias'];
}
} }
return $implicit_mentions; return $implicit_mentions;

View file

@ -1317,6 +1317,13 @@ class Transmitter
$uid = $first_user['uid']; $uid = $first_user['uid'];
} }
$condition = ['verb' => ACTIVITY_FOLLOW, 'uid' => 0, 'parent-uri' => $object,
'author-id' => Contact::getPublicIdByUserId($uid)];
if (Item::exists($condition)) {
Logger::log('Follow for ' . $object . ' for user ' . $uid . ' does already exist.', Logger::DEBUG);
return false;
}
$owner = User::getOwnerDataById($uid); $owner = User::getOwnerDataById($uid);
$data = ['@context' => ActivityPub::CONTEXT, $data = ['@context' => ActivityPub::CONTEXT,