From 87cc17337b36bd560c4aada76073ae3dc1e0b986 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 4 Jul 2021 12:35:48 +0000 Subject: [PATCH 1/2] Fix local follow (and local contact data update) --- src/Model/Contact.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index d8d73a983..784f9bb9f 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -2051,7 +2051,11 @@ class Contact } if (self::isLocal($ret['url'])) { - Logger::info('Local contacts are not updated here.'); + if ($contact['uid'] == 0) { + Logger::info('Local contacts are not updated here.'); + } else { + self::updateFromPublicContact($id, $contact); + } return true; } @@ -2186,6 +2190,26 @@ class Contact return true; } + private static function updateFromPublicContact(int $id, array $contact) + { + $public = self::getByURL($contact['url'], false); + + $fields = []; + + foreach ($contact as $field => $value) { + if ($field == 'uid') { + continue; + } + if ($public[$field] != $value) { + $fields[$field] = $public[$field]; + } + } + if (!empty($fields)) { + DBA::update('contact', $fields, ['id' => $id]); + Logger::info('Updating local contact', ['id' => $id]); + } + } + /** * @param integer $url contact url * @return integer Contact id @@ -2294,8 +2318,10 @@ class Contact } if (!empty($arr['contact']['name'])) { + $probed = false; $ret = $arr['contact']; } else { + $probed = true; $ret = Probe::uri($url, $network, $user['uid']); } @@ -2439,6 +2465,10 @@ class Contact // pull feed and consume it, which should subscribe to the hub. if ($contact['network'] == Protocol::OSTATUS) { Worker::add(PRIORITY_HIGH, 'OnePoll', $contact_id, 'force'); + } + + if ($probed) { + self::updateFromProbeArray($contact_id, $ret); } else { Worker::add(PRIORITY_HIGH, 'UpdateContact', $contact_id); } From 74a0bfc6da602b8bd94dfa8979819e9d74354bf0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 4 Jul 2021 12:38:35 +0000 Subject: [PATCH 2/2] Ensure to not update the "self" contact --- src/Model/Contact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 784f9bb9f..a45145d9c 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -2205,7 +2205,7 @@ class Contact } } if (!empty($fields)) { - DBA::update('contact', $fields, ['id' => $id]); + DBA::update('contact', $fields, ['id' => $id, 'self' => false]); Logger::info('Updating local contact', ['id' => $id]); } }