From c0f26ace2ecb5dffcc232ed9015eb7ef20ccf63a Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 9 Oct 2018 19:58:15 +0000 Subject: [PATCH] AP: Switchting existing contacts to AP when receiving activities --- src/Protocol/ActivityPub/Processor.php | 28 +++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index a85123817a..36b283e8d5 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -294,6 +294,7 @@ class Processor $cid = Contact::getIdForURL($activity['actor'], $uid); if (!empty($cid)) { + self::switchContact($cid); $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]); } else { $contact = false; @@ -308,11 +309,6 @@ class Processor return; } - $contact = DBA::selectFirst('contact', ['network'], ['id' => $cid]); - if ($contact['network'] != Protocol::ACTIVITYPUB) { - Contact::updateFromProbe($cid, Protocol::ACTIVITYPUB); - } - DBA::update('contact', ['hub-verify' => $activity['id']], ['id' => $cid]); logger('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']); } @@ -378,6 +374,8 @@ class Processor return; } + self::switchContact($cid); + $fields = ['pending' => false]; $contact = DBA::selectFirst('contact', ['rel'], ['id' => $cid]); @@ -410,6 +408,8 @@ class Processor return; } + self::switchContact($cid); + if (DBA::exists('contact', ['id' => $cid, 'rel' => Contact::SHARING, 'pending' => true])) { Contact::remove($cid); logger('Rejected contact request from contact ' . $cid . ' for user ' . $uid . ' - contact had been removed.', LOGGER_DEBUG); @@ -461,6 +461,8 @@ class Processor return; } + self::switchContact($cid); + $contact = DBA::selectFirst('contact', [], ['id' => $cid]); if (!DBA::isResult($contact)) { return; @@ -469,4 +471,20 @@ class Processor Contact::removeFollower($owner, $contact); logger('Undo following request from contact ' . $cid . ' for user ' . $uid, LOGGER_DEBUG); } + + /** + * Switches a contact to AP if needed + * + * @param integer $cid Contact ID + */ + private static function switchContact($cid) + { + $contact = DBA::selectFirst('contact', ['network'], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]); + if (!DBA::isResult($contact) || ($contact['network'] == Protocol::ACTIVITYPUB)) { + return; + } + + logger('Change existing contact ' . $cid . ' from ' . $contact['network'] . ' to ActivityPub.'); + Contact::updateFromProbe($cid, Protocol::ACTIVITYPUB); + } }