Skip to content

Commit

Permalink
Don't load the session by default on getParticipantsForRoom
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 5ed9b8e commit 52d3c74
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
11 changes: 3 additions & 8 deletions lib/Command/Room/TRoomCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,9 @@ protected function completeParticipantValues(CompletionContext $context): array
return [];
}

$users = [];
$participants = $this->participantService->getParticipantsForRoom($room);
foreach ($participants as $participant) {
if ($participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS
&& stripos($participant->getAttendee()->getActorId(), $context->getCurrentWord()) !== false) {
$users[] = $participant->getAttendee()->getActorId();
}
}
$users = array_filter($this->participantService->getParticipantUserIds($room), static function ($userId) use ($context) {
return stripos($userId, $context->getCurrentWord()) !== false;
});

return $users;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ protected function formatRoomV1(Room $room, ?Participant $currentParticipant): a
$numActiveGuests = 0;
$cleanGuests = false;
$participantList = [];
$participants = $this->participantService->getParticipantsForRoom($room);
$participants = $this->participantService->getParticipantsForRoom($room, true); // FIXME NEEDS the session but can potentially kill APIv1?
uasort($participants, function (Participant $participant1, Participant $participant2) {
$s1 = $participant1->getSession() ? $participant1->getSession()->getLastPing() : 0;
$s2 = $participant2->getSession() ? $participant2->getSession()->getLastPing() : 0;
Expand Down Expand Up @@ -1110,7 +1110,7 @@ public function getParticipants(bool $includeStatus = false): DataResponse {
}

$maxPingAge = $this->timeFactory->getTime() - 100;
$participants = $this->participantService->getParticipantsForRoom($this->room);
$participants = $this->participantService->getParticipantsForRoom($this->room, true); // FIXME should return some what session info?
$results = $headers = $statuses = [];

if ($this->userId !== null
Expand Down
14 changes: 9 additions & 5 deletions lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,21 +583,25 @@ public function getLastCommonReadChatMessageForMultipleRooms(array $roomIds): ar

/**
* @param Room $room
* @param bool $loadSession Loads a random session if possible for the users
* @return Participant[]
*/
public function getParticipantsForRoom(Room $room): array {
public function getParticipantsForRoom(Room $room, bool $loadSession = false): array {
// FIXME Need to make sure a user is skipped when at least one session is in the call
$query = $this->connection->getQueryBuilder();

$helper = new SelectHelper();
$helper->selectAttendeesTable($query);
$helper->selectSessionsTable($query);
$query->from('talk_attendees', 'a')
->leftJoin(
->where($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)));

if ($loadSession) {
$helper->selectSessionsTable($query);
$query->leftJoin(
'a', 'talk_sessions', 's',
$query->expr()->eq('s.attendee_id', 'a.id')
)
->where($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)));
);
}

return $this->getParticipantsFromQuery($query, $room);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Signaling/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected static function registerInternalSignaling(IEventDispatcher $dispatcher
/** @var ParticipantService $participantService */
$participantService = \OC::$server->query(ParticipantService::class);

$participants = $participantService->getParticipantsForRoom($room);
$participants = $participantService->getParticipantsForAllSessions($room);
foreach ($participants as $participant) {
$session = $participant->getSession();
if ($session instanceof Session) {
Expand Down

0 comments on commit 52d3c74

Please sign in to comment.