`created` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
`command` varbinary(32) COMMENT '',
`failed` tinyint DEFAULT 0 COMMENT 'Number of times the delivery has failed',
+ `receivers` mediumtext COMMENT 'JSON encoded array with the receiving contacts',
PRIMARY KEY(`uri-id`,`inbox-id`),
INDEX `inbox-id_created` (`inbox-id`,`created`),
INDEX `uid` (`uid`),
Fields
------
-| Field | Description | Type | Null | Key | Default | Extra |
-| -------- | --------------------------------------------------------- | ------------------ | ---- | --- | ------------------- | ----- |
-| uri-id | Id of the item-uri table entry that contains the item uri | int unsigned | NO | PRI | NULL | |
-| inbox-id | Item-uri id of inbox url | int unsigned | NO | PRI | NULL | |
-| uid | Delivering user | mediumint unsigned | YES | | NULL | |
-| created | | datetime | YES | | 0001-01-01 00:00:00 | |
-| command | | varbinary(32) | YES | | NULL | |
-| failed | Number of times the delivery has failed | tinyint | YES | | 0 | |
+| Field | Description | Type | Null | Key | Default | Extra |
+| --------- | --------------------------------------------------------- | ------------------ | ---- | --- | ------------------- | ----- |
+| uri-id | Id of the item-uri table entry that contains the item uri | int unsigned | NO | PRI | NULL | |
+| inbox-id | Item-uri id of inbox url | int unsigned | NO | PRI | NULL | |
+| uid | Delivering user | mediumint unsigned | YES | | NULL | |
+| created | | datetime | YES | | 0001-01-01 00:00:00 | |
+| command | | varbinary(32) | YES | | NULL | |
+| failed | Number of times the delivery has failed | tinyint | YES | | 0 | |
+| receivers | JSON encoded array with the receiving contacts | mediumtext | YES | | NULL | |
Indexes
------------
* @param integer $uri_id
* @param string $inbox
* @param string $created
+ * @param array %receivers
*/
- public static function add(int $uri_id, int $uid, string $inbox, string $created, string $command)
+ public static function add(int $uri_id, int $uid, string $inbox, string $created, string $command, array $receivers)
{
if (empty($uri_id)) {
throw new BadMethodCallException('Empty URI_id');
}
- $fields = ['uri-id' => $uri_id, 'uid' => $uid, 'inbox-id' => ItemURI::getIdByURI($inbox), 'created' => $created, 'command' => $command];
+ $fields = ['uri-id' => $uri_id, 'uid' => $uid, 'inbox-id' => ItemURI::getIdByURI($inbox),
+ 'created' => $created, 'command' => $command, 'receivers' => json_encode($receivers)];
DBA::insert('post-delivery', $fields, Database::INSERT_IGNORE);
}
public static function selectForInbox(string $inbox)
{
- return DBA::selectToArray('post-delivery', [], ['inbox-id' => ItemURI::getIdByURI($inbox)], ['order' => ['created']]);
+ $rows = DBA::select('post-delivery', [], ['inbox-id' => ItemURI::getIdByURI($inbox)], ['order' => ['created']]);
+ $deliveries = [];
+ while ($row = DBA::fetch($rows)) {
+ if (!empty($row['receivers'])) {
+ $row['receivers'] = json_decode($row['receivers'], true);
+ } else {
+ $row['receivers'] = [];
+ }
+ $deliveries[] = $row;
+ }
+ DBA::close($rows);
+
+ return $deliveries;
}
}
use Friendica\Core\Worker;
use Friendica\Model\Contact;
use Friendica\Model\GServer;
-use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\HTTPSignature;
$posts = Post\Delivery::selectForInbox($inbox);
foreach ($posts as $post) {
- if (!self::deliverToInbox($post['command'], 0, $inbox, $post['uid'], [], $post['uri-id'])) {
+ if (!self::deliverToInbox($post['command'], 0, $inbox, $post['uid'], $post['receivers'], $post['uri-id'])) {
$uri_ids[] = $post['uri-id'];
}
}
{
if (empty($item_id) && !empty($uri_id) && !empty($uid)) {
$item = Post::selectFirst(['id', 'parent', 'origin'], ['uri-id' => $uri_id, 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
- $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] ?? [];
- }
- } elseif (empty($item_id)) {
+ if (empty($item['id'])) {
Logger::debug('Item not found, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]);
Post\Delivery::remove($uri_id, $inbox);
return true;
+ } else {
+ $item_id = $item['id'];
}
}
if (DI::config()->get('system', 'bulk_delivery')) {
$delivery_queue_count++;
- Post\Delivery::add($target_item['uri-id'], $uid, $inbox, $target_item['created'], $cmd);
+ Post\Delivery::add($target_item['uri-id'], $uid, $inbox, $target_item['created'], $cmd, $receivers);
Worker::add(PRIORITY_HIGH, 'APDelivery', '', 0, $inbox, 0);
} else {
if (Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true],
if (DI::config()->get('system', 'bulk_delivery')) {
$delivery_queue_count++;
- Post\Delivery::add($target_item['uri-id'], $uid, $inbox, $target_item['created'], $cmd);
+ Post\Delivery::add($target_item['uri-id'], $uid, $inbox, $target_item['created'], $cmd, []);
Worker::add(PRIORITY_MEDIUM, 'APDelivery', '', 0, $inbox, 0);
} else {
if (Worker::add(['priority' => $priority, 'dont_fork' => true], 'APDelivery', $cmd, $target_item['id'], $inbox, $uid, [], $target_item['uri-id'])) {
"created" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
"command" => ["type" => "varbinary(32)", "comment" => ""],
"failed" => ["type" => "tinyint", "default" => 0, "comment" => "Number of times the delivery has failed"],
+ "receivers" => ["type" => "mediumtext", "comment" => "JSON encoded array with the receiving contacts"],
],
"indexes" => [
"PRIMARY" => ["uri-id", "inbox-id"],