From e27915a819397f391b5c50b5bf15e2475eb084bf Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 22 May 2020 10:10:24 +0000 Subject: [PATCH] Centralized gsid generation --- src/Model/Contact.php | 12 ------------ src/Network/Probe.php | 11 +++++++++-- src/Protocol/ActivityPub.php | 1 + 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index f611cc452f..ee49d9b75c 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1530,10 +1530,6 @@ class Contact if (empty($data)) { $data = Probe::uri($url, "", $uid); - // Ensure that there is a gserver entry - if (!empty($data['baseurl']) && ($data['network'] != Protocol::PHANTOM)) { - $data['gsid'] = GServer::getID($data['baseurl']); - } } // Take the default values when probing failed @@ -2136,10 +2132,6 @@ class Contact } } - if (!empty($ret['baseurl']) && empty($contact['gsid'])) { - $ret['gsid'] = GServer::getID($ret['baseurl']); - } - $new_pubkey = $ret['pubkey']; $update = false; @@ -2308,10 +2300,6 @@ class Contact $ret = Probe::uri($url, $network, $uid, false); } - if (!empty($ret['baseurl'])) { - $ret['gsid'] = GServer::getID($ret['baseurl']); - } - if (($network != '') && ($ret['network'] != $network)) { Logger::log('Expected network ' . $network . ' does not match actual network ' . $ret['network']); return $result; diff --git a/src/Network/Probe.php b/src/Network/Probe.php index edcb9f4c34..5872ae587b 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -30,6 +30,7 @@ use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; +use Friendica\Model\GServer; use Friendica\Model\Profile; use Friendica\Protocol\ActivityNamespace; use Friendica\Protocol\ActivityPub; @@ -86,14 +87,16 @@ class Probe "community", "keywords", "location", "about", "hide", "batch", "notify", "poll", "request", "confirm", "poco", "following", "followers", "inbox", "outbox", "sharedinbox", - "priority", "network", "pubkey", "baseurl"]; + "priority", "network", "pubkey", "baseurl", "gsid"]; $newdata = []; foreach ($fields as $field) { if (isset($data[$field])) { $newdata[$field] = $data[$field]; - } else { + } elseif ($field != "gsid") { $newdata[$field] = ""; + } else { + $newdata[$field] = null; } } @@ -461,6 +464,10 @@ class Probe $data['baseurl'] = self::$baseurl; } + if (!empty($data['baseurl']) && empty($data['gsid'])) { + $data['gsid'] = GServer::getID($data['baseurl']); + } + if (empty($data['network'])) { $data['network'] = Protocol::PHANTOM; } diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index c3168f5509..9d6223a748 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -171,6 +171,7 @@ class ActivityPub $profile['poll'] = $apcontact['outbox']; $profile['pubkey'] = $apcontact['pubkey']; $profile['baseurl'] = $apcontact['baseurl']; + $profile['gsid'] = $apcontact['gsid']; // Remove all "null" fields foreach ($profile as $field => $content) {