diff --git a/lib/Command/Room/TRoomCommand.php b/lib/Command/Room/TRoomCommand.php index 59ab9dda5d9..c9d5058d608 100644 --- a/lib/Command/Room/TRoomCommand.php +++ b/lib/Command/Room/TRoomCommand.php @@ -26,6 +26,7 @@ namespace OCA\Talk\Command\Room; use InvalidArgumentException; +use OCA\Talk\Events\AAttendeeRemovedEvent; use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; @@ -298,7 +299,7 @@ protected function removeRoomParticipants(Room $room, array $userIds): void { } foreach ($users as $user) { - $this->participantService->removeUser($room, $user, Room::PARTICIPANT_REMOVED); + $this->participantService->removeUser($room, $user, AAttendeeRemovedEvent::REASON_REMOVED); } } diff --git a/lib/Command/User/TransferOwnership.php b/lib/Command/User/TransferOwnership.php index 6dacc490949..45764f4a633 100644 --- a/lib/Command/User/TransferOwnership.php +++ b/lib/Command/User/TransferOwnership.php @@ -26,6 +26,7 @@ namespace OCA\Talk\Command\User; use OC\Core\Command\Base; +use OCA\Talk\Events\AAttendeeRemovedEvent; use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Model\Attendee; @@ -136,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } if ($removeSourceUser) { - $this->participantService->removeAttendee($room, $sourceParticipant, Room::PARTICIPANT_REMOVED); + $this->participantService->removeAttendee($room, $sourceParticipant, AAttendeeRemovedEvent::REASON_REMOVED); } } diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index 2696c01e1ec..fc2b9fad19a 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -30,6 +30,7 @@ use InvalidArgumentException; use OCA\Talk\Config; +use OCA\Talk\Events\AAttendeeRemovedEvent; use OCA\Talk\Events\BeforeRoomsFetchEvent; use OCA\Talk\Events\UserEvent; use OCA\Talk\Exceptions\CannotReachRemoteException; @@ -1253,7 +1254,7 @@ protected function removeSelfFromRoomLogic(Room $room, Participant $participant) return new DataResponse([], Http::STATUS_NOT_FOUND); } - $this->participantService->removeUser($room, $currentUser, Room::PARTICIPANT_LEFT); + $this->participantService->removeUser($room, $currentUser, AAttendeeRemovedEvent::REASON_LEFT); return new DataResponse(); } @@ -1296,7 +1297,7 @@ public function removeAttendeeFromRoom(int $attendeeId): DataResponse { return new DataResponse([], Http::STATUS_FORBIDDEN); } - $this->participantService->removeAttendee($this->room, $targetParticipant, Room::PARTICIPANT_REMOVED); + $this->participantService->removeAttendee($this->room, $targetParticipant, AAttendeeRemovedEvent::REASON_REMOVED); return new DataResponse([]); } diff --git a/lib/Controller/SignalingController.php b/lib/Controller/SignalingController.php index 74247477697..050e62b54cf 100644 --- a/lib/Controller/SignalingController.php +++ b/lib/Controller/SignalingController.php @@ -28,6 +28,7 @@ use GuzzleHttp\Exception\ConnectException; use OCA\Talk\Config; +use OCA\Talk\Events\AAttendeeRemovedEvent; use OCA\Talk\Events\BeforeSignalingResponseSentEvent; use OCA\Talk\Events\SignalingEvent; use OCA\Talk\Exceptions\ParticipantNotFoundException; @@ -769,7 +770,7 @@ private function backendRoom(array $roomRequest): DataResponse { // Emails are retained as their PIN needs to remain and stay // valid. if ($participant->getAttendee()->getActorType() === Attendee::ACTOR_GUESTS) { - $this->participantService->removeAttendee($room, $participant, Room::PARTICIPANT_LEFT); + $this->participantService->removeAttendee($room, $participant, AAttendeeRemovedEvent::REASON_LEFT); } else { $this->participantService->leaveRoomAsSession($room, $participant); } diff --git a/lib/Listener/AMembershipListener.php b/lib/Listener/AMembershipListener.php index e5e97d1ef4c..c8fd904c965 100644 --- a/lib/Listener/AMembershipListener.php +++ b/lib/Listener/AMembershipListener.php @@ -25,6 +25,7 @@ use OCA\Circles\CirclesManager; use OCA\Circles\Model\Member; +use OCA\Talk\Events\AAttendeeRemovedEvent; use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Model\Attendee; @@ -61,7 +62,7 @@ protected function removeFromRoomsUnlessStillLinked(array $rooms, IUser $user): $participant = $room->getParticipant($user->getUID()); $participantType = $participant->getAttendee()->getParticipantType(); if ($participantType === Participant::USER) { - $this->participantService->removeUser($room, $user, Room::PARTICIPANT_REMOVED); + $this->participantService->removeUser($room, $user, AAttendeeRemovedEvent::REASON_REMOVED); } } catch (ParticipantNotFoundException $e) { } diff --git a/lib/Listener/CircleDeletedListener.php b/lib/Listener/CircleDeletedListener.php index d47e9b36c3b..0b1c8e41939 100644 --- a/lib/Listener/CircleDeletedListener.php +++ b/lib/Listener/CircleDeletedListener.php @@ -24,9 +24,9 @@ namespace OCA\Talk\Listener; use OCA\Circles\Events\CircleDestroyedEvent; +use OCA\Talk\Events\AAttendeeRemovedEvent; use OCA\Talk\Manager; use OCA\Talk\Model\Attendee; -use OCA\Talk\Room; use OCA\Talk\Service\ParticipantService; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; @@ -54,7 +54,7 @@ public function handle(Event $event): void { $rooms = $this->manager->getRoomsForActor(Attendee::ACTOR_CIRCLES, $circleId); foreach ($rooms as $room) { $participant = $this->participantService->getParticipantByActor($room, Attendee::ACTOR_CIRCLES, $circleId); - $this->participantService->removeAttendee($room, $participant, Room::PARTICIPANT_REMOVED); + $this->participantService->removeAttendee($room, $participant, AAttendeeRemovedEvent::REASON_REMOVED); } } } diff --git a/lib/Listener/GroupDeletedListener.php b/lib/Listener/GroupDeletedListener.php index ced188bf5d3..f81ae695121 100644 --- a/lib/Listener/GroupDeletedListener.php +++ b/lib/Listener/GroupDeletedListener.php @@ -23,9 +23,9 @@ namespace OCA\Talk\Listener; +use OCA\Talk\Events\AAttendeeRemovedEvent; use OCA\Talk\Manager; use OCA\Talk\Model\Attendee; -use OCA\Talk\Room; use OCA\Talk\Service\ParticipantService; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; @@ -60,7 +60,7 @@ public function handle(Event $event): void { $rooms = $this->manager->getRoomsForActor(Attendee::ACTOR_GROUPS, $gid); foreach ($rooms as $room) { $participant = $this->participantService->getParticipantByActor($room, Attendee::ACTOR_GROUPS, $gid); - $this->participantService->removeAttendee($room, $participant, Room::PARTICIPANT_REMOVED); + $this->participantService->removeAttendee($room, $participant, AAttendeeRemovedEvent::REASON_REMOVED); } } diff --git a/lib/Manager.php b/lib/Manager.php index c46d9077a18..728a72bdad8 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -24,6 +24,7 @@ namespace OCA\Talk; use OCA\Talk\Chat\CommentsManager; +use OCA\Talk\Events\AAttendeeRemovedEvent; use OCA\Talk\Events\RoomCreatedEvent; use OCA\Talk\Events\RoomEvent; use OCA\Talk\Exceptions\ParticipantNotFoundException; @@ -416,7 +417,7 @@ public function removeUserFromAllRooms(IUser $user, bool $privateOnly = false): if ($this->participantService->getNumberOfUsers($room) === 1) { Server::get(RoomService::class)->deleteRoom($room); } else { - $this->participantService->removeUser($room, $user, Room::PARTICIPANT_REMOVED_ALL); + $this->participantService->removeUser($room, $user, AAttendeeRemovedEvent::REASON_REMOVED_ALL); } } diff --git a/lib/MatterbridgeManager.php b/lib/MatterbridgeManager.php index 4cdee676028..c61be98f830 100644 --- a/lib/MatterbridgeManager.php +++ b/lib/MatterbridgeManager.php @@ -28,6 +28,7 @@ use OC\Authentication\Token\IProvider as IAuthTokenProvider; use OC\Authentication\Token\IToken; use OCA\Talk\Chat\ChatManager; +use OCA\Talk\Events\AAttendeeRemovedEvent; use OCA\Talk\Exceptions\ImpossibleToKillException; use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\Exceptions\RoomNotFoundException; @@ -278,7 +279,7 @@ private function checkBotUser(Room $room, bool $isBridgeEnabled): array { try { $this->participantService->getParticipant($room, self::BRIDGE_BOT_USERID, false); if (!$isBridgeEnabled) { - $this->participantService->removeUser($room, $botUser, Room::PARTICIPANT_REMOVED); + $this->participantService->removeUser($room, $botUser, AAttendeeRemovedEvent::REASON_REMOVED); } } catch (ParticipantNotFoundException $e) { if ($isBridgeEnabled) { diff --git a/lib/Service/BreakoutRoomService.php b/lib/Service/BreakoutRoomService.php index 834612be8d9..2346c51cf17 100644 --- a/lib/Service/BreakoutRoomService.php +++ b/lib/Service/BreakoutRoomService.php @@ -28,6 +28,7 @@ use InvalidArgumentException; use OCA\Talk\Chat\ChatManager; use OCA\Talk\Config; +use OCA\Talk\Events\AAttendeeRemovedEvent; use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Model\Attendee; @@ -238,7 +239,7 @@ public function applyAttendeeMap(Room $parent, string $attendeeMap): array { } foreach ($removals as $removal) { - $this->participantService->removeAttendee($removal['room'], $removal['participant'], Room::PARTICIPANT_REMOVED); + $this->participantService->removeAttendee($removal['room'], $removal['participant'], AAttendeeRemovedEvent::REASON_REMOVED); } $map = []; @@ -489,7 +490,7 @@ public function switchBreakoutRoom(Room $parent, Participant $participant, strin $this->participantService->removeAttendee( $breakoutRoom, $removeParticipant, - Room::PARTICIPANT_LEFT + AAttendeeRemovedEvent::REASON_LEFT ); } } catch (ParticipantNotFoundException $e) { @@ -572,7 +573,7 @@ public function removeAttendeeFromBreakoutRoom(Room $parent, string $actorType, throw new \InvalidArgumentException('moderator'); } - $this->participantService->removeAttendee($breakoutRoom, $participant, Room::PARTICIPANT_REMOVED); + $this->participantService->removeAttendee($breakoutRoom, $participant, AAttendeeRemovedEvent::REASON_REMOVED); } catch (ParticipantNotFoundException $e) { // Skip this room } diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index 3cba81c0854..840b682856c 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -28,6 +28,7 @@ use OCA\Circles\Model\Member; use OCA\Talk\Chat\ChatManager; use OCA\Talk\Config; +use OCA\Talk\Events\AAttendeeRemovedEvent; use OCA\Talk\Events\AddParticipantsEvent; use OCA\Talk\Events\AParticipantModifiedEvent; use OCA\Talk\Events\AttendeeRemovedEvent; @@ -177,7 +178,7 @@ public function updateParticipantType(Room $room, Participant $participant, int if ($demotedFromModerator) { // Remove participant from all breakout rooms - $this->removeAttendee($breakoutRoom, $breakoutRoomParticipant, Room::PARTICIPANT_REMOVED); + $this->removeAttendee($breakoutRoom, $breakoutRoomParticipant, AAttendeeRemovedEvent::REASON_REMOVED); } elseif (!$breakoutRoomParticipant->hasModeratorPermissions()) { if ($breakoutRoomParticipant->getAttendee()->getParticipantType() === Participant::USER || $breakoutRoomParticipant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED) { @@ -327,7 +328,7 @@ public function joinRoom(RoomService $roomService, Room $room, IUser $user, stri $this->dispatcher->dispatch(Room::EVENT_BEFORE_ROOM_CONNECT, $legacyEvent); if ($legacyEvent->getCancelJoin() === true) { - $this->removeUser($room, $user, Room::PARTICIPANT_LEFT); + $this->removeUser($room, $user, AAttendeeRemovedEvent::REASON_LEFT); throw new UnauthorizedException('Participant is not allowed to join'); } @@ -855,10 +856,13 @@ public function leaveRoomAsSession(Room $room, Participant $participant, bool $d && empty($this->sessionMapper->findByAttendeeId($participant->getAttendee()->getId()))) { $user = $this->userManager->get($participant->getAttendee()->getActorId()); - $this->removeUser($room, $user, Room::PARTICIPANT_LEFT); + $this->removeUser($room, $user, AAttendeeRemovedEvent::REASON_LEFT); } } + /** + * @psalm-param AAttendeeRemovedEvent::REASON_* $reason + */ public function removeAttendee(Room $room, Participant $participant, string $reason, bool $attendeeEventIsTriggeredAlready = false): void { $isUser = $participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS; @@ -1006,6 +1010,9 @@ public function removeCircleMembers(Room $room, Participant $removedCirclePartic $this->dispatcher->dispatchTyped($attendeeEvent); } + /** + * @psalm-param AAttendeeRemovedEvent::REASON_* $reason + */ public function removeUser(Room $room, IUser $user, string $reason): void { try { $participant = $this->getParticipant($room, $user->getUID(), false); @@ -1016,7 +1023,7 @@ public function removeUser(Room $room, IUser $user, string $reason): void { $attendee = $participant->getAttendee(); $sessions = $this->sessionService->getAllSessionsForAttendee($attendee); - if ($reason !== Room::PARTICIPANT_REMOVED_ALL && $room->getBreakoutRoomMode() !== BreakoutRoom::MODE_NOT_CONFIGURED) { + if ($reason !== AAttendeeRemovedEvent::REASON_REMOVED_ALL && $room->getBreakoutRoomMode() !== BreakoutRoom::MODE_NOT_CONFIGURED) { /** @var BreakoutRoomService $breakoutRoomService */ $breakoutRoomService = Server::get(BreakoutRoomService::class); $breakoutRoomService->removeAttendeeFromBreakoutRoom( @@ -1025,8 +1032,8 @@ public function removeUser(Room $room, IUser $user, string $reason): void { $attendee->getActorId(), false ); - } elseif ($reason === Room::PARTICIPANT_REMOVED_ALL) { - $reason = Room::PARTICIPANT_REMOVED; + } elseif ($reason === AAttendeeRemovedEvent::REASON_REMOVED_ALL) { + $reason = AAttendeeRemovedEvent::REASON_REMOVED; } $attendeeEvent = new BeforeAttendeeRemovedEvent($room, $attendee, $reason, $sessions);