Merge pull request #5867 from annando/ap-fix-follow

AP: Switchting existing contacts to AP when receiving activities
This commit is contained in:
Hypolite Petovan 2018-10-09 16:08:38 -04:00 committed by GitHub
commit 5f9dd11cfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -297,6 +297,7 @@ class Processor
$cid = Contact::getIdForURL($activity['actor'], $uid); $cid = Contact::getIdForURL($activity['actor'], $uid);
if (!empty($cid)) { if (!empty($cid)) {
self::switchContact($cid);
$contact = DBA::selectFirst('contact', [], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]); $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]);
} else { } else {
$contact = false; $contact = false;
@ -311,11 +312,6 @@ class Processor
return; 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]); DBA::update('contact', ['hub-verify' => $activity['id']], ['id' => $cid]);
logger('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']); logger('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']);
} }
@ -381,6 +377,8 @@ class Processor
return; return;
} }
self::switchContact($cid);
$fields = ['pending' => false]; $fields = ['pending' => false];
$contact = DBA::selectFirst('contact', ['rel'], ['id' => $cid]); $contact = DBA::selectFirst('contact', ['rel'], ['id' => $cid]);
@ -413,6 +411,8 @@ class Processor
return; return;
} }
self::switchContact($cid);
if (DBA::exists('contact', ['id' => $cid, 'rel' => Contact::SHARING, 'pending' => true])) { if (DBA::exists('contact', ['id' => $cid, 'rel' => Contact::SHARING, 'pending' => true])) {
Contact::remove($cid); Contact::remove($cid);
logger('Rejected contact request from contact ' . $cid . ' for user ' . $uid . ' - contact had been removed.', LOGGER_DEBUG); logger('Rejected contact request from contact ' . $cid . ' for user ' . $uid . ' - contact had been removed.', LOGGER_DEBUG);
@ -464,6 +464,8 @@ class Processor
return; return;
} }
self::switchContact($cid);
$contact = DBA::selectFirst('contact', [], ['id' => $cid]); $contact = DBA::selectFirst('contact', [], ['id' => $cid]);
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
return; return;
@ -472,4 +474,20 @@ class Processor
Contact::removeFollower($owner, $contact); Contact::removeFollower($owner, $contact);
logger('Undo following request from contact ' . $cid . ' for user ' . $uid, LOGGER_DEBUG); 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);
}
} }