mirror of
https://github.com/friendica/friendica
synced 2025-04-28 13:44:25 +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
|
@ -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