]> git.mxchange.org Git - friendica.git/commitdiff
Contacts with protocol = AP are now delivered only via AP
authorMichael <heluecht@pirati.ca>
Sat, 11 May 2019 05:58:22 +0000 (05:58 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 11 May 2019 05:58:22 +0000 (05:58 +0000)
src/Protocol/ActivityPub/Transmitter.php
src/Protocol/Diaspora.php
src/Worker/Notifier.php

index a06fbdcf19b532a0cad73877deddc8e05fd4672f..0d024d26fc097fac9c2700a10c759e4a3704cc8f 100644 (file)
@@ -395,16 +395,24 @@ class Transmitter
                        foreach ($terms as $term) {
                                $cid = Contact::getIdForURL($term['url'], $item['uid']);
                                if (!empty($cid) && in_array($cid, $receiver_list)) {
-                                       $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => $networks]);
-                                       if (DBA::isResult($contact) && !empty($profile = APContact::getByURL($contact['url'], false))) {
+                                       $contact = DBA::selectFirst('contact', ['url', 'network', 'protocol'], ['id' => $cid]);
+                                       if (!DBA::isResult($contact) || (!in_array($contact['network'], $networks) && ($contact['protocol'] != Protocol::ACTIVITYPUB))) {
+                                               continue;
+                                       }
+
+                                       if (!empty($profile = APContact::getByURL($contact['url'], false))) {
                                                $data['to'][] = $profile['url'];
                                        }
                                }
                        }
 
                        foreach ($receiver_list as $receiver) {
-                               $contact = DBA::selectFirst('contact', ['url', 'hidden'], ['id' => $receiver, 'network' => $networks]);
-                               if (DBA::isResult($contact) && !empty($profile = APContact::getByURL($contact['url'], false))) {
+                               $contact = DBA::selectFirst('contact', ['url', 'hidden', 'network', 'protocol'], ['id' => $receiver]);
+                               if (!DBA::isResult($contact) || (!in_array($contact['network'], $networks) && ($contact['protocol'] != Protocol::ACTIVITYPUB))) {
+                                       continue;
+                               }
+
+                               if (!empty($profile = APContact::getByURL($contact['url'], false))) {
                                        if ($contact['hidden'] || $always_bcc) {
                                                $data['bcc'][] = $profile['url'];
                                        } else {
@@ -530,14 +538,18 @@ class Transmitter
                        $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
                }
 
-               $condition = ['uid' => $uid, 'network' => $networks, 'archive' => false, 'pending' => false];
+               $condition = ['uid' => $uid, 'archive' => false, 'pending' => false];
 
                if (!empty($uid)) {
                        $condition['rel'] = [Contact::FOLLOWER, Contact::FRIEND];
                }
 
-               $contacts = DBA::select('contact', ['url'], $condition);
+               $contacts = DBA::select('contact', ['url', 'network', 'protocol'], $condition);
                while ($contact = DBA::fetch($contacts)) {
+                       if (!in_array($contact['network'], $networks) && ($contact['protocol'] != Protocol::ACTIVITYPUB)) {
+                               continue;
+                       }
+
                        if (Network::isUrlBlocked($contact['url'])) {
                                continue;
                        }
index e7857cf8e1536503b9baabb938d11d83ffa2d3c0..41ed7e7d9f79b9db0f3d29ae37d24066b27012b8 100644 (file)
@@ -212,7 +212,7 @@ class Diaspora
         */
        public static function participantsForThread($thread, array $contacts)
        {
-               $r = DBA::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`name`, `contact`.`network`,
+               $r = DBA::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`name`, `contact`.`network`, `contact`.`protocol`,
                                `fcontact`.`batch` AS `fbatch`, `fcontact`.`network` AS `fnetwork` FROM `participation`
                                INNER JOIN `contact` ON `contact`.`id` = `participation`.`cid`
                                INNER JOIN `fcontact` ON `fcontact`.`id` = `participation`.`fid`
@@ -224,6 +224,10 @@ class Diaspora
                        }
                        unset($contact['fnetwork']);
 
+                       if (empty($contact['protocol'])) {
+                               $contact['protocol'] = $contact['network'];
+                       }
+
                        if (empty($contact['batch']) && !empty($contact['fbatch'])) {
                                $contact['batch'] = $contact['fbatch'];
                        }
index dac3346f95a6adef8d93f10f51185adddf0bf97c..1ce4ff244e4075f45a2f4c31d9a12a94db226f06 100644 (file)
@@ -89,7 +89,7 @@ class Notifier
                        $uid = $target_id;
 
                        $condition = ['uid' => $target_id, 'self' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
-                       $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'network', 'batch'], $condition);
+                       $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'network', 'protocol', 'batch'], $condition);
                } else {
                        // find ancestors
                        $condition = ['id' => $target_id, 'visible' => true, 'moderated' => false];
@@ -374,7 +374,7 @@ class Notifier
                        if (!empty($networks)) {
                                $condition['network'] = $networks;
                        }
-                       $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'network', 'batch'], $condition);
+                       $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'network', 'protocol', 'batch'], $condition);
                }
 
                $conversants = [];
@@ -388,10 +388,11 @@ class Notifier
 
                                $relay_list_stmt = DBA::p(
                                        "SELECT
-                                               `batch`,
-                                               ANY_VALUE(`id`) AS `id`,
-                                               ANY_VALUE(`name`) AS `name`,
-                                               ANY_VALUE(`network`) AS `network`
+                                               `batch`,
+                                               ANY_VALUE(`id`) AS `id`,
+                                               ANY_VALUE(`name`) AS `name`,
+                                               ANY_VALUE(`network`) AS `network`,
+                                               ANY_VALUE(`protocol`) AS `protocol`
                                        FROM `contact`
                                        WHERE `network` = ?
                                        AND `batch` != ''
@@ -421,7 +422,7 @@ 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', 'url', 'name', 'network'], $condition));
+                       $r2 = DBA::toArray(DBA::select('contact', ['id', 'url', 'name', 'network', 'protocol'], $condition));
 
                        $r = array_merge($r2, $relay_list);
 
@@ -432,6 +433,12 @@ class Notifier
                                                continue;
                                        }
 
+                                       if (($rr['network'] == Protocol::DFRN) && ($rr['protocol'] == Protocol::ACTIVITYPUB) &&
+                                               !in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION])) {
+                                               Logger::info('Contact is Friendica AP, so skipping delivery via legacy DFRN', ['url' => $rr['url']]);
+                                               continue;
+                                       }
+
                                        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;
@@ -466,6 +473,12 @@ class Notifier
                                continue;
                        }
 
+                       if (($contact['network'] == Protocol::DFRN) && ($contact['protocol'] == Protocol::ACTIVITYPUB) &&
+                               !in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION])) {
+                               Logger::info('Contact is Friendica AP, so skipping delivery via legacy DFRN', ['url' => $contact['url']]);
+                               continue;
+                       }
+
                        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;