From 17cc7bc67d229d76100fcb790f0a3bdd3069a41b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 29 Aug 2024 11:11:47 +0200 Subject: [PATCH] fix(api): Properly typed avatar update Signed-off-by: Joas Schilling --- .../RoomProperty/AvatarException.php | 29 +++++++++++++++++++ lib/Service/RoomService.php | 17 ++++++----- 2 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 lib/Exceptions/RoomProperty/AvatarException.php diff --git a/lib/Exceptions/RoomProperty/AvatarException.php b/lib/Exceptions/RoomProperty/AvatarException.php new file mode 100644 index 00000000000..907627bc152 --- /dev/null +++ b/lib/Exceptions/RoomProperty/AvatarException.php @@ -0,0 +1,29 @@ +reason; + } +} diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php index 6b7c8ea632d..a813e906596 100644 --- a/lib/Service/RoomService.php +++ b/lib/Service/RoomService.php @@ -27,6 +27,7 @@ use OCA\Talk\Events\RoomPasswordVerifyEvent; use OCA\Talk\Events\RoomSyncedEvent; use OCA\Talk\Exceptions\RoomNotFoundException; +use OCA\Talk\Exceptions\RoomProperty\AvatarException; use OCA\Talk\Exceptions\RoomProperty\BreakoutRoomModeException; use OCA\Talk\Exceptions\RoomProperty\BreakoutRoomStatusException; use OCA\Talk\Exceptions\RoomProperty\CallRecordingException; @@ -420,9 +421,12 @@ public function setLobby(Room $room, int $newState, ?\DateTime $dateTime, bool $ } } - public function setAvatar(Room $room, string $avatar): bool { + /** + * @throws AvatarException + */ + public function setAvatar(Room $room, string $avatar): void { if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { - return false; + throw new AvatarException(AvatarException::REASON_TYPE); } $oldAvatar = $room->getAvatar(); @@ -439,7 +443,6 @@ public function setAvatar(Room $room, string $avatar): bool { $event = new RoomModifiedEvent($room, ARoomModifiedEvent::PROPERTY_AVATAR, $avatar, $oldAvatar); $this->dispatcher->dispatchTyped($event); - return true; } /** @@ -1079,11 +1082,11 @@ public function syncPropertiesFromHostRoom(Room $local, array $host): void { // Add a fake suffix as we explode by the dot in the AvatarService, but the version doesn't have one. $hostAvatar .= '.fed'; } - $success = $this->setAvatar($local, $hostAvatar); - if (!$success) { - $this->logger->error('An error occurred while trying to sync avatarVersion of ' . $local->getId() . ' to ' . $host['avatarVersion']); - } else { + try { + $this->setAvatar($local, $hostAvatar); $changed[] = ARoomModifiedEvent::PROPERTY_AVATAR; + } catch (AvatarException $e) { + $this->logger->error('An error (' . $e->getReason() . ') occurred while trying to sync avatarVersion of ' . $local->getId() . ' to ' . $host['avatarVersion'], ['exception' => $e]); } } if (isset($host['lastActivity']) && $host['lastActivity'] !== 0 && $host['lastActivity'] !== ((int)$local->getLastActivity()?->getTimestamp())) {