From 58eaf0ba1c42e49d5cede907a0bd5939629764f6 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 10 Feb 2019 18:03:01 +0000 Subject: [PATCH 1/5] Prevent multiple send follow requests --- src/Protocol/ActivityPub/Transmitter.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 1032627b32..ebd32786a8 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -1317,6 +1317,13 @@ class Transmitter $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); $data = ['@context' => ActivityPub::CONTEXT, From 04f34de3a14211de70d5adbcef6375c7746ad425 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 10 Feb 2019 18:42:51 +0000 Subject: [PATCH 2/5] Multiples follows shouldn't be send anymore --- src/Protocol/ActivityPub/Processor.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 6d94b1b49e..a0630fe6c0 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -343,6 +343,8 @@ class Processor $item['body'] = $activity['source']; } + $stored = false; + foreach ($activity['receiver'] as $receiver) { $item['uid'] = $receiver; $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver, true); @@ -357,9 +359,14 @@ class Processor $item_id = Item::insert($item); Logger::log('Storing for user ' . $item['uid'] . ': ' . $item_id); + + if ($item_id) { + $stored = true; + } } - 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); // We send automatic follow requests for reshared messages. (We don't need though for forum posts) if ($author['type'] != 'Group') { @@ -662,11 +669,12 @@ class Processor } foreach ($parent_terms as $term) { - $contact = Contact::getDetailsByURL($term['url']); - - $implicit_mentions[] = $contact['url']; - $implicit_mentions[] = $contact['nurl']; - $implicit_mentions[] = $contact['alias']; + $contact = Contact::getDetailsByURL($term['url'], 0); + if (!empty($contact)) { + $implicit_mentions[] = $contact['url']; + $implicit_mentions[] = $contact['nurl']; + $implicit_mentions[] = $contact['alias']; + } } return $implicit_mentions; From 3b7e9cc3a25c4b2ab2e58ddf3eda64840456b37c Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 10 Feb 2019 18:59:05 +0000 Subject: [PATCH 3/5] This now should really prevent sending the follow requests only once --- src/Protocol/ActivityPub/Processor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index a0630fe6c0..25f064fd6a 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -360,8 +360,8 @@ class Processor $item_id = Item::insert($item); Logger::log('Storing for user ' . $item['uid'] . ': ' . $item_id); - if ($item_id) { - $stored = true; + if ($item['uid'] == 0) { + $stored = $item_id; } } @@ -370,7 +370,7 @@ class Processor $author = APContact::getByURL($item['owner-link'], false); // We send automatic follow requests for reshared messages. (We don't need though for forum posts) 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']); } } From abda71ac0181873c8f9fa2f7c913727bcb9cdd81 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 10 Feb 2019 22:06:27 +0000 Subject: [PATCH 4/5] The "follow" activity is now stored in the "item-activity" table --- src/Model/Item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 54bd4a0ef7..1da9eeaaac 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -91,7 +91,7 @@ class Item extends BaseObject // Never reorder or remove entries from this list. Just add new ones at the end, if needed. // The item-activity table only stores the index and needs this array to know the matching activity. - const ACTIVITIES = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE]; + const ACTIVITIES = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE, ACTIVITY_FOLLOW]; private static $legacy_mode = null; From da5320665543bd8003662b4bdfd877448c1b8206 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 10 Feb 2019 22:08:48 +0000 Subject: [PATCH 5/5] Revert the storing of the "follow" activity --- src/Model/Item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 1da9eeaaac..54bd4a0ef7 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -91,7 +91,7 @@ class Item extends BaseObject // Never reorder or remove entries from this list. Just add new ones at the end, if needed. // The item-activity table only stores the index and needs this array to know the matching activity. - const ACTIVITIES = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE, ACTIVITY_FOLLOW]; + const ACTIVITIES = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE]; private static $legacy_mode = null;