[MEDIA] Only try to get an avatar if a user is logged in
This commit is contained in:
parent
6ed89c77f4
commit
4507b12976
@ -22,6 +22,7 @@ namespace Component\Media;
|
||||
use App\Core\Cache;
|
||||
use App\Core\Event;
|
||||
use App\Core\Module;
|
||||
use App\Util\Common;
|
||||
use App\Util\Nickname;
|
||||
|
||||
class Media extends Module
|
||||
@ -39,7 +40,9 @@ class Media extends Module
|
||||
|
||||
public function onEndTwigPopulateVars(array &$vars)
|
||||
{
|
||||
if (Common::user() != null) {
|
||||
$vars['user_avatar'] = self::getAvatarUrl();
|
||||
}
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,6 @@ abstract class Utils
|
||||
'file_hash' => $hash,
|
||||
'actor_id' => $actor_id,
|
||||
'mimetype' => $sfile->getMimeType(),
|
||||
'size' => $sfile->getSize(),
|
||||
'title' => $title ?: _m('Untitled attachment'),
|
||||
'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) {
|
||||
$user = Common::user();
|
||||
if ($user != null) {
|
||||
$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) {
|
||||
|
Loading…
Reference in New Issue
Block a user