]> git.mxchange.org Git - friendica.git/commitdiff
AP: Debug option to deliver via AP first
authorMichael <heluecht@pirati.ca>
Wed, 30 Jan 2019 19:33:08 +0000 (19:33 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 30 Jan 2019 19:33:08 +0000 (19:33 +0000)
config/defaults.config.php
src/Protocol/ActivityPub/Transmitter.php
src/Worker/Notifier.php

index f16bd664cf99a37d0b42bf31cdbd7e2f670bf81a..42533f5ad20f7db728976e1b7d2e38c4f0142ac8 100644 (file)
@@ -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,
+       ]
 ];
index fa8bdc0439d997ec5009e95b76fa20f6691c311a..b2f0291adf054bd1b9063808532909aad3e619e6 100644 (file)
@@ -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];
 
index 4d63d436fecb92ea6de610312f61caf1c14e1178..681fd13c8f57317d76716a002a0f7bca13584a82 100644 (file)
@@ -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);