forked from GNUsocial/gnu-social
[MEDIA] Only try to get an avatar if a user is logged in
This commit is contained in:
parent
1b0cab6dc8
commit
9204213dbc
@ -22,6 +22,7 @@ namespace Component\Media;
|
|||||||
use App\Core\Cache;
|
use App\Core\Cache;
|
||||||
use App\Core\Event;
|
use App\Core\Event;
|
||||||
use App\Core\Module;
|
use App\Core\Module;
|
||||||
|
use App\Util\Common;
|
||||||
use App\Util\Nickname;
|
use App\Util\Nickname;
|
||||||
|
|
||||||
class Media extends Module
|
class Media extends Module
|
||||||
@ -39,7 +40,9 @@ class Media extends Module
|
|||||||
|
|
||||||
public function onEndTwigPopulateVars(array &$vars)
|
public function onEndTwigPopulateVars(array &$vars)
|
||||||
{
|
{
|
||||||
$vars['user_avatar'] = self::getAvatarUrl();
|
if (Common::user() != null) {
|
||||||
|
$vars['user_avatar'] = self::getAvatarUrl();
|
||||||
|
}
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,6 @@ abstract class Utils
|
|||||||
'file_hash' => $hash,
|
'file_hash' => $hash,
|
||||||
'actor_id' => $actor_id,
|
'actor_id' => $actor_id,
|
||||||
'mimetype' => $sfile->getMimeType(),
|
'mimetype' => $sfile->getMimeType(),
|
||||||
'size' => $sfile->getSize(),
|
|
||||||
'title' => $title ?: _m('Untitled attachment'),
|
'title' => $title ?: _m('Untitled attachment'),
|
||||||
'is_local' => $is_local,
|
'is_local' => $is_local,
|
||||||
]);
|
]);
|
||||||
@ -137,12 +136,14 @@ abstract class Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAvatarUrl(string $nickname = null)
|
public static function getAvatarUrl(?string $nickname = null)
|
||||||
{
|
{
|
||||||
if ($nickname == null) {
|
if ($nickname == null) {
|
||||||
$user = Common::user();
|
$user = Common::user();
|
||||||
if ($user != null) {
|
if ($user != null) {
|
||||||
$nickname = $user->getNickname();
|
$nickname = $user->getNickname();
|
||||||
|
} else {
|
||||||
|
throw new Exception('No user is logged in and no avatar provided to `getAvatarUrl`');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Cache::get('avatar-url-' . $nickname, function () use ($nickname) {
|
return Cache::get('avatar-url-' . $nickname, function () use ($nickname) {
|
||||||
|
Loading…
Reference in New Issue
Block a user