mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-11 01:24:27 +02:00
Support for message delivering via uri-id
This commit is contained in:
parent
07c07ec499
commit
6e1483545e
10 changed files with 95 additions and 56 deletions
|
@ -25,7 +25,6 @@ use Friendica\Core\Logger;
|
|||
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;
|
||||
|
@ -40,10 +39,11 @@ class APDelivery
|
|||
* @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
|
||||
* @param int $uri_id URI-ID of item to be transmitted
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function execute(string $cmd, int $item_id, string $inbox, int $uid, array $receivers = [])
|
||||
public static function execute(string $cmd, int $item_id, string $inbox, int $uid, array $receivers = [], int $uri_id = 0)
|
||||
{
|
||||
if (ActivityPub\Transmitter::archivedInbox($inbox)) {
|
||||
Logger::info('Inbox is archived', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $item_id, 'uid' => $uid]);
|
||||
|
@ -54,7 +54,19 @@ class APDelivery
|
|||
return;
|
||||
}
|
||||
|
||||
Logger::info('Invoked', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $item_id, 'uid' => $uid]);
|
||||
if (empty($uri_id) && !empty($item_id)) {
|
||||
$item = Post::selectFirst(['uri-id'], ['id' => $item_id]);
|
||||
if (!empty($item['uri-id'])) {
|
||||
$uri_id = $item['uri-id'];
|
||||
}
|
||||
} elseif (!empty($uri_id) && !empty($item_id)) {
|
||||
$item = Post::selectFirst(['id'], ['uri-id' => $uri_id, 'uid' => $uid]);
|
||||
if (!empty($item['uri-id'])) {
|
||||
$item_id = $item['id'];
|
||||
}
|
||||
}
|
||||
|
||||
Logger::info('Invoked', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $item_id, 'uri-id' => $uri_id, 'uid' => $uid]);
|
||||
|
||||
$success = true;
|
||||
|
||||
|
@ -81,8 +93,6 @@ class APDelivery
|
|||
}
|
||||
|
||||
// This should never fail and is temporariy (until the move to the "post" structure)
|
||||
$item = Post::selectFirst(['uri-id'], ['id' => $item_id]);
|
||||
$uriid = $item['uri-id'] ?? 0;
|
||||
$gsid = null;
|
||||
|
||||
foreach ($receivers as $receiver) {
|
||||
|
@ -105,9 +115,9 @@ class APDelivery
|
|||
}
|
||||
|
||||
if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) {
|
||||
Post\DeliveryData::incrementQueueFailed($uriid);
|
||||
Post\DeliveryData::incrementQueueFailed($uri_id);
|
||||
} elseif ($success && in_array($cmd, [Delivery::POST])) {
|
||||
Post\DeliveryData::incrementQueueDone($uriid, Post\DeliveryData::ACTIVITYPUB);
|
||||
Post\DeliveryData::incrementQueueDone($uri_id, Post\DeliveryData::ACTIVITYPUB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ use Friendica\Core\Worker;
|
|||
use Friendica\Model\Conversation;
|
||||
use Friendica\Model\FContact;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Protocol\Relay;
|
||||
|
||||
class Delivery
|
||||
|
@ -50,9 +51,20 @@ class Delivery
|
|||
const REMOVAL = 'removeme';
|
||||
const PROFILEUPDATE = 'profileupdate';
|
||||
|
||||
public static function execute($cmd, $target_id, $contact_id)
|
||||
public static function execute(string $cmd, int $post_uriid, int $contact_id, int $sender_uid = 0)
|
||||
{
|
||||
Logger::info('Invoked', ['cmd' => $cmd, 'target' => $target_id, 'contact' => $contact_id]);
|
||||
Logger::info('Invoked', ['cmd' => $cmd, 'target' => $post_uriid, 'sender_uid' => $sender_uid, 'contact' => $contact_id]);
|
||||
|
||||
if (!empty($sender_uid)) {
|
||||
$post = Post::selectFirst(['id'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
|
||||
if (!DBA::isResult($post)) {
|
||||
Logger::warning('Post not found', ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
|
||||
return;
|
||||
}
|
||||
$target_id = $post['id'];
|
||||
} else {
|
||||
$target_id = $post_uriid;
|
||||
}
|
||||
|
||||
$top_level = false;
|
||||
$followup = false;
|
||||
|
|
|
@ -53,11 +53,22 @@ use Friendica\Protocol\Salmon;
|
|||
|
||||
class Notifier
|
||||
{
|
||||
public static function execute(string $cmd, int $target_id)
|
||||
public static function execute(string $cmd, int $post_uriid, int $sender_uid = 0)
|
||||
{
|
||||
$a = DI::app();
|
||||
|
||||
Logger::info('Invoked', ['cmd' => $cmd, 'target' => $target_id]);
|
||||
Logger::info('Invoked', ['cmd' => $cmd, 'target' => $post_uriid, 'sender_uid' => $sender_uid]);
|
||||
|
||||
if (!empty($sender_uid)) {
|
||||
$post = Post::selectFirst(['id'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
|
||||
if (!DBA::isResult($post)) {
|
||||
Logger::warning('Post not found', ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
|
||||
return;
|
||||
}
|
||||
$target_id = $post['id'];
|
||||
} else {
|
||||
$target_id = $post_uriid;
|
||||
}
|
||||
|
||||
$top_level = false;
|
||||
$recipients = [];
|
||||
|
@ -85,7 +96,7 @@ class Notifier
|
|||
$ap_contacts = array_merge($ap_contacts, $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, $receivers);
|
||||
'APDelivery', $cmd, $target_id, $inbox, $uid, $receivers, $post_uriid);
|
||||
}
|
||||
} elseif ($cmd == Delivery::SUGGESTION) {
|
||||
$suggest = DI::fsuggest()->getById($target_id);
|
||||
|
@ -305,8 +316,8 @@ class Notifier
|
|||
/// @todo Possibly we should not uplink when the author is the forum itself?
|
||||
|
||||
if ((intval($parent['forum_mode']) == 1) && !$top_level && ($cmd !== Delivery::UPLINK)
|
||||
&& ($target_item['verb'] != Activity::ANNOUNCE)) {
|
||||
Worker::add($a->queue['priority'], 'Notifier', Delivery::UPLINK, $target_id);
|
||||
&& ($target_item['verb'] != Activity::ANNOUNCE)) {
|
||||
Worker::add($a->queue['priority'], 'Notifier', Delivery::UPLINK, $post_uriid, $sender_uid);
|
||||
}
|
||||
|
||||
foreach ($items as $item) {
|
||||
|
@ -452,13 +463,13 @@ class Notifier
|
|||
|
||||
$conversants = array_merge($contacts, $relay_list);
|
||||
|
||||
$delivery_queue_count += self::delivery($cmd, $target_id, $target_item, $thr_parent, $owner, $batch_delivery, true, $conversants, $ap_contacts, []);
|
||||
$delivery_queue_count += self::delivery($cmd, $post_uriid, $sender_uid, $target_item, $thr_parent, $owner, $batch_delivery, true, $conversants, $ap_contacts, []);
|
||||
|
||||
$push_notify = true;
|
||||
}
|
||||
|
||||
$contacts = DBA::toArray($delivery_contacts_stmt);
|
||||
$delivery_queue_count += self::delivery($cmd, $target_id, $target_item, $thr_parent, $owner, $batch_delivery, false, $contacts, $ap_contacts, $conversants);
|
||||
$delivery_queue_count += self::delivery($cmd, $post_uriid, $sender_uid, $target_item, $thr_parent, $owner, $batch_delivery, false, $contacts, $ap_contacts, $conversants);
|
||||
|
||||
$delivery_queue_count += self::deliverOStatus($target_id, $target_item, $owner, $url_recipients, $public_message, $push_notify);
|
||||
|
||||
|
@ -487,7 +498,8 @@ class Notifier
|
|||
* Deliver the message to the contacts
|
||||
*
|
||||
* @param string $cmd
|
||||
* @param int $target_id
|
||||
* @param int $post_uriid
|
||||
* @param int $sender_uid
|
||||
* @param array $target_item
|
||||
* @param array $thr_parent
|
||||
* @param array $owner
|
||||
|
@ -499,7 +511,7 @@ class Notifier
|
|||
* @throws InternalServerErrorException
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function delivery(string $cmd, int $target_id, array $target_item, array $thr_parent, array $owner, bool $batch_delivery, bool $in_batch, array $contacts, array $ap_contacts, array $conversants = [])
|
||||
private static function delivery(string $cmd, int $post_uriid, int $sender_uid, array $target_item, array $thr_parent, array $owner, bool $batch_delivery, bool $in_batch, array $contacts, array $ap_contacts, array $conversants = [])
|
||||
{
|
||||
$a = DI::app();
|
||||
$delivery_queue_count = 0;
|
||||
|
@ -511,38 +523,38 @@ class Notifier
|
|||
}
|
||||
|
||||
if (in_array($contact['id'], $ap_contacts)) {
|
||||
Logger::info('Contact is already delivered via AP, so skip delivery via legacy DFRN/Diaspora', ['target' => $target_id, 'contact' => $contact['url']]);
|
||||
Logger::info('Contact is already delivered via AP, so skip delivery via legacy DFRN/Diaspora', ['target' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact['url']]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($contact['id']) && Contact::isArchived($contact['id'])) {
|
||||
Logger::info('Contact is archived, so skip delivery', ['target' => $target_id, 'contact' => $contact['url']]);
|
||||
Logger::info('Contact is archived, so skip delivery', ['target' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact['url']]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (self::isRemovalActivity($cmd, $owner, $contact['network'])) {
|
||||
Logger::info('Contact does no supports account removal commands, so skip delivery', ['target' => $target_id, 'contact' => $contact['url']]);
|
||||
Logger::info('Contact does no supports account removal commands, so skip delivery', ['target' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact['url']]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (self::skipActivityPubForDiaspora($contact, $target_item, $thr_parent)) {
|
||||
Logger::info('Contact is from Diaspora, but the replied author is from ActivityPub, so skip delivery via Diaspora', ['id' => $target_id, 'url' => $contact['url']]);
|
||||
Logger::info('Contact is from Diaspora, but the replied author is from ActivityPub, so skip delivery via Diaspora', ['id' => $post_uriid, 'uid' => $sender_uid, 'url' => $contact['url']]);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't deliver to Diaspora if it already had been done as batch delivery
|
||||
if (!$in_batch && $batch_delivery && ($contact['network'] == Protocol::DIASPORA)) {
|
||||
Logger::info('Diaspora contact is already delivered via batch', ['id' => $target_id, 'contact' => $contact]);
|
||||
Logger::info('Diaspora contact is already delivered via batch', ['id' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact]);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't deliver to folks who have already been delivered to
|
||||
if (in_array($contact['id'], $conversants)) {
|
||||
Logger::info('Already delivery', ['id' => $target_id, 'contact' => $contact]);
|
||||
Logger::info('Already delivery', ['id' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact]);
|
||||
continue;
|
||||
}
|
||||
|
||||
Logger::info('Delivery', ['batch' => $in_batch, 'target' => $target_id, 'guid' => $target_item['guid'] ?? '', 'to' => $contact]);
|
||||
Logger::info('Delivery', ['batch' => $in_batch, 'target' => $post_uriid, 'uid' => $sender_uid, 'guid' => $target_item['guid'] ?? '', 'to' => $contact]);
|
||||
|
||||
// Ensure that posts with our own protocol arrives before Diaspora posts arrive.
|
||||
// Situation is that sometimes Friendica servers receive Friendica posts over the Diaspora protocol first.
|
||||
|
@ -554,7 +566,7 @@ class Notifier
|
|||
$deliver_options = ['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true];
|
||||
}
|
||||
|
||||
if (Worker::add($deliver_options, 'Delivery', $cmd, $target_id, (int)$contact['id'])) {
|
||||
if (Worker::add($deliver_options, 'Delivery', $cmd, $post_uriid, (int)$contact['id'], $sender_uid)) {
|
||||
$delivery_queue_count++;
|
||||
}
|
||||
}
|
||||
|
@ -767,7 +779,7 @@ class Notifier
|
|||
Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'id' => $target_item['id'], 'inbox' => $inbox]);
|
||||
|
||||
if (Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true],
|
||||
'APDelivery', $cmd, $target_item['id'], $inbox, $uid, $receivers)) {
|
||||
'APDelivery', $cmd, $target_item['id'], $inbox, $uid, $receivers, $target_item['uri-id'])) {
|
||||
$delivery_queue_count++;
|
||||
}
|
||||
}
|
||||
|
@ -776,7 +788,7 @@ class Notifier
|
|||
foreach ($relay_inboxes as $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, [], $target_item['uri-id'])) {
|
||||
$delivery_queue_count++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue