diff --git a/components/Media/Media.php b/components/Media/Media.php index 21910a1f36..7b055c626f 100644 --- a/components/Media/Media.php +++ b/components/Media/Media.php @@ -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) { - $vars['user_avatar'] = self::getAvatarUrl(); + if (Common::user() != null) { + $vars['user_avatar'] = self::getAvatarUrl(); + } return Event::next; } diff --git a/components/Media/Utils.php b/components/Media/Utils.php index 0297f47a1f..425f8e4c40 100644 --- a/components/Media/Utils.php +++ b/components/Media/Utils.php @@ -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) {