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; } 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/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; } } 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) {