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:
parent
e4228c6218
commit
d59fcd5093
|
@ -34,58 +34,36 @@ class APDelivery
|
|||
/**
|
||||
* Delivers ActivityPub messages
|
||||
*
|
||||
* @param string $cmd
|
||||
* @param integer $target_id
|
||||
* @param string|array $inboxes
|
||||
* @param integer $uid
|
||||
* @param array $receivers
|
||||
* @param string $cmd One of the Worker\Delivery constant values
|
||||
* @param integer $item_id 0 if no item is involved (like Delivery::REMOVAL and Delivery::PROFILEUPDATE)
|
||||
* @param string $inbox The URL of the recipient profile
|
||||
* @param integer $uid The ID of the user who triggered this delivery
|
||||
* @param array $receivers The contact IDs related to the inbox URL for contact archival housekeeping
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function execute(string $cmd, int $target_id, $inboxes, 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 = [])
|
||||
public static function execute(string $cmd, int $item_id, string $inbox, int $uid, array $receivers = [])
|
||||
{
|
||||
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])) {
|
||||
$item = Item::selectFirst(['uri-id'], ['id' => $target_id]);
|
||||
$item = Item::selectFirst(['uri-id'], ['id' => $item_id]);
|
||||
Post\DeliveryData::incrementQueueFailed($item['uri-id'] ?? 0);
|
||||
}
|
||||
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;
|
||||
|
||||
if ($cmd == Delivery::MAIL) {
|
||||
$data = ActivityPub\Transmitter::createActivityFromMail($target_id);
|
||||
$data = ActivityPub\Transmitter::createActivityFromMail($item_id);
|
||||
if (!empty($data)) {
|
||||
$success = HTTPSignature::transmit($data, $inbox, $uid);
|
||||
}
|
||||
} elseif ($cmd == Delivery::SUGGESTION) {
|
||||
$success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $target_id);
|
||||
$success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $item_id);
|
||||
} elseif ($cmd == Delivery::RELOCATION) {
|
||||
// @todo Implementation pending
|
||||
} elseif ($cmd == Delivery::POKE) {
|
||||
|
@ -95,14 +73,14 @@ class APDelivery
|
|||
} elseif ($cmd == Delivery::PROFILEUPDATE) {
|
||||
$success = ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox);
|
||||
} else {
|
||||
$data = ActivityPub\Transmitter::createCachedActivityFromItem($target_id);
|
||||
$data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
|
||||
if (!empty($data)) {
|
||||
$success = HTTPSignature::transmit($data, $inbox, $uid);
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
foreach ($receivers as $receiver) {
|
||||
|
|
|
@ -81,10 +81,10 @@ class Notifier
|
|||
|
||||
$mail = ActivityPub\Transmitter::ItemArrayFromMail($target_id);
|
||||
$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]);
|
||||
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) {
|
||||
$suggest = DI::fsuggest()->getById($target_id);
|
||||
|
@ -744,10 +744,10 @@ class Notifier
|
|||
DBA::close($contacts_stmt);
|
||||
|
||||
$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]);
|
||||
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;
|
||||
|
|
|
@ -40,10 +40,10 @@ class ProfileUpdate {
|
|||
|
||||
$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);
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue