Merge pull request #12375 from annando/issue-12373

Issue 12373: Fix communication to Diaspora
This commit is contained in:
Hypolite Petovan 2022-12-10 08:45:53 -05:00 committed by GitHub
commit 5fd5819321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 5 deletions

View File

@ -1396,6 +1396,8 @@ class Contact
if ($data['network'] == Protocol::DIASPORA) { if ($data['network'] == Protocol::DIASPORA) {
DI::dsprContact()->updateFromProbeArray($data); DI::dsprContact()->updateFromProbeArray($data);
} elseif (!empty($data['networks'][Protocol::DIASPORA])) {
DI::dsprContact()->updateFromProbeArray($data['networks'][Protocol::DIASPORA]);
} }
self::updateFromProbeArray($contact_id, $data); self::updateFromProbeArray($contact_id, $data);
@ -2487,6 +2489,8 @@ class Contact
if ($ret['network'] == Protocol::DIASPORA) { if ($ret['network'] == Protocol::DIASPORA) {
DI::dsprContact()->updateFromProbeArray($ret); DI::dsprContact()->updateFromProbeArray($ret);
} elseif (!empty($ret['networks'][Protocol::DIASPORA])) {
DI::dsprContact()->updateFromProbeArray($ret['networks'][Protocol::DIASPORA]);
} }
return self::updateFromProbeArray($id, $ret); return self::updateFromProbeArray($id, $ret);

View File

@ -134,6 +134,17 @@ class Probe
} }
} }
$newdata['networks'] = [];
foreach ([Protocol::DIASPORA, Protocol::OSTATUS] as $network) {
if (!empty($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']);
}
}
// We don't use the "priority" field anymore and replace it with a dummy. // We don't use the "priority" field anymore and replace it with a dummy.
$newdata['priority'] = 0; $newdata['priority'] = 0;
@ -345,7 +356,11 @@ class Probe
$data = []; $data = [];
} }
if (empty($data) || (!empty($ap_profile) && empty($network) && (($data['network'] ?? '') != Protocol::DFRN))) { 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 = $ap_profile;
$data['networks'] = $networks;
} elseif (!empty($ap_profile)) { } elseif (!empty($ap_profile)) {
$ap_profile['batch'] = ''; $ap_profile['batch'] = '';
$data = array_merge($ap_profile, $data); $data = array_merge($ap_profile, $data);
@ -716,9 +731,13 @@ class Probe
} }
if ((!$result && ($network == '')) || ($network == Protocol::DIASPORA)) { if ((!$result && ($network == '')) || ($network == Protocol::DIASPORA)) {
$result = self::diaspora($webfinger); $result = self::diaspora($webfinger);
} else {
$result['networks'][Protocol::DIASPORA] = self::diaspora($webfinger);
} }
if ((!$result && ($network == '')) || ($network == Protocol::OSTATUS)) { if ((!$result && ($network == '')) || ($network == Protocol::OSTATUS)) {
$result = self::ostatus($webfinger); $result = self::ostatus($webfinger);
} else {
$result['networks'][Protocol::OSTATUS] = self::ostatus($webfinger);
} }
if (in_array($network, ['', Protocol::ZOT])) { if (in_array($network, ['', Protocol::ZOT])) {
$result = self::zot($webfinger, $result, $baseurl); $result = self::zot($webfinger, $result, $baseurl);

View File

@ -826,9 +826,15 @@ class Diaspora
*/ */
public static function isSupportedByContactUrl(string $url, ?bool $update = null): bool 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;
} }
/** /**
@ -4064,7 +4070,7 @@ class Diaspora
return false; 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]); Logger::info('Parent author is no Diaspora contact.', ['parent-id' => $parent_id]);
return false; return false;
} }

View File

@ -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) 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 // 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']]); 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); self::deliverDiaspora($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup);
return; return;

View File

@ -191,7 +191,7 @@ class Notifier
// when the original comment author does support the Diaspora protocol. // when the original comment author does support the Diaspora protocol.
if ($thr_parent['author-link'] && $target_item['parent-uri'] != $target_item['thr-parent']) { if ($thr_parent['author-link'] && $target_item['parent-uri'] != $target_item['thr-parent']) {
$diaspora_delivery = Diaspora::isSupportedByContactUrl($thr_parent['author-link']); $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']]); 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; $diaspora_delivery = false;
} }