+ private static function deliver(string $inbox)
+ {
+ $uri_ids = [];
+ $success = true;
+
+ $posts = Post\Delivery::selectForInbox($inbox);
+ foreach ($posts as $post) {
+ $uri_ids[] = $post['uri-id'];
+ if ($success) {
+ $success = self::deliverToInbox($post['command'], 0, $inbox, $post['uid'], [], $post['uri-id']);
+ }
+ }
+
+ return ['success' => $success, 'uri_ids' => $uri_ids];
+ }
+
+ private static function deliverToInbox(string $cmd, int $item_id, string $inbox, int $uid, array $receivers, int $uri_id)
+ {
+ if (empty($item_id) && !empty($uri_id) && !empty($uid)) {
+ $item = Post::selectFirst(['id', 'parent', 'origin'], ['uri-id' => $uri_id, 'uid' => $uid]);
+ $item_id = $item['id'] ?? 0;
+ if (empty($receivers) && !empty($item)) {
+ $parent = Post::selectFirst(Item::DELIVER_FIELDLIST, ['id' => $item['parent']]);
+
+ $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid);
+ $receivers = $inboxes[$inbox] ?? [];
+
+ // When we haven't fetched the receiver list, it can be a personal inbox
+ if (empty($receivers)) {
+ $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid, true);
+ $receivers = $inboxes[$inbox] ?? [];
+ }
+ }
+ }