Make the method loop over the sessions instead of the attendees

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-02-24 10:20:31 +01:00
parent 62aae8ad96
commit 9cc02f5b70
No known key found for this signature in database
GPG key ID: 7076EA9751AACDDA
2 changed files with 9 additions and 4 deletions

View file

@ -603,22 +603,27 @@ class ParticipantService {
/**
* @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);
}

View file

@ -95,7 +95,7 @@ class Messages {
]
);
$participants = $this->participantService->getParticipantsWithSession($room);
$participants = $this->participantService->getParticipantsForAllSessions($room);
foreach ($participants as $participant) {
$session = $participant->getSession();
if ($session instanceof Session) {