[twitter] Fix contact image handling in twitter_fetch_contact

This commit is contained in:
Hypolite Petovan 2020-06-07 16:49:47 -04:00
parent 2081ee6040
commit 6ce762010e

View File

@ -1077,7 +1077,6 @@ function twitter_user_to_contact($data)
return -1;
}
$avatar = twitter_fix_avatar($data->profile_image_url_https);
$baseurl = 'https://twitter.com';
$url = $baseurl . '/' . $data->screen_name;
$addr = $data->screen_name . '@twitter.com';
@ -1092,7 +1091,7 @@ function twitter_user_to_contact($data)
'addr' => $addr,
'location' => $data->location,
'about' => $data->description,
'photo' => $avatar,
'photo' => twitter_fix_avatar($data->profile_image_url_https),
];
return $fields;
@ -1106,6 +1105,10 @@ function twitter_fetch_contact($uid, $data, $create_user)
return -1;
}
// photo comes from twitter_user_to_contact but shouldn't be saved directly in the contact row
$avatar = $fields['photo'];
unset($fields['photo']);
// Update the public contact
$pcontact = DBA::selectFirst('contact', ['id'], ['uid' => 0, 'alias' => "twitter::" . $data->id_str]);
if (DBA::isResult($pcontact)) {
@ -1116,7 +1119,7 @@ function twitter_fetch_contact($uid, $data, $create_user)
if (!empty($cid)) {
DBA::update('contact', $fields, ['id' => $cid]);
Contact::updateAvatar($fields['photo'], 0, $cid);
Contact::updateAvatar($avatar, 0, $cid);
}
$contact = DBA::selectFirst('contact', [], ['uid' => $uid, 'alias' => "twitter::" . $data->id_str]);
@ -1148,7 +1151,7 @@ function twitter_fetch_contact($uid, $data, $create_user)
Group::addMember(User::getDefaultGroup($uid), $contact_id);
Contact::updateAvatar($fields['photo'], $uid, $contact_id);
Contact::updateAvatar($avatar, $uid, $contact_id);
} else {
if ($contact["readonly"] || $contact["blocked"]) {
Logger::log("twitter_fetch_contact: Contact '" . $contact["nick"] . "' is blocked or readonly.", Logger::DEBUG);
@ -1164,7 +1167,7 @@ function twitter_fetch_contact($uid, $data, $create_user)
$update = true;
}
Contact::updateAvatar($fields['photo'], $uid, $contact['id']);
Contact::updateAvatar($avatar, $uid, $contact['id']);
if ($contact['name'] != $data->name) {
$fields['name-date'] = $fields['uri-date'] = DateTimeFormat::utcNow();