Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base queries on sessions where it makes sense #5258

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Controller/SignalingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 8 additions & 3 deletions lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
32 changes: 15 additions & 17 deletions lib/Signaling/BackendNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,38 +311,36 @@ 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) {
continue;
}

$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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Signaling/Messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down