From 55557a8f180b2e87616b80f6657d5a07d9c9681b Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 11 May 2019 05:58:22 +0000 Subject: [PATCH] Contacts with protocol = AP are now delivered only via AP --- src/Protocol/ActivityPub/Transmitter.php | 24 +++++++++++++++------ src/Protocol/Diaspora.php | 6 +++++- src/Worker/Notifier.php | 27 ++++++++++++++++++------ 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index a06fbdcf19..0d024d26fc 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -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; } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index e7857cf8e1..41ed7e7d9f 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -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']; } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index dac3346f95..1ce4ff244e 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -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; -- 2.39.5