From 969df371ddbce21b61571a55feb2227f4004b115 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sat, 4 Dec 2021 11:56:27 +0000 Subject: [PATCH] [COMPONENT][Avatar] Small refactor --- components/Avatar/Avatar.php | 2 +- src/Entity/Actor.php | 2 +- src/Entity/Note.php | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/components/Avatar/Avatar.php b/components/Avatar/Avatar.php index 2f319fc20e..f6cf7bbf0d 100644 --- a/components/Avatar/Avatar.php +++ b/components/Avatar/Avatar.php @@ -101,7 +101,7 @@ class Avatar extends Component /** * Get the cached avatar associated with the given Actor id, or the current user if not given */ - public static function getAvatarUrl(int $actor_id, string $size = 'full', int $type = Router::ABSOLUTE_PATH): string + public static function getUrl(int $actor_id, string $size = 'full', int $type = Router::ABSOLUTE_PATH): string { try { return self::getAvatar($actor_id)->getUrl($size, $type); diff --git a/src/Entity/Actor.php b/src/Entity/Actor.php index 753057b438..6fc4c1faff 100644 --- a/src/Entity/Actor.php +++ b/src/Entity/Actor.php @@ -247,7 +247,7 @@ class Actor extends Entity public function getAvatarUrl(string $size = 'full') { - return Avatar::getAvatarUrl($this->getId(), $size); + return Avatar::getUrl($this->getId(), $size); } public function getAvatarDimensions(string $size = 'full') diff --git a/src/Entity/Note.php b/src/Entity/Note.php index ebc2b57bea..02b4774987 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -213,7 +213,12 @@ class Note extends Entity public function getActorAvatarUrl(string $size = 'full'): string { - return Avatar::getAvatarUrl($this->getActorId(), $size); + return Avatar::getUrl($this->getActorId(), $size); + } + + public static function getFromId(int $note_id): self + { + return Cache::get("note-{$note_id}", fn () => DB::findOneBy('note', ['id' => $note_id])); } public function getNoteLanguageShortDisplay(): string