diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 6d94b1b49..25f064fd6 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,13 +359,18 @@ class Processor $item_id = Item::insert($item); 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); // 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']); } } @@ -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; diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 1032627b3..ebd32786a 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,