mirror of
https://github.com/friendica/friendica
synced 2025-04-24 11:50:10 +00:00
Merge remote-tracking branch 'upstream/2021.09-rc' into user-contact
This commit is contained in:
commit
3dddea96fa
30 changed files with 414 additions and 301 deletions
|
@ -653,9 +653,9 @@ class Contact
|
|||
'nick' => $user['nickname'],
|
||||
'pubkey' => $user['pubkey'],
|
||||
'prvkey' => $user['prvkey'],
|
||||
'photo' => DI::baseUrl() . '/photo/profile/' . $user['uid'] . '.jpg',
|
||||
'thumb' => DI::baseUrl() . '/photo/avatar/' . $user['uid'] . '.jpg',
|
||||
'micro' => DI::baseUrl() . '/photo/micro/' . $user['uid'] . '.jpg',
|
||||
'photo' => User::getAvatarUrlForId($user['uid']),
|
||||
'thumb' => User::getAvatarUrlForId($user['uid'], Proxy::SIZE_THUMB),
|
||||
'micro' => User::getAvatarUrlForId($user['uid'], Proxy::SIZE_MICRO),
|
||||
'blocked' => 0,
|
||||
'pending' => 0,
|
||||
'url' => DI::baseUrl() . '/profile/' . $user['nickname'],
|
||||
|
@ -768,7 +768,7 @@ class Contact
|
|||
$fields['micro'] = self::getDefaultAvatar($fields, Proxy::SIZE_MICRO);
|
||||
}
|
||||
|
||||
$fields['avatar'] = DI::baseUrl() . '/photo/profile/' .$uid . '.' . $file_suffix;
|
||||
$fields['avatar'] = User::getAvatarUrlForId($uid);
|
||||
$fields['forum'] = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
|
||||
$fields['prv'] = $user['page-flags'] == User::PAGE_FLAGS_PRVGROUP;
|
||||
$fields['unsearchable'] = !$profile['net-publish'];
|
||||
|
@ -794,8 +794,11 @@ class Contact
|
|||
self::update($fields, ['uid' => 0, 'nurl' => $self['nurl']]);
|
||||
|
||||
// Update the profile
|
||||
$fields = ['photo' => DI::baseUrl() . '/photo/profile/' .$uid . '.' . $file_suffix,
|
||||
'thumb' => DI::baseUrl() . '/photo/avatar/' . $uid .'.' . $file_suffix];
|
||||
$fields = [
|
||||
'photo' => User::getAvatarUrlForId($uid),
|
||||
'thumb' => User::getAvatarUrlForId($uid, Proxy::SIZE_THUMB)
|
||||
];
|
||||
|
||||
DBA::update('profile', $fields, ['uid' => $uid]);
|
||||
}
|
||||
|
||||
|
@ -2780,12 +2783,14 @@ class Contact
|
|||
return null;
|
||||
}
|
||||
|
||||
public static function removeFollower($importer, $contact)
|
||||
public static function removeFollower(array $contact)
|
||||
{
|
||||
if (($contact['rel'] == self::FRIEND) || ($contact['rel'] == self::SHARING)) {
|
||||
self::update(['rel' => self::SHARING], ['id' => $contact['id']]);
|
||||
} else {
|
||||
if (in_array($contact['rel'] ?? [], [self::FRIEND, self::SHARING])) {
|
||||
DBA::update('contact', ['rel' => self::SHARING], ['id' => $contact['id']]);
|
||||
} elseif (!empty($contact['id'])) {
|
||||
self::remove($contact['id']);
|
||||
} else {
|
||||
DI::logger()->info('Couldn\'t remove follower because of invalid contact array', ['contact' => $contact, 'callstack' => System::callstack()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -547,7 +547,7 @@ class Media
|
|||
return $attachments;
|
||||
}
|
||||
|
||||
$height = 0;
|
||||
$heights = [];
|
||||
$selected = '';
|
||||
$previews = [];
|
||||
|
||||
|
@ -591,14 +591,11 @@ class Media
|
|||
in_array($filetype, ['audio', 'image'])) {
|
||||
$attachments['visual'][] = $medium;
|
||||
} elseif (($medium['type'] == self::VIDEO) || ($filetype == 'video')) {
|
||||
if (strpos($medium['url'], $guid) !== false) {
|
||||
if (!empty($medium['height'])) {
|
||||
// Peertube videos are delivered in many different resolutions. We pick a moderate one.
|
||||
// By checking against the GUID we also ensure to only work this way on Peertube posts.
|
||||
// This wouldn't be executed when someone for example on Mastodon was sharing multiple videos in a single post.
|
||||
if (empty($height) || ($height > $medium['height']) && ($medium['height'] >= 480)) {
|
||||
$height = $medium['height'];
|
||||
$selected = $medium['url'];
|
||||
}
|
||||
// Since only Peertube provides a "height" parameter, this wouldn't be executed
|
||||
// when someone for example on Mastodon was sharing multiple videos in a single post.
|
||||
$heights[$medium['height']] = $medium['url'];
|
||||
$video[$medium['url']] = $medium;
|
||||
} else {
|
||||
$attachments['visual'][] = $medium;
|
||||
|
@ -607,13 +604,24 @@ class Media
|
|||
$attachments['additional'][] = $medium;
|
||||
}
|
||||
}
|
||||
if (!empty($selected)) {
|
||||
$attachments['visual'][] = $video[$selected];
|
||||
unset($video[$selected]);
|
||||
foreach ($video as $element) {
|
||||
$attachments['additional'][] = $element;
|
||||
|
||||
if (!empty($heights)) {
|
||||
ksort($heights);
|
||||
foreach ($heights as $height => $url) {
|
||||
if (empty($selected) || $height <= 480) {
|
||||
$selected = $url;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($selected)) {
|
||||
$attachments['visual'][] = $video[$selected];
|
||||
unset($video[$selected]);
|
||||
foreach ($video as $element) {
|
||||
$attachments['additional'][] = $element;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $attachments;
|
||||
}
|
||||
|
||||
|
|
|
@ -840,6 +840,57 @@ class User
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get avatar link for given user id
|
||||
*
|
||||
* @param integer $uid user id
|
||||
* @param string $size One of the ProxyUtils::SIZE_* constants
|
||||
* @return string avatar link
|
||||
*/
|
||||
public static function getAvatarUrlForId(int $uid, string $size = ''):string
|
||||
{
|
||||
$url = DI::baseUrl() . '/photo/';
|
||||
|
||||
switch ($size) {
|
||||
case Proxy::SIZE_MICRO:
|
||||
$url .= 'micro/';
|
||||
$scale = 6;
|
||||
break;
|
||||
case Proxy::SIZE_THUMB:
|
||||
$url .= 'avatar/';
|
||||
$scale = 5;
|
||||
break;
|
||||
default:
|
||||
$url .= 'profile/';
|
||||
$scale = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
$updated = '';
|
||||
$imagetype = IMAGETYPE_JPEG;
|
||||
|
||||
$photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => $scale, 'uid' => $uid, 'profile' => true]);
|
||||
if (!empty($photo)) {
|
||||
$updated = max($photo['created'], $photo['edited'], $photo['updated']);
|
||||
|
||||
switch ($photo['type']) {
|
||||
case 'image/png':
|
||||
$imagetype = IMAGETYPE_PNG;
|
||||
break;
|
||||
|
||||
case 'image/gif':
|
||||
$imagetype = IMAGETYPE_PNG;
|
||||
break;
|
||||
|
||||
default:
|
||||
$imagetype = IMAGETYPE_JPEG;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $url . $uid . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Catch-all user creation function
|
||||
*
|
||||
|
@ -1054,8 +1105,8 @@ class User
|
|||
$insert_result = DBA::insert('profile', [
|
||||
'uid' => $uid,
|
||||
'name' => $username,
|
||||
'photo' => DI::baseUrl() . "/photo/profile/{$uid}.jpg",
|
||||
'thumb' => DI::baseUrl() . "/photo/avatar/{$uid}.jpg",
|
||||
'photo' => self::getAvatarUrlForId($uid),
|
||||
'thumb' => self::getAvatarUrlForId($uid, Proxy::SIZE_THUMB),
|
||||
'publish' => $publish,
|
||||
'net-publish' => $netpublish,
|
||||
]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue