diff options
-rw-r--r-- | core/Controller/GuestAvatarController.php | 13 | ||||
-rw-r--r-- | core/routes.php | 1 | ||||
-rw-r--r-- | lib/private/Avatar/Avatar.php | 2 | ||||
-rw-r--r-- | lib/private/Avatar/GuestAvatar.php | 4 | ||||
-rw-r--r-- | lib/private/Avatar/PlaceholderAvatar.php | 10 |
5 files changed, 20 insertions, 10 deletions
diff --git a/core/Controller/GuestAvatarController.php b/core/Controller/GuestAvatarController.php index 9c0606f368f..09146ff3928 100644 --- a/core/Controller/GuestAvatarController.php +++ b/core/Controller/GuestAvatarController.php @@ -60,8 +60,9 @@ class GuestAvatarController extends Controller { * @param string $size The desired avatar size, e.g. 64 for 64x64px * @return FileDisplayResponse|Http\Response */ - public function getAvatar(string $guestName, string $size) { + public function getAvatar(string $guestName, string $size, ?bool $dark = false) { $size = (int) $size; + $dark = $dark === null ? false : $dark; if ($size <= 64) { if ($size !== 64) { @@ -94,7 +95,15 @@ class GuestAvatarController extends Controller { } // Cache for 30 minutes - $resp->cacheFor(1800); + $resp->cacheFor(1800, false, true); return $resp; } + + /** + * @PublicPage + * @NoCSRFRequired + */ + public function getAvatarDark(string $guestName, string $size) { + return $this->getAvatar($guestName, $size, true); + } } diff --git a/core/routes.php b/core/routes.php index ee5fbb34a4c..5e08213828d 100644 --- a/core/routes.php +++ b/core/routes.php @@ -51,6 +51,7 @@ $application->registerRoutes($this, [ ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'], ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'], ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'], + ['name' => 'GuestAvatar#getAvatarDark', 'url' => '/avatar/guest/{guestName}/{size}/dark', 'verb' => 'GET'], ['name' => 'GuestAvatar#getAvatar', 'url' => '/avatar/guest/{guestName}/{size}', 'verb' => 'GET'], ['name' => 'CSRFToken#index', 'url' => '/csrftoken', 'verb' => 'GET'], ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'], diff --git a/lib/private/Avatar/Avatar.php b/lib/private/Avatar/Avatar.php index aec0f6e10f4..1e6ebd7c61b 100644 --- a/lib/private/Avatar/Avatar.php +++ b/lib/private/Avatar/Avatar.php @@ -150,7 +150,7 @@ abstract class Avatar implements IAvatar { protected function generateAvatar(string $userDisplayName, int $size, bool $dark): string { $text = $this->getAvatarText(); $textColor = $this->avatarBackgroundColor($userDisplayName); - $backgroundColor = $textColor->alphaBlending(0.1, $dark ? new Color() : new Color(255, 255, 255)); + $backgroundColor = $textColor->alphaBlending(0.1, $dark ? new Color(0, 0, 0) : new Color(255, 255, 255)); $im = imagecreatetruecolor($size, $size); $background = imagecolorallocate( diff --git a/lib/private/Avatar/GuestAvatar.php b/lib/private/Avatar/GuestAvatar.php index 79d7e6ee094..083deb4108f 100644 --- a/lib/private/Avatar/GuestAvatar.php +++ b/lib/private/Avatar/GuestAvatar.php @@ -84,8 +84,8 @@ class GuestAvatar extends Avatar { /** * Generates an avatar for the guest. */ - public function getFile(int $size): ISimpleFile { - $avatar = $this->generateAvatar($this->userDisplayName, $size); + public function getFile(int $size, bool $darkTheme = false): ISimpleFile { + $avatar = $this->generateAvatar($this->userDisplayName, $size, $darkTheme); return new InMemoryFile('avatar.png', $avatar); } diff --git a/lib/private/Avatar/PlaceholderAvatar.php b/lib/private/Avatar/PlaceholderAvatar.php index 504e5c1457d..e7ca89f4d30 100644 --- a/lib/private/Avatar/PlaceholderAvatar.php +++ b/lib/private/Avatar/PlaceholderAvatar.php @@ -108,13 +108,13 @@ class PlaceholderAvatar extends Avatar { * @throws \OCP\Files\NotPermittedException * @throws \OCP\PreConditionNotMetException */ - public function getFile(int $size): ISimpleFile { + public function getFile(int $size, bool $darkTheme = false): ISimpleFile { $ext = 'png'; if ($size === -1) { - $path = 'avatar-placeholder.' . $ext; + $path = 'avatar-placeholder' . ($darkTheme ? '-dark' : '') . '.' . $ext; } else { - $path = 'avatar-placeholder.' . $size . '.' . $ext; + $path = 'avatar-placeholder' . ($darkTheme ? '-dark' : '') . '.' . $size . '.' . $ext; } try { @@ -124,8 +124,8 @@ class PlaceholderAvatar extends Avatar { throw new NotFoundException; } - if (!$data = $this->generateAvatarFromSvg($size)) { - $data = $this->generateAvatar($this->getDisplayName(), $size); + if (!$data = $this->generateAvatarFromSvg($size, $darkTheme)) { + $data = $this->generateAvatar($this->getDisplayName(), $size, $darkTheme); } try { |