From 019bb56668e6c41254b851e2274be0f5c6cf79ea Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 10 Dec 2022 12:08:55 +0000 Subject: [PATCH 1/3] Issue 12373: Fix communication to Diaspora --- src/Model/Contact.php | 4 ++++ src/Network/Probe.php | 15 +++++++++++++++ src/Protocol/Diaspora.php | 13 ++++++++++--- src/Worker/Delivery.php | 2 +- src/Worker/Notifier.php | 2 +- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index e80f0752e..873de0890 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1396,6 +1396,8 @@ class Contact if ($data['network'] == Protocol::DIASPORA) { DI::dsprContact()->updateFromProbeArray($data); + } elseif (!empty($data['networks'][Protocol::DIASPORA])) { + DI::dsprContact()->updateFromProbeArray($data['networks'][Protocol::DIASPORA]); } self::updateFromProbeArray($contact_id, $data); @@ -2487,6 +2489,8 @@ class Contact if ($ret['network'] == Protocol::DIASPORA) { DI::dsprContact()->updateFromProbeArray($ret); + } elseif (!empty($ret['networks'][Protocol::DIASPORA])) { + DI::dsprContact()->updateFromProbeArray($ret['networks'][Protocol::DIASPORA]); } return self::updateFromProbeArray($id, $ret); diff --git a/src/Network/Probe.php b/src/Network/Probe.php index d79cd4055..9cdcd5fa8 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -134,6 +134,13 @@ class Probe } } + $newdata['networks'] = $data['networks'] ?? []; + foreach ([Protocol::DIASPORA, Protocol::OSTATUS] as $network) { + if (empty($newdata['networks'][$network])) { + unset($newdata['networks'][$network]); + } + } + // We don't use the "priority" field anymore and replace it with a dummy. $newdata['priority'] = 0; @@ -345,7 +352,11 @@ class Probe $data = []; } if (empty($data) || (!empty($ap_profile) && empty($network) && (($data['network'] ?? '') != Protocol::DFRN))) { + $networks = $data['networks'] ?? []; + unset($data['networks']); + $networks[$data['network']] = $data; $data = $ap_profile; + $data['networks'] = $networks; } elseif (!empty($ap_profile)) { $ap_profile['batch'] = ''; $data = array_merge($ap_profile, $data); @@ -716,9 +727,13 @@ class Probe } if ((!$result && ($network == '')) || ($network == Protocol::DIASPORA)) { $result = self::diaspora($webfinger); + } else { + $result['networks'][Protocol::DIASPORA] = self::diaspora($webfinger); } if ((!$result && ($network == '')) || ($network == Protocol::OSTATUS)) { $result = self::ostatus($webfinger); + } else { + $result['networks'][Protocol::OSTATUS] = self::ostatus($webfinger); } if (in_array($network, ['', Protocol::ZOT])) { $result = self::zot($webfinger, $result, $baseurl); diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 3c60f4041..e5194ba3d 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -826,9 +826,15 @@ class Diaspora */ public static function isSupportedByContactUrl(string $url, ?bool $update = null): bool { - $contact = Contact::getByURL($url, $update); + $contact = Contact::getByURL($url, $update, ['uri-id', 'network']); - return DI::dsprContact()->existsByUriId($contact['uri-id'] ?? 0); + $supported = DI::dsprContact()->existsByUriId($contact['uri-id'] ?? 0); + + if (!$supported && is_null($update) && ($contact['network'] == Protocol::DFRN)) { + $supported = self::isSupportedByContactUrl($url, true); + } + + return $supported; } /** @@ -4035,6 +4041,7 @@ class Diaspora if (!self::parentSupportDiaspora($item['thr-parent-id'])) { Logger::info('One of the parents does not support Diaspora. A signature will not be created.', ['uri-id' => $item['uri-id'], 'guid' => $item['guid']]); + echo "5"; return false; } @@ -4064,7 +4071,7 @@ class Diaspora return false; } - if (!self::isSupportedByContactUrl($parent_post['author-link'], false)) { + if (!self::isSupportedByContactUrl($parent_post['author-link'])) { Logger::info('Parent author is no Diaspora contact.', ['parent-id' => $parent_id]); return false; } diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index cec894480..1a0758987 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -277,7 +277,7 @@ class Delivery private static function deliverDFRN(string $cmd, array $contact, array $owner, array $items, array $target_item, bool $public_message, bool $top_level, bool $followup, int $server_protocol = null) { // Transmit Diaspora reshares via Diaspora if the Friendica contact support Diaspora - if (Diaspora::getReshareDetails($target_item ?? []) && Diaspora::isSupportedByContactUrl($contact['addr'], false)) { + if (Diaspora::getReshareDetails($target_item ?? []) && Diaspora::isSupportedByContactUrl($contact['addr'])) { 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; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index db593b6a4..c09faca89 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -191,7 +191,7 @@ class Notifier // when the original comment author does support the Diaspora protocol. if ($thr_parent['author-link'] && $target_item['parent-uri'] != $target_item['thr-parent']) { $diaspora_delivery = Diaspora::isSupportedByContactUrl($thr_parent['author-link']); - if ($diaspora_delivery && empty($target_item['signed_text'])) { + if ($diaspora_delivery && empty($target_item['signed_text'])) { Logger::debug('Post has got no Diaspora signature, so there will be no Diaspora delivery', ['guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id']]); $diaspora_delivery = false; } From 6496ed4c1910c39394eec8066dc7a2f958a16a1b Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 10 Dec 2022 12:14:23 +0000 Subject: [PATCH 2/3] Remove testcode, improve rearrange --- src/Network/Probe.php | 6 +++--- src/Protocol/Diaspora.php | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 9cdcd5fa8..a97f6f811 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -134,10 +134,10 @@ class Probe } } - $newdata['networks'] = $data['networks'] ?? []; + $newdata['networks'] = []; foreach ([Protocol::DIASPORA, Protocol::OSTATUS] as $network) { - if (empty($newdata['networks'][$network])) { - unset($newdata['networks'][$network]); + if (!empty($data['networks'][$network])) { + $newdata['networks'][$network] = $data['networks'][$network]; } } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index e5194ba3d..fe5b27d33 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -4041,7 +4041,6 @@ class Diaspora if (!self::parentSupportDiaspora($item['thr-parent-id'])) { Logger::info('One of the parents does not support Diaspora. A signature will not be created.', ['uri-id' => $item['uri-id'], 'guid' => $item['guid']]); - echo "5"; return false; } From c6ca844f33cba1c4cf5bdfd2127f0fa751ea25b4 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 10 Dec 2022 12:35:05 +0000 Subject: [PATCH 3/3] "networks" has to contain all probing fields --- src/Network/Probe.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index a97f6f811..e74b43734 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -137,7 +137,11 @@ class Probe $newdata['networks'] = []; foreach ([Protocol::DIASPORA, Protocol::OSTATUS] as $network) { if (!empty($data['networks'][$network])) { - $newdata['networks'][$network] = $data['networks'][$network]; + $data['networks'][$network]['subscribe'] = $newdata['subscribe'] ?? ''; + $data['networks'][$network]['baseurl'] = $newdata['baseurl'] ?? ''; + $data['networks'][$network]['gsid'] = $newdata['gsid'] ?? 0; + $newdata['networks'][$network] = self::rearrangeData($data['networks'][$network]); + unset($newdata['networks'][$network]['networks']); } }