diff options
author | Vitor Mattos <vitor@php.rio> | 2023-05-01 14:31:28 -0300 |
---|---|---|
committer | Vitor Mattos <vitor@php.rio> | 2023-05-03 04:58:45 -0300 |
commit | cb3fa784d49afd72587130ec7fe9b3b71bb12a13 (patch) | |
tree | 4e25f4d54ad50b439eed67e3a881fb2b50bbe3e3 /lib | |
parent | b140bcf69116e5732c510f83ca368f7ed816cb12 (diff) |
Fixes to be able identify if have a custom avatar
* Added the header X-NC-IsCustomAvatar
* Return every time a non empty string as avatarVersion
Signed-off-by: Vitor Mattos <vitor@php.rio>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/AvatarController.php | 1 | ||||
-rw-r--r-- | lib/Service/AvatarService.php | 34 |
2 files changed, 26 insertions, 9 deletions
diff --git a/lib/Controller/AvatarController.php b/lib/Controller/AvatarController.php index 7edebf977..876f0dc22 100644 --- a/lib/Controller/AvatarController.php +++ b/lib/Controller/AvatarController.php @@ -86,6 +86,7 @@ class AvatarController extends AEnvironmentAwareController { $response = new FileDisplayResponse($file); $response->addHeader('Content-Type', $file->getMimeType()); + $response->addHeader('X-NC-IsCustomAvatar', $this->avatarService->isCustomAvatar($this->getRoom()) ? '1' : '0'); // Cache for 1 day $response->cacheFor(60 * 60 * 24, false, true); return $response; diff --git a/lib/Service/AvatarService.php b/lib/Service/AvatarService.php index 5dd942fc4..2a0513761 100644 --- a/lib/Service/AvatarService.php +++ b/lib/Service/AvatarService.php @@ -185,19 +185,26 @@ class AvatarService { } elseif ($this->emojiHelper->isValidSingleEmoji(mb_substr($room->getName(), 0, 1))) { $file = new InMemoryFile($token, $this->getEmojiAvatar($room->getName(), $darkTheme)); } elseif ($room->getType() === Room::TYPE_CHANGELOG) { - $file = new InMemoryFile($token, file_get_contents(__DIR__ . '/../../img/changelog.svg')); + $fileName = 'changelog.svg'; + $file = new InMemoryFile($fileName, file_get_contents(__DIR__ . '/../../img/' . $fileName)); } elseif ($room->getObjectType() === 'file') { - $file = new InMemoryFile($token, file_get_contents(__DIR__ . '/../../img/icon-conversation-text-' . $colorTone . '.svg')); + $fileName = 'icon-conversation-text-' . $colorTone . '.svg'; + $file = new InMemoryFile($fileName, file_get_contents(__DIR__ . '/../../img/' . $fileName)); } elseif ($room->getObjectType() === 'share:password') { - $file = new InMemoryFile($token, file_get_contents(__DIR__ . '/../../img/icon-conversation-password-' . $colorTone . '.svg')); + $fileName = 'icon-conversation-password-' . $colorTone . '.svg'; + $file = new InMemoryFile($fileName, file_get_contents(__DIR__ . '/../../img/' . $fileName)); } elseif ($room->getObjectType() === 'emails') { - $file = new InMemoryFile($token, file_get_contents(__DIR__ . '/../../img/icon-conversation-mail-' . $colorTone . '.svg')); + $fileName = 'icon-conversation-mail-' . $colorTone . '.svg'; + $file = new InMemoryFile($fileName, file_get_contents(__DIR__ . '/../../img/' . $fileName)); } elseif ($room->getType() === Room::TYPE_PUBLIC) { - $file = new InMemoryFile($token, file_get_contents(__DIR__ . '/../../img/icon-conversation-public-' . $colorTone . '.svg')); + $fileName = 'icon-conversation-public-' . $colorTone . '.svg'; + $file = new InMemoryFile($fileName, file_get_contents(__DIR__ . '/../../img/' . $fileName)); } elseif ($room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { - $file = new InMemoryFile($token, file_get_contents(__DIR__ . '/../../img/icon-conversation-user-' . $colorTone . '.svg')); + $fileName = 'icon-conversation-user-' . $colorTone . '.svg'; + $file = new InMemoryFile($fileName, file_get_contents(__DIR__ . '/../../img/' . $fileName)); } else { - $file = new InMemoryFile($token, file_get_contents(__DIR__ . '/../../img/icon-conversation-group-' . $colorTone . '.svg')); + $fileName = 'icon-conversation-group-' . $colorTone . '.svg'; + $file = new InMemoryFile($fileName, file_get_contents(__DIR__ . '/../../img/' . $fileName)); } } return $file; @@ -245,6 +252,11 @@ class AvatarService { return ''; } + public function isCustomAvatar(Room $room): bool { + return $room->getAvatar() !== '' + || $this->getFirstCombinedEmoji($room->getName()); + } + public function deleteAvatar(Room $room): void { try { $folder = $this->appData->getFolder('room-avatar'); @@ -270,7 +282,11 @@ class AvatarService { public function getAvatarVersion(Room $room): string { $avatarVersion = $room->getAvatar(); - [$version] = explode('.', $avatarVersion); - return $version; + if ($avatarVersion) { + [$version] = explode('.', $avatarVersion); + return $version; + } + $file = $this->getAvatar($room, null); + return substr(md5($file->getName()), 0, 8); } } |