Browse Source

Move setDescription to room service

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/7413/head
Joas Schilling 3 years ago
parent
commit
6097eb20aa
No known key found for this signature in database GPG Key ID: 7076EA9751AACDDA
  1. 2
      lib/Command/Room/TRoomCommand.php
  2. 2
      lib/Controller/RoomController.php
  3. 36
      lib/Room.php
  4. 33
      lib/Service/RoomService.php
  5. 2
      tests/php/Signaling/BackendNotifierTest.php

2
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.');
}

2
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);
}

36
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
@ -688,38 +692,6 @@ class Room {
return true;
}
/**
* @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

33
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);

2
tests/php/Signaling/BackendNotifierTest.php

@ -438,7 +438,7 @@ class BackendNotifierTest extends TestCase {
public function testRoomDescriptionChanged() {
$room = $this->manager->createRoom(Room::TYPE_PUBLIC);
$room->setDescription('The description');
$this->roomService->setDescription($room, 'The description');
$this->assertMessageWasSent($room, [
'type' => 'update',

Loading…
Cancel
Save