* One of the parameters is a contact array.
* This is done to avoid duplicates.
*
- * @param array $parent The parent post
+ * @param array $item Item that is about to be delivered
* @param array $contacts The previously fetched contacts
*
* @return array of relay servers
* @throws \Exception
*/
- public static function participantsForThread(array $parent, array $contacts)
+ public static function participantsForThread(array $item, array $contacts)
{
- if (!in_array($parent['private'], [Item::PUBLIC, Item::UNLISTED])) {
+ if (!in_array($item['private'], [Item::PUBLIC, Item::UNLISTED]) || in_array($item["verb"], [Activity::FOLLOW, Activity::TAG])) {
+ Logger::info('Item is private or a participation request. It will not be relayed', ['guid' => $item['guid'], 'private' => $item['private'], 'verb' => $item['verb']]);
return $contacts;
}
- $items = Item::select(['author-id'], ['parent' => $parent['id']], ['group_by' => ['author-id']]);
+ $items = Item::select(['author-id', 'author-link', 'parent-author-link', 'parent-guid', 'guid'],
+ ['parent' => $item['parent'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_ACTIVITY]]);
while ($item = DBA::fetch($items)) {
$contact = DBA::selectFirst('contact', ['id', 'url', 'name', 'protocol', 'batch', 'network'],
['id' => $item['author-id']]);
- if (!DBA::isResult($contact)) {
- // Shouldn't happen
+ if (!DBA::isResult($contact) || empty($contact['batch']) ||
+ ($contact['network'] != Protocol::DIASPORA) ||
+ Strings::compareLink($item['parent-author-link'], $item['author-link'])) {
continue;
}
}
if (!$exists) {
- Logger::info('Add participant to receiver list', ['item' => $parent['guid'], 'participant' => $contact['url']]);
+ Logger::info('Add participant to receiver list', ['parent' => $item['parent-guid'], 'item' => $item['guid'], 'participant' => $contact['url']]);
$contacts[] = $contact;
}
}
return false;
}
+ if (!$parent_item['origin']) {
+ Logger::info('Not our origin. Participation is ignored', ['parent_guid' => $parent_guid, 'guid' => $guid, 'author' => $author]);
+ }
+
if (!in_array($parent_item['private'], [Item::PUBLIC, Item::UNLISTED])) {
Logger::info('Item is not public, participation is ignored', ['parent_guid' => $parent_guid, 'guid' => $guid, 'author' => $author]);
return false;
Logger::info('Participation stored', ['id' => $message_id, 'guid' => $guid, 'parent_guid' => $parent_guid, 'author' => $author]);
// Send all existing comments and likes to the requesting server
- $comments = Item::select(['id', 'uri-id', 'parent', 'verb', 'self'], ['parent' => $parent_item['id']]);
+ $comments = Item::select(['id', 'uri-id', 'parent', 'verb'], ['parent' => $parent_item['id'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_ACTIVITY]]);
while ($comment = Item::fetch($comments)) {
- if ($comment['id'] == $comment['parent']) {
+ if (in_array($comment["verb"], [Activity::FOLLOW, Activity::TAG])) {
+ Logger::info('participation messages are not relayed', ['item' => $comment['id']]);
continue;
}