From 41f8796ffc557c00b8bd957aba010180ab87d207 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 6 Dec 2019 06:39:50 +0000 Subject: [PATCH 1/5] Delivery of reshares --- src/Protocol/ActivityPub/Transmitter.php | 19 ++++++++++++++++++- src/Worker/Delivery.php | 11 +++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 5bb03a8517..0b7784848e 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -363,7 +363,7 @@ class Transmitter } } - if (Config::get('debug', 'total_ap_delivery')) { + if (self::isAnnounce($item) || Config::get('debug', 'total_ap_delivery')) { // Will be activated in a later step $networks = Protocol::FEDERATED; } else { @@ -1423,6 +1423,23 @@ class Transmitter return ['object' => $reshared_item, 'actor' => $profile, 'comment' => $reshared['comment']]; } + /** + * Checks if the provided item array is an announce + * + * @param array $item + * + * @return boolean + */ + public static function isAnnounce($item) + { + $announce = self::getAnnounceArray($item); + if (empty($announce)) { + return false; + } + + return empty($announce['comment']); + } + /** * Creates an activity id for a given contact id * diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index d9a2109ba3..e59ea37aad 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -251,6 +251,17 @@ class Delivery extends BaseObject */ private static function deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup) { +/* + if (Diaspora::isReshare($target_item['body'])) { + // Transmit Diaspora reshares only via Diaspora + self::deliverDiaspora($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup); + return; + } + + if (ActivityPub\Transmitter::::isAnnounce($target_item) && getby) { + return; + } +*/ Logger::info('Deliver ' . (($target_item['guid'] ?? '') ?: $target_item['id']) . ' via DFRN to ' . (($contact['addr'] ?? '') ?: $contact['url'])); if ($cmd == self::MAIL) { From 7ccbe3ee29789d48dc38ae03fb0692ae25baff08 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 8 Dec 2019 08:59:21 +0000 Subject: [PATCH 2/5] Transmit reshares and announce natively via Diaspora and AP whenever possible --- src/Worker/Delivery.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index e59ea37aad..cc06f17923 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -251,17 +251,19 @@ class Delivery extends BaseObject */ private static function deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup) { -/* - if (Diaspora::isReshare($target_item['body'])) { - // Transmit Diaspora reshares only via Diaspora + // Transmit Diaspora reshares via Diaspora if the Friendica contact support Diaspora + if (Diaspora::isReshare($target_item['body']) && !empty(Diaspora::personByHandle(contact['addr'], false))) { + Logger::info('Reshare will be transmitted via Diaspora', ['url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id']]); self::deliverDiaspora($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup); return; } - if (ActivityPub\Transmitter::::isAnnounce($target_item) && getby) { + // Skip transmitting the announce via DFRN when it had already been done via AP + if (ActivityPub\Transmitter::isAnnounce($target_item) && !empty(Model\APContact::getByURL($contact['url'], false))) { + Logger::info('Announce had already been transmitted', ['url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id']]); return; } -*/ + Logger::info('Deliver ' . (($target_item['guid'] ?? '') ?: $target_item['id']) . ' via DFRN to ' . (($contact['addr'] ?? '') ?: $contact['url'])); if ($cmd == self::MAIL) { From aa047278cc07a004e290f10bae9b7784e07e2fe2 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 8 Dec 2019 09:01:06 +0000 Subject: [PATCH 3/5] Reversed annouce check to have priority for AP --- src/Worker/Delivery.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index cc06f17923..e901e45f24 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -251,6 +251,12 @@ class Delivery extends BaseObject */ private static function deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup) { + // Skip transmitting the announce via DFRN when it had already been done via AP + if (ActivityPub\Transmitter::isAnnounce($target_item) && !empty(Model\APContact::getByURL($contact['url'], false))) { + Logger::info('Announce had already been transmitted', ['url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id']]); + return; + } + // Transmit Diaspora reshares via Diaspora if the Friendica contact support Diaspora if (Diaspora::isReshare($target_item['body']) && !empty(Diaspora::personByHandle(contact['addr'], false))) { Logger::info('Reshare will be transmitted via Diaspora', ['url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id']]); @@ -258,12 +264,6 @@ class Delivery extends BaseObject return; } - // Skip transmitting the announce via DFRN when it had already been done via AP - if (ActivityPub\Transmitter::isAnnounce($target_item) && !empty(Model\APContact::getByURL($contact['url'], false))) { - Logger::info('Announce had already been transmitted', ['url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id']]); - return; - } - Logger::info('Deliver ' . (($target_item['guid'] ?? '') ?: $target_item['id']) . ' via DFRN to ' . (($contact['addr'] ?? '') ?: $contact['url'])); if ($cmd == self::MAIL) { From fb64010d7a3ed7dcb6366fa7131b3ac315f60450 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 8 Dec 2019 21:40:06 +0000 Subject: [PATCH 4/5] Missing "use" --- src/Worker/Delivery.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index e901e45f24..0d01d82848 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -16,6 +16,7 @@ use Friendica\Protocol\DFRN; use Friendica\Protocol\Diaspora; use Friendica\Protocol\Email; use Friendica\Protocol\Activity; +use Friendica\Protocol\ActivityPub; use Friendica\Util\Strings; use Friendica\Util\Network; use Friendica\Core\Worker; @@ -254,6 +255,7 @@ class Delivery extends BaseObject // Skip transmitting the announce via DFRN when it had already been done via AP if (ActivityPub\Transmitter::isAnnounce($target_item) && !empty(Model\APContact::getByURL($contact['url'], false))) { Logger::info('Announce had already been transmitted', ['url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id']]); + Model\ItemDeliveryData::incrementQueueDone($target_item['id']); return; } From b8f81d5e7d92213559de023cae378bc0a55e7361 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 8 Dec 2019 22:04:32 +0000 Subject: [PATCH 5/5] Relocate check for announce --- src/Worker/Delivery.php | 8 -------- src/Worker/Notifier.php | 5 +++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 0d01d82848..da0c8f2adb 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -16,7 +16,6 @@ use Friendica\Protocol\DFRN; use Friendica\Protocol\Diaspora; use Friendica\Protocol\Email; use Friendica\Protocol\Activity; -use Friendica\Protocol\ActivityPub; use Friendica\Util\Strings; use Friendica\Util\Network; use Friendica\Core\Worker; @@ -252,13 +251,6 @@ class Delivery extends BaseObject */ private static function deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup) { - // Skip transmitting the announce via DFRN when it had already been done via AP - if (ActivityPub\Transmitter::isAnnounce($target_item) && !empty(Model\APContact::getByURL($contact['url'], false))) { - Logger::info('Announce had already been transmitted', ['url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id']]); - Model\ItemDeliveryData::incrementQueueDone($target_item['id']); - return; - } - // Transmit Diaspora reshares via Diaspora if the Friendica contact support Diaspora if (Diaspora::isReshare($target_item['body']) && !empty(Diaspora::personByHandle(contact['addr'], false))) { Logger::info('Reshare will be transmitted via Diaspora', ['url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id']]); diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 3e4efb5f3c..19bd518856 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -625,6 +625,11 @@ class Notifier return false; } + // We deliver reshares via AP whenever possible + if (ActivityPub\Transmitter::isAnnounce($item)) { + return true; + } + // Skip DFRN when the item will be (forcefully) delivered via AP if (Config::get('debug', 'total_ap_delivery') && ($contact['network'] == Protocol::DFRN) && !empty(APContact::getByURL($contact['url'], false))) { return true;