Clarify usage of ActivityPub\Transmitter::fetchTargetInboxes in Worker\APDelivery queuing

- $inbox is now always a string
- $receivers should be correctly populated now
- $target_id is renamed to $item_id and correctly initialized to 0 for non-item deliveries
This commit is contained in:
Hypolite Petovan 2020-12-14 23:33:14 -05:00
parent e4228c6218
commit d59fcd5093
3 changed files with 19 additions and 41 deletions

View file

@ -34,58 +34,36 @@ class APDelivery
/** /**
* Delivers ActivityPub messages * Delivers ActivityPub messages
* *
* @param string $cmd * @param string $cmd One of the Worker\Delivery constant values
* @param integer $target_id * @param integer $item_id 0 if no item is involved (like Delivery::REMOVAL and Delivery::PROFILEUPDATE)
* @param string|array $inboxes * @param string $inbox The URL of the recipient profile
* @param integer $uid * @param integer $uid The ID of the user who triggered this delivery
* @param array $receivers * @param array $receivers The contact IDs related to the inbox URL for contact archival housekeeping
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function execute(string $cmd, int $target_id, $inboxes, int $uid, array $receivers = []) public static function execute(string $cmd, int $item_id, string $inbox, int $uid, array $receivers = [])
{
if (is_string($inboxes)) {
$inboxes = [$inboxes];
}
foreach ($inboxes as $inbox) {
self::perform($cmd, $target_id, $inbox, $uid, $receivers);
}
}
/**
* Delivers ActivityPub messages
*
* @param string $cmd
* @param integer $target_id
* @param string $inbox
* @param integer $uid
* @param array $receivers
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
private static function perform(string $cmd, int $target_id, string $inbox, int $uid, array $receivers = [])
{ {
if (ActivityPub\Transmitter::archivedInbox($inbox)) { if (ActivityPub\Transmitter::archivedInbox($inbox)) {
Logger::info('Inbox is archived', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $target_id, 'uid' => $uid]); Logger::info('Inbox is archived', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $item_id, 'uid' => $uid]);
if (in_array($cmd, [Delivery::POST])) { if (in_array($cmd, [Delivery::POST])) {
$item = Item::selectFirst(['uri-id'], ['id' => $target_id]); $item = Item::selectFirst(['uri-id'], ['id' => $item_id]);
Post\DeliveryData::incrementQueueFailed($item['uri-id'] ?? 0); Post\DeliveryData::incrementQueueFailed($item['uri-id'] ?? 0);
} }
return; return;
} }
Logger::info('Invoked', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $target_id, 'uid' => $uid]); Logger::info('Invoked', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $item_id, 'uid' => $uid]);
$success = true; $success = true;
if ($cmd == Delivery::MAIL) { if ($cmd == Delivery::MAIL) {
$data = ActivityPub\Transmitter::createActivityFromMail($target_id); $data = ActivityPub\Transmitter::createActivityFromMail($item_id);
if (!empty($data)) { if (!empty($data)) {
$success = HTTPSignature::transmit($data, $inbox, $uid); $success = HTTPSignature::transmit($data, $inbox, $uid);
} }
} elseif ($cmd == Delivery::SUGGESTION) { } elseif ($cmd == Delivery::SUGGESTION) {
$success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $target_id); $success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $item_id);
} elseif ($cmd == Delivery::RELOCATION) { } elseif ($cmd == Delivery::RELOCATION) {
// @todo Implementation pending // @todo Implementation pending
} elseif ($cmd == Delivery::POKE) { } elseif ($cmd == Delivery::POKE) {
@ -95,14 +73,14 @@ class APDelivery
} elseif ($cmd == Delivery::PROFILEUPDATE) { } elseif ($cmd == Delivery::PROFILEUPDATE) {
$success = ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox); $success = ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox);
} else { } else {
$data = ActivityPub\Transmitter::createCachedActivityFromItem($target_id); $data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
if (!empty($data)) { if (!empty($data)) {
$success = HTTPSignature::transmit($data, $inbox, $uid); $success = HTTPSignature::transmit($data, $inbox, $uid);
} }
} }
// This should never fail and is temporariy (until the move to the "post" structure) // This should never fail and is temporariy (until the move to the "post" structure)
$item = Item::selectFirst(['uri-id'], ['id' => $target_id]); $item = Item::selectFirst(['uri-id'], ['id' => $item_id]);
$uriid = $item['uri-id'] ?? 0; $uriid = $item['uri-id'] ?? 0;
foreach ($receivers as $receiver) { foreach ($receivers as $receiver) {

View file

@ -81,10 +81,10 @@ class Notifier
$mail = ActivityPub\Transmitter::ItemArrayFromMail($target_id); $mail = ActivityPub\Transmitter::ItemArrayFromMail($target_id);
$inboxes = ActivityPub\Transmitter::fetchTargetInboxes($mail, $uid, true); $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($mail, $uid, true);
foreach ($inboxes as $inbox) { foreach ($inboxes as $inbox => $receivers) {
Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'target' => $target_id, 'inbox' => $inbox]); Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'target' => $target_id, 'inbox' => $inbox]);
Worker::add(['priority' => PRIORITY_HIGH, 'created' => $a->queue['created'], 'dont_fork' => true], Worker::add(['priority' => PRIORITY_HIGH, 'created' => $a->queue['created'], 'dont_fork' => true],
'APDelivery', $cmd, $target_id, $inbox, $uid); 'APDelivery', $cmd, $target_id, $inbox, $uid, $receivers);
} }
} elseif ($cmd == Delivery::SUGGESTION) { } elseif ($cmd == Delivery::SUGGESTION) {
$suggest = DI::fsuggest()->getById($target_id); $suggest = DI::fsuggest()->getById($target_id);
@ -744,10 +744,10 @@ class Notifier
DBA::close($contacts_stmt); DBA::close($contacts_stmt);
$inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0); $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0);
foreach ($inboxes as $inbox) { foreach ($inboxes as $inbox => $receivers) {
Logger::info('Account removal via ActivityPub', ['uid' => $self_user_id, 'inbox' => $inbox]); Logger::info('Account removal via ActivityPub', ['uid' => $self_user_id, 'inbox' => $inbox]);
Worker::add(['priority' => PRIORITY_NEGLIGIBLE, 'created' => $created, 'dont_fork' => true], Worker::add(['priority' => PRIORITY_NEGLIGIBLE, 'created' => $created, 'dont_fork' => true],
'APDelivery', Delivery::REMOVAL, '', $inbox, $self_user_id); 'APDelivery', Delivery::REMOVAL, 0, $inbox, $self_user_id, $receivers);
} }
return true; return true;

View file

@ -40,10 +40,10 @@ class ProfileUpdate {
$inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser($uid); $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser($uid);
foreach ($inboxes as $inbox) { foreach ($inboxes as $inbox => $receivers) {
Logger::log('Profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', Logger::DEBUG); Logger::log('Profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', Logger::DEBUG);
Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true], Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
'APDelivery', Delivery::PROFILEUPDATE, '', $inbox, $uid); 'APDelivery', Delivery::PROFILEUPDATE, 0, $inbox, $uid, $receivers);
} }
Diaspora::sendProfile($uid); Diaspora::sendProfile($uid);