Merge pull request #1234 from annando/twitter-avatar

Twitter: Assign contacts via their twitter id - not via their url
This commit is contained in:
Hypolite Petovan 2022-02-02 18:07:37 -05:00 committed by GitHub
commit dd6bf79e19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 23 deletions

View File

@ -1346,6 +1346,8 @@ function twitter_user_to_contact($data)
$fields = [
'url' => $url,
'nurl' => Strings::normaliseLink($url),
'uri-id' => ItemURI::getIdByURI($url),
'network' => Protocol::TWITTER,
'alias' => 'twitter::' . $data->id_str,
'baseurl' => $baseurl,
@ -1361,6 +1363,16 @@ function twitter_user_to_contact($data)
return $fields;
}
function twitter_get_contact($data, int $uid = 0)
{
$contact = DBA::selectFirst('contact', ['id'], ['uid' => $uid, 'alias' => "twitter::" . $data->id_str]);
if (DBA::isResult($contact)) {
return $contact['id'];
} else {
return twitter_fetch_contact($uid, $data, false);
}
}
function twitter_fetch_contact($uid, $data, $create_user)
{
$fields = twitter_user_to_contact($data);
@ -1402,7 +1414,6 @@ function twitter_fetch_contact($uid, $data, $create_user)
// create contact record
$fields['uid'] = $uid;
$fields['created'] = DateTimeFormat::utcNow();
$fields['nurl'] = Strings::normaliseLink($fields['url']);
$fields['poll'] = 'twitter::' . $data->id_str;
$fields['rel'] = $relation;
$fields['priority'] = 1;
@ -1418,8 +1429,6 @@ function twitter_fetch_contact($uid, $data, $create_user)
$contact_id = DBA::lastInsertId();
Group::addMember(User::getDefaultGroup($uid), $contact_id);
Contact::updateAvatar($contact_id, $avatar);
} else {
if ($contact["readonly"] || $contact["blocked"]) {
Logger::notice('Contact is blocked or readonly.', ['nickname' => $contact["nick"]]);
@ -1435,8 +1444,6 @@ function twitter_fetch_contact($uid, $data, $create_user)
$update = true;
}
Contact::updateAvatar($contact['id'], $avatar);
if ($contact['name'] != $data->name) {
$fields['name-date'] = $fields['uri-date'] = DateTimeFormat::utcNow();
$update = true;
@ -1458,6 +1465,8 @@ function twitter_fetch_contact($uid, $data, $create_user)
}
}
Contact::updateAvatar($contact_id, $avatar);
return $contact_id;
}
@ -1787,8 +1796,9 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl
if ($contactid == 0) {
$contactid = twitter_fetch_contact($uid, $post->user, $create_user);
$postarray['owner-name'] = $post->user->name;
$postarray['owner-link'] = "https://twitter.com/" . $post->user->screen_name;
$postarray['owner-id'] = twitter_get_contact($post->user);
$postarray['owner-name'] = $post->user->name;
$postarray['owner-link'] = "https://twitter.com/" . $post->user->screen_name;
$postarray['owner-avatar'] = twitter_fix_avatar($post->user->profile_image_url_https);
}
@ -1799,20 +1809,20 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl
return [];
}
$postarray['contact-id'] = $contactid;
$postarray['verb'] = Activity::POST;
$postarray['author-name'] = $postarray['owner-name'];
$postarray['author-link'] = $postarray['owner-link'];
$postarray['contact-id'] = $contactid;
$postarray['verb'] = Activity::POST;
$postarray['author-id'] = $postarray['owner-id'];
$postarray['author-name'] = $postarray['owner-name'];
$postarray['author-link'] = $postarray['owner-link'];
$postarray['author-avatar'] = $postarray['owner-avatar'];
$postarray['plink'] = "https://twitter.com/" . $post->user->screen_name . "/status/" . $post->id_str;
$postarray['app'] = strip_tags($post->source);
$postarray['plink'] = "https://twitter.com/" . $post->user->screen_name . "/status/" . $post->id_str;
$postarray['app'] = strip_tags($post->source);
if ($post->user->protected) {
$postarray['private'] = Item::PRIVATE;
$postarray['private'] = Item::PRIVATE;
$postarray['allow_cid'] = '<' . $self['id'] . '>';
} else {
$postarray['private'] = Item::UNLISTED;
$postarray['private'] = Item::UNLISTED;
$postarray['allow_cid'] = '';
}
@ -1876,13 +1886,14 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl
$postarray['thr-parent'] = $retweet['uri'];
} else {
$retweet['source'] = $postarray['source'];
$retweet['direction'] = $postarray['direction'];
$retweet['private'] = $postarray['private'];
$retweet['allow_cid'] = $postarray['allow_cid'];
$retweet['contact-id'] = $postarray['contact-id'];
$retweet['owner-name'] = $postarray['owner-name'];
$retweet['owner-link'] = $postarray['owner-link'];
$retweet['source'] = $postarray['source'];
$retweet['direction'] = $postarray['direction'];
$retweet['private'] = $postarray['private'];
$retweet['allow_cid'] = $postarray['allow_cid'];
$retweet['contact-id'] = $postarray['contact-id'];
$retweet['owner-id'] = $postarray['owner-id'];
$retweet['owner-name'] = $postarray['owner-name'];
$retweet['owner-link'] = $postarray['owner-link'];
$retweet['owner-avatar'] = $postarray['owner-avatar'];
$postarray = $retweet;