*
* Worker::add(PRIORITY_HIGH, "Notifier", COMMAND, ITEM_ID);
*
- * where COMMAND is one of the following:
- *
- * activity (in diaspora.php, dfrn_confirm.php, profiles.php)
- * comment-import (in diaspora.php, items.php)
- * comment-new (in item.php)
- * drop (in diaspora.php, items.php, photos.php)
- * edit_post (in item.php)
- * event (in events.php)
- * like (in like.php, poke.php)
- * mail (in message.php)
- * suggest (in fsuggest.php)
- * tag (in photos.php, poke.php, tagger.php)
- * tgroup (in items.php)
- * wall-new (in photos.php, item.php)
- * removeme (in Contact.php)
- * relocate (in uimport.php)
- *
+ * where COMMAND is one of the constants that are defined in Worker/Delivery.php
* and ITEM_ID is the id of the item in the database that needs to be sent to others.
*/
}
$uid = $message['uid'];
$recipients[] = $message['contact-id'];
+
+ $mail = ActivityPub\Transmitter::ItemArrayFromMail($target_id);
+ $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($mail, $uid, true);
+ foreach ($inboxes as $inbox) {
+ Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'id' => $target_id, 'inbox' => $inbox]);
+ Worker::add(['priority' => PRIORITY_HIGH, 'created' => $a->queue['created'], 'dont_fork' => true],
+ 'APDelivery', $cmd, $target_id, $inbox, $uid);
+ }
} elseif ($cmd == Delivery::SUGGESTION) {
$suggest = DBA::selectFirst('fsuggest', ['uid', 'cid'], ['id' => $target_id]);
if (!DBA::isResult($suggest)) {
$uid = $target_id;
$condition = ['uid' => $target_id, 'self' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
- $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'network', 'batch'], $condition);
+ $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'network', 'protocol', 'batch'], $condition);
} else {
// find ancestors
$condition = ['id' => $target_id, 'visible' => true, 'moderated' => false];
$parent = $items[0];
if (!self::isRemovalActivity($cmd, $owner, Protocol::ACTIVITYPUB)) {
- $delivery_queue_count += self::activityPubDelivery($cmd, $target_item, $parent, $a->queue['priority'], $a->queue['created']);
+ $delivery_queue_count += self::activityPubDelivery($cmd, $target_item, $parent, $a->queue['priority'], $a->queue['created'], $owner);
}
$fields = ['network', 'author-id', 'owner-id'];
}
- if (($cmd === 'uplink') && (intval($parent['forum_mode']) == 1) && !$top_level) {
+ if (($cmd === Delivery::UPLINK) && (intval($parent['forum_mode']) == 1) && !$top_level) {
$relay_to_owner = true;
}
}
// Special treatment for forum posts
- if (self::isForumPost($target_item, $owner)) {
+ if (Item::isForumPost($target_item, $owner)) {
$relay_to_owner = true;
$direct_forum_delivery = true;
}
// Avoid that comments in a forum thread are sent to OStatus
- if (self::isForumPost($parent, $owner)) {
+ if (Item::isForumPost($parent, $owner)) {
$direct_forum_delivery = true;
}
// if our parent is a public forum (forum_mode == 1), uplink to the origional author causing
// a delivery fork. private groups (forum_mode == 2) do not uplink
- if ((intval($parent['forum_mode']) == 1) && !$top_level && ($cmd !== 'uplink')) {
- Worker::add($a->queue['priority'], 'Notifier', 'uplink', $target_id);
+ if ((intval($parent['forum_mode']) == 1) && !$top_level && ($cmd !== Delivery::UPLINK)) {
+ Worker::add($a->queue['priority'], 'Notifier', Delivery::UPLINK, $target_id);
}
foreach ($items as $item) {
if (!empty($networks)) {
$condition['network'] = $networks;
}
- $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'network', 'batch'], $condition);
+ $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'network', 'protocol', 'batch'], $condition);
}
$conversants = [];
$relay_list_stmt = DBA::p(
"SELECT
- `batch`,
- ANY_VALUE(`id`) AS `id`,
- ANY_VALUE(`name`) AS `name`,
- ANY_VALUE(`network`) AS `network`
+ `batch`,
+ ANY_VALUE(`id`) AS `id`,
+ ANY_VALUE(`name`) AS `name`,
+ ANY_VALUE(`network`) AS `network`,
+ ANY_VALUE(`protocol`) AS `protocol`
FROM `contact`
WHERE `network` = ?
AND `batch` != ''
// Add the relay to the list, avoid duplicates.
// Don't send community posts to the relay. Forum posts via the Diaspora protocol are looking ugly.
- if (!$followup && !self::isForumPost($target_item, $owner)) {
+ if (!$followup && !Item::isForumPost($target_item, $owner)) {
$relay_list = Diaspora::relayList($target_id, $relay_list);
}
}
$condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false,
'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]];
- $r2 = DBA::toArray(DBA::select('contact', ['id', 'url', 'name', 'network'], $condition));
+ $r2 = DBA::toArray(DBA::select('contact', ['id', 'url', 'name', 'network', 'protocol'], $condition));
$r = array_merge($r2, $relay_list);
continue;
}
+ if (in_array($rr['network'], [Protocol::DFRN, Protocol::DIASPORA]) && ($rr['protocol'] == Protocol::ACTIVITYPUB) &&
+ !in_array($cmd, [Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION, Delivery::POKE])) {
+ Logger::info('Contact is Friendica AP, so skipping delivery via legacy DFRN', ['url' => $rr['url']]);
+ continue;
+ }
+
if (Config::get('debug', 'total_ap_delivery') && !empty($rr['url']) && ($rr['network'] == Protocol::DFRN) && !empty(APContact::getByURL($rr['url'], false))) {
Logger::log('Skipping contact ' . $rr['url'] . ' since it will be delivered via AP', Logger::DEBUG);
continue;
continue;
}
+ if (in_array($contact['network'], [Protocol::DFRN, Protocol::DIASPORA]) && ($contact['protocol'] == Protocol::ACTIVITYPUB) &&
+ !in_array($cmd, [Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION, Delivery::POKE])) {
+ Logger::info('Contact is Friendica AP, so skipping delivery via legacy DFRN', ['url' => $contact['url']]);
+ continue;
+ }
+
if (Config::get('debug', 'total_ap_delivery') && ($contact['network'] == Protocol::DFRN) && !empty(APContact::getByURL($contact['url'], false))) {
Logger::log('Skipping contact ' . $contact['url'] . ' since it will be delivered via AP', Logger::DEBUG);
continue;
if (!empty($target_item)) {
Logger::log('Calling hooks for ' . $cmd . ' ' . $target_id, Logger::DEBUG);
- if (in_array($cmd, [Delivery::POST, Delivery::COMMENT])) {
+ if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
ItemDeliveryData::update($target_item['id'], ['queue_count' => $delivery_queue_count]);
}
*/
private static function isRemovalActivity($cmd, $owner, $network)
{
- return ($cmd == Delivery::DELETION) && $owner['account_removed'] && in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DIASPORA]);
+ return ($cmd == Delivery::DELETION) && $owner['account_removed'] && in_array($network, [Protocol::ACTIVITYPUB, Protocol::DIASPORA]);
}
/**
$inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0);
foreach ($inboxes as $inbox) {
- Logger::log('Account removal for user ' . $self_user_id . ' to ' . $inbox .' via ActivityPub', Logger::DEBUG);
+ Logger::info('Account removal via ActivityPub', ['uid' => $self_user_id, 'inbox' => $inbox]);
Worker::add(['priority' => PRIORITY_NEGLIGIBLE, 'created' => $created, 'dont_fork' => true],
'APDelivery', Delivery::REMOVAL, '', $inbox, $self_user_id);
}
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function activityPubDelivery($cmd, array $target_item, array $parent, $priority, $created)
+ private static function activityPubDelivery($cmd, array $target_item, array $parent, $priority, $created, $owner)
{
$inboxes = [];
if ($target_item['origin']) {
$inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid);
Logger::log('Origin item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.', Logger::DEBUG);
+ } elseif (Item::isForumPost($target_item, $owner)) {
+ $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid, false, 0, true);
+ Logger::log('Forum item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.', Logger::DEBUG);
} elseif (!DBA::exists('conversation', ['item-uri' => $target_item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB])) {
Logger::log('Remote item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' is no AP post. It will not be distributed.', Logger::DEBUG);
return 0;
ActivityPub\Transmitter::createCachedActivityFromItem($target_item['id'], true);
foreach ($inboxes as $inbox) {
- Logger::log('Deliver ' . $target_item['id'] .' to ' . $inbox .' via ActivityPub', Logger::DEBUG);
+ Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'id' => $target_item['id'], 'inbox' => $inbox]);
Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true],
'APDelivery', $cmd, $target_item['id'], $inbox, $uid);
return count($inboxes);
}
-
- private static function isForumPost(array $item, array $owner)
- {
- if (($item['author-id'] == $item['owner-id']) ||
- ($owner['id'] == $item['contact-id']) ||
- ($item['uri'] != $item['parent-uri'])) {
- return false;
- }
-
- return self::isForum($item['contact-id']);
- }
-
- private static function isForum($contactid)
- {
- $fields = ['forum', 'prv'];
- $condition = ['id' => $contactid];
- $contact = DBA::selectFirst('contact', $fields, $condition);
- if (!DBA::isResult($contact)) {
- // Should never happen
- return false;
- }
-
- // Is it a forum?
- return ($contact['forum'] || $contact['prv']);
- }
}