diff options
author | Joas Schilling <coding@schilljs.com> | 2020-09-22 12:07:37 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-09-22 14:08:56 +0300 |
commit | 9a599f12ce266fbac430be412c4e1bdb1a4cb87e (patch) | |
tree | 336d5c578a53209e5d8be35520f397fe0aa31827 /lib/Manager.php | |
parent | 64c66e7ba18ded8129f462496de6add5e91284a3 (diff) |
Allow to preload a user when getting the room by token
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Manager.php')
-rw-r--r-- | lib/Manager.php | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/Manager.php b/lib/Manager.php index 944d1c333..d372f8fd8 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -446,14 +446,25 @@ class Manager { /** * @param string $token + * @param string|null $preloadParticipant Load this participants information if possible * @return Room * @throws RoomNotFoundException */ - public function getRoomByToken(string $token): Room { + public function getRoomByToken(string $token, ?string $preloadParticipant = null): Room { + $preloadParticipant = $preloadParticipant === '' ? null : $preloadParticipant; + $query = $this->db->getQueryBuilder(); - $query->select('*') - ->from('talk_rooms') - ->where($query->expr()->eq('token', $query->createNamedParameter($token))); + $query->select('r.*') + ->from('talk_rooms', 'r') + ->where($query->expr()->eq('r.token', $query->createNamedParameter($token))); + + if ($preloadParticipant !== null) { + $query->addSelect('p.*') + ->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX( + $query->expr()->eq('p.user_id', $query->createNamedParameter($preloadParticipant)), + $query->expr()->eq('p.room_id', 'r.id') + )); + } $result = $query->execute(); $row = $result->fetch(); @@ -468,7 +479,12 @@ class Manager { throw new RoomNotFoundException(); } - return $this->createRoomObject($row); + $room = $this->createRoomObject($row); + if ($preloadParticipant !== null && isset($row['user_id'])) { + $room->setParticipant($row['user_id'], $this->createParticipantObject($room, $row)); + } + + return $room; } /** |