From 9cc02f5b70f5001c2a5a5d14fbb6c5f4bbbc5ec8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 24 Feb 2021 10:20:31 +0100 Subject: [PATCH 1/3] Make the method loop over the sessions instead of the attendees Signed-off-by: Joas Schilling --- lib/Service/ParticipantService.php | 11 ++++++++--- lib/Signaling/Messages.php | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index 8459b71596f..6a20eb32383 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -603,22 +603,27 @@ public function getParticipantsForRoom(Room $room): array { /** * @param Room $room + * @param int $maxAge * @return Participant[] */ - public function getParticipantsWithSession(Room $room): array { + public function getParticipantsForAllSessions(Room $room, int $maxAge = 0): array { $query = $this->connection->getQueryBuilder(); $helper = new SelectHelper(); $helper->selectAttendeesTable($query); $helper->selectSessionsTable($query); - $query->from('talk_attendees', 'a') + $query->from('talk_sessions', 's') ->leftJoin( - 'a', 'talk_sessions', 's', + 's', 'talk_attendees', 'a', $query->expr()->eq('s.attendee_id', 'a.id') ) ->where($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT))) ->andWhere($query->expr()->isNotNull('s.id')); + if ($maxAge > 0) { + $query->andWhere($query->expr()->gt('s.last_ping', $query->createNamedParameter($maxAge, IQueryBuilder::PARAM_INT))); + } + return $this->getParticipantsFromQuery($query, $room); } diff --git a/lib/Signaling/Messages.php b/lib/Signaling/Messages.php index 8f695442c0c..418bf24bd2d 100644 --- a/lib/Signaling/Messages.php +++ b/lib/Signaling/Messages.php @@ -95,7 +95,7 @@ public function addMessageForAllParticipants(Room $room, string $message): void ] ); - $participants = $this->participantService->getParticipantsWithSession($room); + $participants = $this->participantService->getParticipantsForAllSessions($room); foreach ($participants as $participant) { $session = $participant->getSession(); if ($session instanceof Session) { From a347cf23752aec0f08b95ccdbdee5a44b9f9a0f0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 24 Feb 2021 10:21:11 +0100 Subject: [PATCH 2/3] Pick all sessions instead of attendees when returning participants on signaling Signed-off-by: Joas Schilling --- lib/Controller/SignalingController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Controller/SignalingController.php b/lib/Controller/SignalingController.php index de5518e0f79..bcad873c0f7 100644 --- a/lib/Controller/SignalingController.php +++ b/lib/Controller/SignalingController.php @@ -382,11 +382,11 @@ protected function getUsersInRoom(Room $room, int $pingTimestamp): array { $timestamp = min($this->timeFactory->getTime() - (self::PULL_MESSAGES_TIMEOUT + 10), $pingTimestamp); // "- 1" is needed because only the participants whose last ping is // greater than the given timestamp are returned. - $participants = $this->participantService->getParticipantsForRoom($room); + $participants = $this->participantService->getParticipantsForAllSessions($room, $timestamp - 1); foreach ($participants as $participant) { $session = $participant->getSession(); if (!$session instanceof Session) { - // User is not active + // This is just to make Psalm happy, since we select by session it's always with one. continue; } From adc5996e8752c1ddc2fed6cef77777e4aaa5b4f0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 24 Feb 2021 10:25:36 +0100 Subject: [PATCH 3/3] First check for session because we don't do something otherwise anyway Signed-off-by: Joas Schilling --- lib/Signaling/BackendNotifier.php | 32 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/Signaling/BackendNotifier.php b/lib/Signaling/BackendNotifier.php index 1d5be017f7d..a1ec485322a 100644 --- a/lib/Signaling/BackendNotifier.php +++ b/lib/Signaling/BackendNotifier.php @@ -311,8 +311,13 @@ public function roomInCallChanged(Room $room, int $flags, array $sessionIds): vo $changed = []; $users = []; - $participants = $this->participantService->getParticipantsForRoom($room); + $participants = $this->participantService->getParticipantsForAllSessions($room); foreach ($participants as $participant) { + $session = $participant->getSession(); + if (!$session instanceof Session) { + continue; + } + $attendee = $participant->getAttendee(); if ($attendee->getActorType() !== Attendee::ACTOR_USERS && $attendee->getActorType() !== Attendee::ACTOR_GUESTS) { @@ -320,29 +325,22 @@ public function roomInCallChanged(Room $room, int $flags, array $sessionIds): vo } $data = [ - 'inCall' => Participant::FLAG_DISCONNECTED, - 'lastPing' => 0, - 'sessionId' => '0', + 'inCall' => $session->getInCall(), + 'lastPing' => $session->getLastPing(), + 'sessionId' => $session->getSessionId(), + 'nextcloudSessionId' => $session->getSessionId(), 'participantType' => $attendee->getParticipantType(), ]; if ($attendee->getActorType() === Attendee::ACTOR_USERS) { $data['userId'] = $attendee->getActorId(); } - $session = $participant->getSession(); - if ($session instanceof Session) { - $data['inCall'] = $session->getInCall(); - $data['lastPing'] = $session->getLastPing(); - $data['sessionId'] = $session->getSessionId(); - $data['nextcloudSessionId'] = $session->getSessionId(); - - if ($session->getInCall() !== Participant::FLAG_DISCONNECTED) { - $users[] = $data; - } + if ($session->getInCall() !== Participant::FLAG_DISCONNECTED) { + $users[] = $data; + } - if (\in_array($session->getSessionId(), $sessionIds, true)) { - $changed[] = $data; - } + if (\in_array($session->getSessionId(), $sessionIds, true)) { + $changed[] = $data; } }