Merge pull request #7368 from annando/fix-switch

Use standard function to update the contact to avoid SQL errors
This commit is contained in:
Philipp 2019-07-12 07:24:36 +02:00 committed by GitHub
commit 108f15a94e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -657,27 +657,14 @@ class Receiver
*/ */
public static function switchContact($cid, $uid, $url) public static function switchContact($cid, $uid, $url)
{ {
$profile = ActivityPub::probeProfile($url); Contact::updateFromProbe($cid, '', true);
if (empty($profile)) {
return;
}
Logger::log('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' to ActivityPub'); Logger::log('Switch contact ' . $cid . ' (' . $url . ') for user ' . $uid . ' to ActivityPub');
$photo = defaults($profile, 'photo', null);
unset($profile['photo']);
unset($profile['baseurl']);
unset($profile['guid']);
$profile['nurl'] = Strings::normaliseLink($profile['url']);
DBA::update('contact', $profile, ['id' => $cid]);
Contact::updateAvatar($photo, $uid, $cid);
// Send a new follow request to be sure that the connection still exists // Send a new follow request to be sure that the connection still exists
if (($uid != 0) && DBA::exists('contact', ['id' => $cid, 'rel' => [Contact::SHARING, Contact::FRIEND]])) { if (($uid != 0) && DBA::exists('contact', ['id' => $cid, 'rel' => [Contact::SHARING, Contact::FRIEND]])) {
ActivityPub\Transmitter::sendActivity('Follow', $profile['url'], $uid); ActivityPub\Transmitter::sendActivity('Follow', $url, $uid);
Logger::log('Send a new follow request to ' . $profile['url'] . ' for user ' . $uid, Logger::DEBUG); Logger::log('Send a new follow request to ' . $url . ' for user ' . $uid, Logger::DEBUG);
} }
} }