mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-22 08:23:43 +00:00
Merge pull request #1234 from annando/twitter-avatar
Twitter: Assign contacts via their twitter id - not via their url
This commit is contained in:
commit
dd6bf79e19
1 changed files with 34 additions and 23 deletions
|
@ -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,6 +1796,7 @@ 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-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);
|
||||
|
@ -1800,8 +1810,8 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl
|
|||
}
|
||||
|
||||
$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'];
|
||||
|
@ -1881,6 +1891,7 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl
|
|||
$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'];
|
||||
|
|
Loading…
Reference in a new issue