From fc0acd7b1f4723b9e45badcaae53e466e1a29b85 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 30 Jan 2019 19:33:08 +0000 Subject: [PATCH] AP: Debug option to deliver via AP first --- config/defaults.config.php | 14 +++++++++----- src/Protocol/ActivityPub/Transmitter.php | 24 ++++++++++++++---------- src/Worker/Notifier.php | 13 ++++++++++++- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/config/defaults.config.php b/config/defaults.config.php index f16bd664cf..42533f5ad2 100644 --- a/config/defaults.config.php +++ b/config/defaults.config.php @@ -421,9 +421,13 @@ return [ // Must be writable by the ejabberd process. if set then it will prevent the running of multiple processes. 'lockpath' => '', ], - 'debug' => [ - // ap_inbox_log (Boolean) - // Logs every call to /inbox as a JSON file in Friendica's temporary directory - 'ap_inbox_log' => false, - ] + 'debug' => [ + // ap_inbox_log (Boolean) + // Logs every call to /inbox as a JSON file in Friendica's temporary directory + 'ap_inbox_log' => false, + + // total_ap_delivery (Boolean) + // Deliver via AP to every possible receiver and we suppress the delivery to these contacts with other protocols + 'total_ap_delivery' => false, + ] ]; diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index fa8bdc0439..b2f0291adf 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -325,11 +325,13 @@ class Transmitter } } - // Will be activated in a later step - // $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; - - // For now only send to these contacts: - $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS]; + if (Config::get('debug', 'total_ap_delivery')) { + // Will be activated in a later step + $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; + } else { + // For now only send to these contacts: + $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS]; + } $data = ['to' => [], 'cc' => [], 'bcc' => []]; @@ -473,11 +475,13 @@ class Transmitter { $inboxes = []; - // Will be activated in a later step - // $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; - - // For now only send to these contacts: - $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS]; + if (Config::get('debug', 'total_ap_delivery')) { + // Will be activated in a later step + $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; + } else { + // For now only send to these contacts: + $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS]; + } $condition = ['uid' => $uid, 'network' => $networks, 'archive' => false, 'pending' => false]; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 4d63d436fe..681fd13c8f 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -11,6 +11,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\Model\APContact; use Friendica\Model\Contact; use Friendica\Model\Conversation; use Friendica\Model\Group; @@ -418,12 +419,17 @@ class Notifier $condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false, 'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; - $r2 = DBA::toArray(DBA::select('contact', ['id', 'name', 'network'], $condition)); + $r2 = DBA::toArray(DBA::select('contact', ['id', 'url', 'name', 'network'], $condition)); $r = array_merge($r2, $relay_list); if (DBA::isResult($r)) { foreach ($r as $rr) { + if (Config::get('debug', 'total_ap_delivery') && !empty($rr['url']) && ($rr['network'] == Protocol::DFRN) && !empty(APContact::getByURL($rr['url'], false))) { + Logger::log('Skipping contact ' . $rr['url'] . ' since it will be delivered via AP', Logger::DEBUG); + continue; + } + $conversants[] = $rr['id']; $delivery_queue_count++; @@ -447,6 +453,11 @@ class Notifier // delivery loop while ($contact = DBA::fetch($delivery_contacts_stmt)) { + if (Config::get('debug', 'total_ap_delivery') && ($contact['network'] == Protocol::DFRN) && !empty(APContact::getByURL($contact['url'], false))) { + Logger::log('Skipping contact ' . $contact['url'] . ' since it will be delivered via AP', Logger::DEBUG); + continue; + } + // Don't deliver to Diaspora if it already had been done as batch delivery if (($contact['network'] == Protocol::DIASPORA) && $batch_delivery) { Logger::log('Already delivered id ' . $target_id . ' via batch to ' . json_encode($contact), Logger::DEBUG);