Merge pull request #9651 from annando/ap-archive
Archive/Unarchive at ActivityPub delivery
This commit is contained in:
commit
0bd557132c
|
@ -809,7 +809,7 @@ class Contact
|
||||||
Logger::info('Empty contact', ['contact' => $contact, 'callstack' => System::callstack(20)]);
|
Logger::info('Empty contact', ['contact' => $contact, 'callstack' => System::callstack(20)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::info('Contact is marked for archival', ['id' => $contact['id']]);
|
Logger::info('Contact is marked for archival', ['id' => $contact['id'], 'term-date' => $contact['term-date']]);
|
||||||
|
|
||||||
// Contact already archived or "self" contact? => nothing to do
|
// Contact already archived or "self" contact? => nothing to do
|
||||||
if ($contact['archive'] || $contact['self']) {
|
if ($contact['archive'] || $contact['self']) {
|
||||||
|
@ -867,7 +867,7 @@ class Contact
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::info('Contact is marked as vital again', ['id' => $contact['id']]);
|
Logger::info('Contact is marked as vital again', ['id' => $contact['id'], 'term-date' => $contact['term-date']]);
|
||||||
|
|
||||||
if (!isset($contact['url']) && !empty($contact['id'])) {
|
if (!isset($contact['url']) && !empty($contact['id'])) {
|
||||||
$fields = ['id', 'url', 'batch'];
|
$fields = ['id', 'url', 'batch'];
|
||||||
|
|
|
@ -74,7 +74,7 @@ class Transmitter
|
||||||
["`type` = ? AND `url` IN (SELECT `url` FROM `contact` WHERE `uid` = ? AND `rel` IN (?, ?))",
|
["`type` = ? AND `url` IN (SELECT `url` FROM `contact` WHERE `uid` = ? AND `rel` IN (?, ?))",
|
||||||
'Application', 0, Contact::FOLLOWER, Contact::FRIEND]);
|
'Application', 0, Contact::FOLLOWER, Contact::FRIEND]);
|
||||||
while ($contact = DBA::fetch($contacts)) {
|
while ($contact = DBA::fetch($contacts)) {
|
||||||
$inboxes[] = $contact['inbox'];
|
$inboxes[$contact['inbox']] = $contact['inbox'];
|
||||||
}
|
}
|
||||||
DBA::close($contacts);
|
DBA::close($contacts);
|
||||||
|
|
||||||
|
@ -89,15 +89,19 @@ class Transmitter
|
||||||
*/
|
*/
|
||||||
public static function addRelayServerInboxesForItem(int $item_id, array $inboxes = [])
|
public static function addRelayServerInboxesForItem(int $item_id, array $inboxes = [])
|
||||||
{
|
{
|
||||||
|
$item = Item::selectFirst(['uid'], ['id' => $item_id]);
|
||||||
|
if (empty($item)) {
|
||||||
|
return $inboxes;
|
||||||
|
}
|
||||||
|
|
||||||
$relays = Relay::getList($item_id, [], [Protocol::ACTIVITYPUB]);
|
$relays = Relay::getList($item_id, [], [Protocol::ACTIVITYPUB]);
|
||||||
if (empty($relays)) {
|
if (empty($relays)) {
|
||||||
return $inboxes;
|
return $inboxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($relays as $relay) {
|
foreach ($relays as $relay) {
|
||||||
if (!in_array($relay['batch'], $inboxes)) {
|
$contact = Contact::getByURLForUser($relay['url'], $item['uid'], false, ['id']);
|
||||||
$inboxes[] = $relay['batch'];
|
$inboxes[$relay['batch']][] = $contact['id'] ?? 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $inboxes;
|
return $inboxes;
|
||||||
}
|
}
|
||||||
|
@ -728,7 +732,7 @@ class Transmitter
|
||||||
$condition['rel'] = [Contact::FOLLOWER, Contact::FRIEND];
|
$condition['rel'] = [Contact::FOLLOWER, Contact::FRIEND];
|
||||||
}
|
}
|
||||||
|
|
||||||
$contacts = DBA::select('contact', ['url', 'network', 'protocol'], $condition);
|
$contacts = DBA::select('contact', ['id', 'url', 'network', 'protocol'], $condition);
|
||||||
while ($contact = DBA::fetch($contacts)) {
|
while ($contact = DBA::fetch($contacts)) {
|
||||||
if (Contact::isLocal($contact['url'])) {
|
if (Contact::isLocal($contact['url'])) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -754,7 +758,7 @@ class Transmitter
|
||||||
$target = $profile['sharedinbox'];
|
$target = $profile['sharedinbox'];
|
||||||
}
|
}
|
||||||
if (!self::archivedInbox($target)) {
|
if (!self::archivedInbox($target)) {
|
||||||
$inboxes[$target] = $target;
|
$inboxes[$target][] = $contact['id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -817,13 +821,15 @@ class Transmitter
|
||||||
|
|
||||||
$profile = APContact::getByURL($receiver, false);
|
$profile = APContact::getByURL($receiver, false);
|
||||||
if (!empty($profile)) {
|
if (!empty($profile)) {
|
||||||
|
$contact = Contact::getByURLForUser($receiver, $uid, false, ['id']);
|
||||||
|
|
||||||
if (empty($profile['sharedinbox']) || $personal || $blindcopy) {
|
if (empty($profile['sharedinbox']) || $personal || $blindcopy) {
|
||||||
$target = $profile['inbox'];
|
$target = $profile['inbox'];
|
||||||
} else {
|
} else {
|
||||||
$target = $profile['sharedinbox'];
|
$target = $profile['sharedinbox'];
|
||||||
}
|
}
|
||||||
if (!self::archivedInbox($target)) {
|
if (!self::archivedInbox($target)) {
|
||||||
$inboxes[$target] = $target;
|
$inboxes[$target][] = $contact['id'] ?? 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace Friendica\Worker;
|
||||||
|
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\Logger;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
|
@ -37,10 +38,11 @@ class APDelivery
|
||||||
* @param integer $target_id
|
* @param integer $target_id
|
||||||
* @param string $inbox
|
* @param string $inbox
|
||||||
* @param integer $uid
|
* @param integer $uid
|
||||||
|
* @param array $receivers
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function execute($cmd, $target_id, $inbox, $uid)
|
public static function execute($cmd, $target_id, $inbox, $uid, $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' => $target_id, 'uid' => $uid]);
|
||||||
|
@ -81,6 +83,19 @@ class APDelivery
|
||||||
$item = Item::selectFirst(['uri-id'], ['id' => $target_id]);
|
$item = Item::selectFirst(['uri-id'], ['id' => $target_id]);
|
||||||
$uriid = $item['uri-id'] ?? 0;
|
$uriid = $item['uri-id'] ?? 0;
|
||||||
|
|
||||||
|
foreach ($receivers as $receiver) {
|
||||||
|
$contact = Contact::getById($receiver);
|
||||||
|
if (empty($contact)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($success) {
|
||||||
|
Contact::unmarkForArchival($contact);
|
||||||
|
} else {
|
||||||
|
Contact::markForArchival($contact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) {
|
if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) {
|
||||||
Post\DeliveryData::incrementQueueFailed($uriid);
|
Post\DeliveryData::incrementQueueFailed($uriid);
|
||||||
} elseif ($success && in_array($cmd, [Delivery::POST])) {
|
} elseif ($success && in_array($cmd, [Delivery::POST])) {
|
||||||
|
|
|
@ -824,20 +824,20 @@ class Notifier
|
||||||
|
|
||||||
$delivery_queue_count = 0;
|
$delivery_queue_count = 0;
|
||||||
|
|
||||||
foreach ($inboxes as $inbox) {
|
foreach ($inboxes as $inbox => $receivers) {
|
||||||
Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'id' => $target_item['id'], 'inbox' => $inbox]);
|
Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'id' => $target_item['id'], 'inbox' => $inbox]);
|
||||||
|
|
||||||
if (Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true],
|
if (Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true],
|
||||||
'APDelivery', $cmd, $target_item['id'], $inbox, $uid)) {
|
'APDelivery', $cmd, $target_item['id'], $inbox, $uid, $receivers)) {
|
||||||
$delivery_queue_count++;
|
$delivery_queue_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We deliver posts to relay servers slightly delayed to priorize the direct delivery
|
// We deliver posts to relay servers slightly delayed to priorize the direct delivery
|
||||||
foreach ($relay_inboxes as $inbox) {
|
foreach ($relay_inboxes as $inbox => $receivers) {
|
||||||
Logger::info('Delivery to relay servers via ActivityPub', ['cmd' => $cmd, 'id' => $target_item['id'], 'inbox' => $inbox]);
|
Logger::info('Delivery to relay servers via ActivityPub', ['cmd' => $cmd, 'id' => $target_item['id'], 'inbox' => $inbox]);
|
||||||
|
|
||||||
if (Worker::add(['priority' => $priority, 'dont_fork' => true], 'APDelivery', $cmd, $target_item['id'], $inbox, $uid)) {
|
if (Worker::add(['priority' => $priority, 'dont_fork' => true], 'APDelivery', $cmd, $target_item['id'], $inbox, $uid, $receivers)) {
|
||||||
$delivery_queue_count++;
|
$delivery_queue_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user