Skip to content

Commit

Permalink
Fix session selection in signaling code
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Feb 18, 2021
1 parent a3ae8bc commit 637d752
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 2 additions & 3 deletions lib/Controller/SignalingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +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.
// FIXME needs to select session and left join attendees instead!
$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;
}

Expand Down
7 changes: 6 additions & 1 deletion lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,10 @@ public function getParticipantsForRoom(Room $room): array {

/**
* @param Room $room
* @param int $maxAge
* @return Participant[]
*/
public function getParticipantsForAllSessions(Room $room): array {
public function getParticipantsForAllSessions(Room $room, int $maxAge = 0): array {
$query = $this->connection->getQueryBuilder();

$helper = new SelectHelper();
Expand All @@ -620,6 +621,10 @@ public function getParticipantsForAllSessions(Room $room): array {
->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);
}

Expand Down
6 changes: 2 additions & 4 deletions lib/Signaling/BackendNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ public function participantsModified(Room $room, array $sessionIds): void {
$this->logger->info('Room participants modified: ' . $room->getToken() . ' ' . print_r($sessionIds, true));
$changed = [];
$users = [];
// FIXME needs to select session and left join attendees instead!
$participants = $this->participantService->getParticipantsForRoom($room);
$participants = $this->participantService->getParticipantsForAllSessions($room);
foreach ($participants as $participant) {
$attendee = $participant->getAttendee();
if ($attendee->getActorType() !== Attendee::ACTOR_USERS
Expand Down Expand Up @@ -312,8 +311,7 @@ public function roomInCallChanged(Room $room, int $flags, array $sessionIds): vo
$changed = [];
$users = [];

// FIXME needs to select session and left join attendees instead!
$participants = $this->participantService->getParticipantsForRoom($room);
$participants = $this->participantService->getParticipantsForAllSessions($room);
foreach ($participants as $participant) {
$attendee = $participant->getAttendee();
if ($attendee->getActorType() !== Attendee::ACTOR_USERS
Expand Down

0 comments on commit 637d752

Please sign in to comment.