diff options
author | Joas Schilling <coding@schilljs.com> | 2022-05-24 09:17:26 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-05-24 09:26:30 +0300 |
commit | 6097eb20aa8e593f64ecf5494c3c43069337321f (patch) | |
tree | b7cb8da0bb1c6102602d6407bf5a907fa52e704c /lib | |
parent | b2de1e8034b999373230f87b7bd1284f623f8cb0 (diff) |
Move setDescription to room servicetechdebt/6235/set-description
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Command/Room/TRoomCommand.php | 2 | ||||
-rw-r--r-- | lib/Controller/RoomController.php | 2 | ||||
-rw-r--r-- | lib/Room.php | 36 | ||||
-rw-r--r-- | lib/Service/RoomService.php | 33 |
4 files changed, 39 insertions, 34 deletions
diff --git a/lib/Command/Room/TRoomCommand.php b/lib/Command/Room/TRoomCommand.php index 07b31bc5e..280f96b8d 100644 --- a/lib/Command/Room/TRoomCommand.php +++ b/lib/Command/Room/TRoomCommand.php @@ -114,7 +114,7 @@ trait TRoomCommand { */ protected function setRoomDescription(Room $room, string $description): void { try { - $room->setDescription($description); + $this->roomService->setDescription($room, $description); } catch (\LengthException $e) { throw new InvalidArgumentException('Invalid room description.'); } diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index 7eba275b1..3d5e542ed 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -876,7 +876,7 @@ class RoomController extends AEnvironmentAwareController { } try { - $this->room->setDescription($description); + $this->roomService->setDescription($this->room, $description); } catch (\LengthException $exception) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } diff --git a/lib/Room.php b/lib/Room.php index 49f6ca324..a965dda8c 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -359,6 +359,10 @@ class Room { return $this->description; } + public function setDescription(string $description): void { + $this->description = $description; + } + /** * @deprecated Use ParticipantService::getGuestCount() instead * @return int @@ -689,38 +693,6 @@ class Room { } /** - * @param string $description - * @return bool True when the change was valid, false otherwise - * @throws \LengthException when the given description is too long - */ - public function setDescription(string $description): bool { - $description = trim($description); - - if (mb_strlen($description) > self::DESCRIPTION_MAXIMUM_LENGTH) { - throw new \LengthException('Conversation description is limited to ' . self::DESCRIPTION_MAXIMUM_LENGTH . ' characters'); - } - - $oldDescription = $this->getDescription(); - if ($description === $oldDescription) { - return false; - } - - $event = new ModifyRoomEvent($this, 'description', $description, $oldDescription); - $this->dispatcher->dispatch(self::EVENT_BEFORE_DESCRIPTION_SET, $event); - - $update = $this->db->getQueryBuilder(); - $update->update('talk_rooms') - ->set('description', $update->createNamedParameter($description)) - ->where($update->expr()->eq('id', $update->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT))); - $update->executeStatement(); - $this->description = $description; - - $this->dispatcher->dispatch(self::EVENT_AFTER_DESCRIPTION_SET, $event); - - return true; - } - - /** * @param string $password Currently it is only allowed to have a password for Room::TYPE_PUBLIC * @return bool True when the change was valid, false otherwise */ diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php index 0c9805d44..ca5f8cb8a 100644 --- a/lib/Service/RoomService.php +++ b/lib/Service/RoomService.php @@ -440,6 +440,39 @@ class RoomService { return $updated; } + /** + * @param string $description + * @return bool True when the change was valid, false otherwise + * @throws \LengthException when the given description is too long + */ + public function setDescription(Room $room, string $description): bool { + $description = trim($description); + + if (mb_strlen($description) > Room::DESCRIPTION_MAXIMUM_LENGTH) { + throw new \LengthException('Conversation description is limited to ' . Room::DESCRIPTION_MAXIMUM_LENGTH . ' characters'); + } + + $oldDescription = $room->getDescription(); + if ($description === $oldDescription) { + return false; + } + + $event = new ModifyRoomEvent($room, 'description', $description, $oldDescription); + $this->dispatcher->dispatch(Room::EVENT_BEFORE_DESCRIPTION_SET, $event); + + $update = $this->db->getQueryBuilder(); + $update->update('talk_rooms') + ->set('description', $update->createNamedParameter($description)) + ->where($update->expr()->eq('id', $update->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT))); + $update->executeStatement(); + + $room->setDescription($description); + + $this->dispatcher->dispatch(Room::EVENT_AFTER_DESCRIPTION_SET, $event); + + return true; + } + public function verifyPassword(Room $room, string $password): array { $event = new VerifyRoomPasswordEvent($room, $password); $this->dispatcher->dispatch(Room::EVENT_PASSWORD_VERIFY, $event); |