diff options
author | Joas Schilling <coding@schilljs.com> | 2021-03-05 14:37:12 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-03-08 13:56:21 +0300 |
commit | 928e047de2dca944ba2d1747bd1e3a83e57e746c (patch) | |
tree | b5d23aa1d49e78f51a983836448223643d98c4b7 /lib/Signaling | |
parent | 1dd9297864a925f36db88bd3bfd59af41a1e2f3d (diff) |
Handle all getParticipants with multi sessions
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Signaling')
-rw-r--r-- | lib/Signaling/Listener.php | 70 |
1 files changed, 43 insertions, 27 deletions
diff --git a/lib/Signaling/Listener.php b/lib/Signaling/Listener.php index b8567e157..6c4056cdb 100644 --- a/lib/Signaling/Listener.php +++ b/lib/Signaling/Listener.php @@ -37,6 +37,7 @@ use OCA\Talk\GuestManager; use OCA\Talk\Model\Session; use OCA\Talk\Room; use OCA\Talk\Service\ParticipantService; +use OCA\Talk\Service\SessionService; use OCP\EventDispatcher\IEventDispatcher; class Listener { @@ -77,19 +78,10 @@ class Listener { /** @var Messages $messages */ $messages = \OC::$server->query(Messages::class); $messages->addMessageForAllParticipants($room, 'refresh-participant-list'); - - // When "addMessageForAllParticipants" is called the participant is - // no longer in the room, so the message needs to be explicitly - // added for the participant. - $participant = $event->getParticipant(); - $session = $participant->getSession(); - if ($session instanceof Session) { - $messages->addMessage($session->getSessionId(), $session->getSessionId(), 'refresh-participant-list'); - } }; - $dispatcher->addListener(Room::EVENT_AFTER_USER_REMOVE, $listener); - $dispatcher->addListener(Room::EVENT_AFTER_PARTICIPANT_REMOVE, $listener); - $dispatcher->addListener(Room::EVENT_AFTER_ROOM_DISCONNECT, $listener); + $dispatcher->addListener(Room::EVENT_BEFORE_USER_REMOVE, $listener); + $dispatcher->addListener(Room::EVENT_BEFORE_PARTICIPANT_REMOVE, $listener); + $dispatcher->addListener(Room::EVENT_BEFORE_ROOM_DISCONNECT, $listener); $listener = static function (RoomEvent $event) { $room = $event->getRoom(); @@ -149,11 +141,14 @@ class Listener { // If the participant is not active in the room the "participants" // request will be sent anyway, although with an empty "changed" // property. - $participant = $event->getParticipant(); - $session = $participant->getSession(); - if ($session instanceof Session) { + + /** @var SessionService $sessionService */ + $sessionService = \OC::$server->query(SessionService::class); + $sessions = $sessionService->getAllSessionsForAttendee($event->getParticipant()->getAttendee()); + foreach ($sessions as $session) { $sessionIds[] = $session->getSessionId(); } + $notifier->participantsModified($event->getRoom(), $sessionIds); }); $dispatcher->addListener(Room::EVENT_BEFORE_ROOM_DELETE, static function (RoomEvent $event) { @@ -187,10 +182,17 @@ class Listener { /** @var BackendNotifier $notifier */ $notifier = \OC::$server->query(BackendNotifier::class); - $participant = $event->getParticipant(); - $session = $participant->getSession(); - if ($session instanceof Session) { - $notifier->roomSessionsRemoved($event->getRoom(), [$session->getSessionId()]); + $sessionIds = []; + + /** @var SessionService $sessionService */ + $sessionService = \OC::$server->query(SessionService::class); + $sessions = $sessionService->getAllSessionsForAttendee($event->getParticipant()->getAttendee()); + foreach ($sessions as $session) { + $sessionIds[] = $session->getSessionId(); + } + + if (!empty($sessionIds)) { + $notifier->roomSessionsRemoved($event->getRoom(), $sessionIds); } }); @@ -202,13 +204,20 @@ class Listener { /** @var BackendNotifier $notifier */ $notifier = \OC::$server->query(BackendNotifier::class); - $participant = $event->getParticipant(); - $session = $participant->getSession(); - if ($session instanceof Session) { + $sessionIds = []; + + /** @var SessionService $sessionService */ + $sessionService = \OC::$server->query(SessionService::class); + $sessions = $sessionService->getAllSessionsForAttendee($event->getParticipant()->getAttendee()); + foreach ($sessions as $session) { + $sessionIds[] = $session->getSessionId(); + } + + if (!empty($sessionIds)) { $notifier->roomInCallChanged( $event->getRoom(), $event->getNewValue(), - [$session->getSessionId()] + $sessionIds ); } }; @@ -236,10 +245,17 @@ class Listener { /** @var BackendNotifier $notifier */ $notifier = \OC::$server->query(BackendNotifier::class); - $participant = $event->getParticipant(); - $session = $participant->getSession(); - if ($session instanceof Session) { - $notifier->participantsModified($event->getRoom(), [$session->getSessionId()]); + $sessionIds = []; + + /** @var SessionService $sessionService */ + $sessionService = \OC::$server->query(SessionService::class); + $sessions = $sessionService->getAllSessionsForAttendee($event->getParticipant()->getAttendee()); + foreach ($sessions as $session) { + $sessionIds[] = $session->getSessionId(); + } + + if (!empty($sessionIds)) { + $notifier->participantsModified($event->getRoom(), $sessionIds); } }); $dispatcher->addListener(ChatManager::EVENT_AFTER_MESSAGE_SEND , static function (ChatParticipantEvent $event) { |