summaryrefslogtreecommitdiffstats
path: root/lib/Controller/AvatarController.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-05-04 13:08:16 +0200
committerJoas Schilling <coding@schilljs.com>2023-05-04 16:38:59 +0200
commit555f4a7e3ab4c69be79dffcf8f794ec3bfa2c8b2 (patch)
tree44a853200d20c79087d8d9893a0e9b47f856bdcf /lib/Controller/AvatarController.php
parent741f7c5689908742fdd757e68d293b09d1b34a53 (diff)
feat(avatar): Allow to select an emoji + color as avatar
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Controller/AvatarController.php')
-rw-r--r--lib/Controller/AvatarController.php23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/Controller/AvatarController.php b/lib/Controller/AvatarController.php
index 7edebf977..b069975c0 100644
--- a/lib/Controller/AvatarController.php
+++ b/lib/Controller/AvatarController.php
@@ -27,6 +27,7 @@ declare(strict_types=1);
namespace OCA\Talk\Controller;
use InvalidArgumentException;
+use OCA\Mail\Service\Avatar\Avatar;
use OCA\Talk\Middleware\Attribute\RequireModeratorParticipant;
use OCA\Talk\Middleware\Attribute\RequireParticipant;
use OCA\Talk\Service\AvatarService;
@@ -79,6 +80,28 @@ class AvatarController extends AEnvironmentAwareController {
}
#[PublicPage]
+ #[RequireModeratorParticipant]
+ public function emojiAvatar(string $emoji, ?string $color): DataResponse {
+ try {
+ $this->avatarService->setAvatarFromEmoji($this->getRoom(), $emoji, $color);
+ return new DataResponse($this->roomFormatter->formatRoom(
+ $this->getResponseFormat(),
+ [],
+ $this->getRoom(),
+ $this->participant,
+ ));
+ } catch (InvalidArgumentException $e) {
+ return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
+ } catch (\Exception $e) {
+ $this->logger->error('Failed to post avatar', [
+ 'exception' => $e,
+ ]);
+
+ return new DataResponse(['message' => $this->l->t('An error occurred. Please contact your administrator.')], Http::STATUS_BAD_REQUEST);
+ }
+ }
+
+ #[PublicPage]
#[NoCSRFRequired]
#[RequireParticipant]
public function getAvatar(bool $darkTheme = false): Response {