diff options
author | Vitor Mattos <vitor@php.rio> | 2022-10-07 09:21:55 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-07 09:21:55 -0300 |
commit | b6f3890821fd12718c0bc2892b6249e6eaa82a42 (patch) | |
tree | cb353b223514d8b426f430d1b451430f38e924bc | |
parent | 03961228f64b5e6d0cee9c79135654bac3c5ada9 (diff) | |
parent | c897dcc5cd9392ae79a95389fa1a1fcd0af47047 (diff) |
Merge pull request #8106 from nextcloud/bugfix/6235/finish-room-model-clearing
Move getParticipant()
32 files changed, 254 insertions, 143 deletions
diff --git a/lib/Chat/Notifier.php b/lib/Chat/Notifier.php index 56f668252..9a9c4e2ed 100644 --- a/lib/Chat/Notifier.php +++ b/lib/Chat/Notifier.php @@ -283,7 +283,7 @@ class Notifier { return; } - $participant = $chat->getParticipant($comment->getActorId(), false); + $participant = $this->participantService->getParticipant($chat, $comment->getActorId(), false); $notificationLevel = $participant->getAttendee()->getNotificationLevel(); if ($notificationLevel === Participant::NOTIFY_DEFAULT) { if ($chat->getType() === Room::TYPE_ONE_TO_ONE) { @@ -449,7 +449,7 @@ class Notifier { return false; } - $participant = $room->getParticipant($userId, false); + $participant = $this->participantService->getParticipant($room, $userId, false); $attendee = $participant->getAttendee(); } else { $participant = new Participant($room, $attendee, null); diff --git a/lib/Collaboration/Collaborators/Listener.php b/lib/Collaboration/Collaborators/Listener.php index af065dae4..2f9603942 100644 --- a/lib/Collaboration/Collaborators/Listener.php +++ b/lib/Collaboration/Collaborators/Listener.php @@ -153,7 +153,7 @@ class Listener { $userId = $result['value']['shareWith']; try { - $participant = $this->room->getParticipant($userId, false); + $participant = $this->participantService->getParticipant($this->room, $userId, false); if ($participant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED) { // do list self-joined users so they can be added as permanent participants by moderators return true; diff --git a/lib/Collaboration/Collaborators/RoomPlugin.php b/lib/Collaboration/Collaborators/RoomPlugin.php index cc03429fe..1e92332a3 100644 --- a/lib/Collaboration/Collaborators/RoomPlugin.php +++ b/lib/Collaboration/Collaborators/RoomPlugin.php @@ -28,6 +28,7 @@ use OCA\Talk\Manager; use OCA\Talk\Model\Attendee; use OCA\Talk\Participant; use OCA\Talk\Room; +use OCA\Talk\Service\ParticipantService; use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\ISearchResult; use OCP\Collaboration\Collaborators\SearchResultType; @@ -35,13 +36,15 @@ use OCP\IUserSession; use OCP\Share\IShare; class RoomPlugin implements ISearchPlugin { - private Manager $manager; - - private IUserSession $userSession; + protected Manager $manager; + protected ParticipantService $participantService; + protected IUserSession $userSession; public function __construct(Manager $manager, + ParticipantService $participantService, IUserSession $userSession) { $this->manager = $manager; + $this->participantService = $participantService; $this->userSession = $userSession; } @@ -64,7 +67,7 @@ class RoomPlugin implements ISearchPlugin { continue; } - $participant = $room->getParticipant($userId, false); + $participant = $this->participantService->getParticipant($room, $userId, false); if (!$participant instanceof Participant || !($participant->getPermissions() & Attendee::PERMISSIONS_CHAT)) { // No chat permissions is like read-only continue; diff --git a/lib/Collaboration/Reference/TalkReferenceProvider.php b/lib/Collaboration/Reference/TalkReferenceProvider.php index f3b0b1ba2..88d448f74 100644 --- a/lib/Collaboration/Reference/TalkReferenceProvider.php +++ b/lib/Collaboration/Reference/TalkReferenceProvider.php @@ -33,6 +33,7 @@ use OCA\Talk\Manager; use OCA\Talk\Model\Attendee; use OCA\Talk\Participant; use OCA\Talk\Room; +use OCA\Talk\Service\ParticipantService; use OCP\Collaboration\Reference\IReference; use OCP\Collaboration\Reference\IReferenceProvider; use OCP\Collaboration\Reference\Reference; @@ -45,6 +46,7 @@ use OCP\IURLGenerator; class TalkReferenceProvider implements IReferenceProvider { protected IURLGenerator $urlGenerator; protected Manager $roomManager; + protected ParticipantService $participantService; protected ChatManager $chatManager; protected MessageParser $messageParser; protected IL10N $l; @@ -52,12 +54,14 @@ class TalkReferenceProvider implements IReferenceProvider { public function __construct(IURLGenerator $urlGenerator, Manager $manager, + ParticipantService $participantService, ChatManager $chatManager, MessageParser $messageParser, IL10N $l, ?string $userId) { $this->urlGenerator = $urlGenerator; $this->roomManager = $manager; + $this->participantService = $participantService; $this->chatManager = $chatManager; $this->messageParser = $messageParser; $this->l = $l; @@ -152,7 +156,7 @@ class TalkReferenceProvider implements IReferenceProvider { $room = $this->roomManager->getRoomForUserByToken($referenceMatch['token'], $this->userId); try { - $participant = $room->getParticipant($this->userId); + $participant = $this->participantService->getParticipant($room, $this->userId); } catch (ParticipantNotFoundException $e) { $participant = null; } diff --git a/lib/Collaboration/Resources/ConversationProvider.php b/lib/Collaboration/Resources/ConversationProvider.php index 591157287..1b9e2b40b 100644 --- a/lib/Collaboration/Resources/ConversationProvider.php +++ b/lib/Collaboration/Resources/ConversationProvider.php @@ -28,6 +28,7 @@ use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Participant; use OCA\Talk\Room; +use OCA\Talk\Service\ParticipantService; use OCP\Collaboration\Resources\IProvider; use OCP\Collaboration\Resources\IResource; use OCP\Collaboration\Resources\ResourceException; @@ -37,13 +38,16 @@ use OCP\IUserSession; class ConversationProvider implements IProvider { protected Manager $manager; + protected ParticipantService $participantService; protected IUserSession $userSession; protected IURLGenerator $urlGenerator; public function __construct(Manager $manager, + ParticipantService $participantService, IUserSession $userSession, IURLGenerator $urlGenerator) { $this->manager = $manager; + $this->participantService = $participantService; $this->userSession = $userSession; $this->urlGenerator = $urlGenerator; } @@ -89,7 +93,7 @@ class ConversationProvider implements IProvider { // Logged in users need to have a regular participant, // before they can do anything with the room. - $participant = $room->getParticipant($userId, false); + $participant = $this->participantService->getParticipant($room, $userId, false); return $participant->getAttendee()->getParticipantType() !== Participant::USER_SELF_JOINED; } catch (RoomNotFoundException $e) { throw new ResourceException('Conversation not found'); diff --git a/lib/Command/Room/TRoomCommand.php b/lib/Command/Room/TRoomCommand.php index 15991b832..7a34b5db2 100644 --- a/lib/Command/Room/TRoomCommand.php +++ b/lib/Command/Room/TRoomCommand.php @@ -201,7 +201,7 @@ trait TRoomCommand { */ protected function setRoomOwner(Room $room, string $userId): void { try { - $participant = $room->getParticipant($userId, false); + $participant = $this->participantService->getParticipant($room, $userId, false); } catch (ParticipantNotFoundException $e) { throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId)); } @@ -278,7 +278,7 @@ trait TRoomCommand { } try { - $room->getParticipant($user->getUID(), false); + $this->participantService->getParticipant($room, $user->getUID(), false); // nothing to do, user is a participant already continue; @@ -306,7 +306,7 @@ trait TRoomCommand { $users = []; foreach ($userIds as $userId) { try { - $room->getParticipant($userId, false); + $this->participantService->getParticipant($room, $userId, false); } catch (ParticipantNotFoundException $e) { throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId)); } @@ -333,7 +333,7 @@ trait TRoomCommand { } try { - $participant = $room->getParticipant($userId, false); + $participant = $this->participantService->getParticipant($room, $userId, false); } catch (ParticipantNotFoundException $e) { throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId)); } @@ -358,7 +358,7 @@ trait TRoomCommand { $participants = []; foreach ($userIds as $userId) { try { - $participant = $room->getParticipant($userId, false); + $participant = $this->participantService->getParticipant($room, $userId, false); } catch (ParticipantNotFoundException $e) { throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId)); } diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 4814952e4..6585efcba 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -32,6 +32,7 @@ use OCA\Talk\Config; use OCA\Talk\Manager; use OCA\Talk\Participant; use OCA\Talk\Room; +use OCA\Talk\Service\ParticipantService; use OCA\Talk\Service\RoomService; use OCA\Talk\TalkSession; use OCA\Talk\TInitialState; @@ -70,6 +71,7 @@ class PageController extends Controller { private IUserSession $userSession; private LoggerInterface $logger; private Manager $manager; + private ParticipantService $participantService; private RoomService $roomService; private IURLGenerator $url; private INotificationManager $notificationManager; @@ -86,6 +88,7 @@ class PageController extends Controller { ?string $UserId, LoggerInterface $logger, Manager $manager, + ParticipantService $participantService, RoomService $roomService, IURLGenerator $url, INotificationManager $notificationManager, @@ -104,6 +107,7 @@ class PageController extends Controller { $this->userId = $UserId; $this->logger = $logger; $this->manager = $manager; + $this->participantService = $participantService; $this->roomService = $roomService; $this->url = $url; $this->notificationManager = $notificationManager; @@ -220,7 +224,7 @@ class PageController extends Controller { if ($room instanceof Room && $room->hasPassword()) { // If the user joined themselves or is not found, they need the password. try { - $participant = $room->getParticipant($this->userId, false); + $participant = $this->participantService->getParticipant($room, $this->userId, false); $requirePassword = $participant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED; } catch (ParticipantNotFoundException $e) { $requirePassword = true; diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index 2fb836562..6a1f4d234 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -226,7 +226,7 @@ class RoomController extends AEnvironmentAwareController { $return = []; foreach ($rooms as $room) { try { - $return[] = $this->formatRoom($room, $room->getParticipant($this->userId), $statuses); + $return[] = $this->formatRoom($room, $this->participantService->getParticipant($room, $this->userId), $statuses); } catch (RoomNotFoundException $e) { } catch (ParticipantNotFoundException $e) { // for example in case the room was deleted concurrently, @@ -289,7 +289,7 @@ class RoomController extends AEnvironmentAwareController { $participant = null; try { - $participant = $room->getParticipant($this->userId, $sessionId); + $participant = $this->participantService->getParticipant($room, $this->userId, $sessionId); } catch (ParticipantNotFoundException $e) { try { $participant = $this->participantService->getParticipantBySession($room, $sessionId); @@ -695,7 +695,7 @@ class RoomController extends AEnvironmentAwareController { $room = $this->manager->getOne2OneRoom($currentUser->getUID(), $targetUser->getUID()); $this->participantService->ensureOneToOneRoomIsFilled($room); return new DataResponse( - $this->formatRoom($room, $room->getParticipant($currentUser->getUID(), false)), + $this->formatRoom($room, $this->participantService->getParticipant($room, $currentUser->getUID(), false)), Http::STATUS_OK ); } catch (RoomNotFoundException $e) { @@ -704,7 +704,7 @@ class RoomController extends AEnvironmentAwareController { try { $room = $this->roomService->createOneToOneConversation($currentUser, $targetUser); return new DataResponse( - $this->formatRoom($room, $room->getParticipant($currentUser->getUID(), false)), + $this->formatRoom($room, $this->participantService->getParticipant($room, $currentUser->getUID(), false)), Http::STATUS_CREATED ); } catch (InvalidArgumentException $e) { @@ -739,7 +739,7 @@ class RoomController extends AEnvironmentAwareController { $room = $this->roomService->createConversation(Room::TYPE_GROUP, $name, $currentUser); $this->participantService->addGroup($room, $targetGroup); - return |