Skip to content

Commit 8b611c9

Browse files
committed
Try to load a room by accessToken
Signed-off-by: Joas Schilling <[email protected]>
1 parent 2571388 commit 8b611c9

File tree

3 files changed

+71
-7
lines changed

3 files changed

+71
-7
lines changed

Diff for: lib/Controller/RoomController.php

+19-7
Original file line numberDiff line numberDiff line change
@@ -325,18 +325,30 @@ public function getSingleRoom(string $token): DataResponse {
325325
$includeLastMessage = !$isSIPBridgeRequest;
326326

327327
try {
328-
$sessionId = $this->session->getSessionForRoom($token);
329-
$room = $this->manager->getRoomForUserByToken($token, $this->userId, $sessionId, $includeLastMessage, $isSIPBridgeRequest);
330-
331328
$participant = null;
332-
try {
333-
$participant = $this->participantService->getParticipant($room, $this->userId, $sessionId);
334-
} catch (ParticipantNotFoundException $e) {
329+
330+
$isTalkFederation = $this->request->getHeader('X-Nextcloud-Federation');
331+
332+
if (!$isTalkFederation) {
333+
$sessionId = $this->session->getSessionForRoom($token);
334+
$room = $this->manager->getRoomForUserByToken($token, $this->userId, $sessionId, $includeLastMessage, $isSIPBridgeRequest);
335+
335336
try {
336-
$participant = $this->participantService->getParticipantBySession($room, $sessionId);
337+
$participant = $this->participantService->getParticipant($room, $this->userId, $sessionId);
337338
} catch (ParticipantNotFoundException $e) {
339+
try {
340+
$participant = $this->participantService->getParticipantBySession($room, $sessionId);
341+
} catch (ParticipantNotFoundException $e) {
342+
}
338343
}
344+
} else {
345+
$cloudId = urldecode($this->request->server['PHP_AUTH_USER']);
346+
$accessToken = $this->request->server['PHP_AUTH_PW'];
347+
$room = $this->manager->getRoomByRemoteAccess($token, Attendee::ACTOR_FEDERATED_USERS, $cloudId, $accessToken);
348+
// FIXME continue on this
349+
$participant = $this->participantService->getParticipantByActor($room, Attendee::ACTOR_FEDERATED_USERS, $cloudId);
339350
}
351+
340352
$statuses = [];
341353
if ($this->userId !== null
342354
&& $this->appManager->isEnabledForUser('user_status')) {

Diff for: lib/Manager.php

+51
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,57 @@ public function getRoomByActor(string $token, string $actorType, string $actorId
732732
return $room;
733733
}
734734

735+
/**
736+
* @param string $token
737+
* @param string $actorType
738+
* @param string $actorId
739+
* @param string $remoteAccess
740+
* @return Room
741+
* @throws RoomNotFoundException
742+
*/
743+
public function getRoomByRemoteAccess(string $token, string $actorType, string $actorId, string $remoteAccess): Room {
744+
$query = $this->db->getQueryBuilder();
745+
$helper = new SelectHelper();
746+
$helper->selectRoomsTable($query);
747+
$helper->selectAttendeesTable($query);
748+
$query->from('talk_rooms', 'r')
749+
->leftJoin('r', 'talk_attendees', 'a', $query->expr()->andX(
750+
$query->expr()->eq('a.actor_type', $query->createNamedParameter($actorType)),
751+
$query->expr()->eq('a.actor_id', $query->createNamedParameter($actorId)),
752+
$query->expr()->eq('a.access_token', $query->createNamedParameter($remoteAccess)),
753+
$query->expr()->eq('a.room_id', 'r.id')
754+
))
755+
->where($query->expr()->eq('r.token', $query->createNamedParameter($token)));
756+
757+
// if ($sessionId !== null) {
758+
// $helper->selectSessionsTable($query);
759+
// $query->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
760+
// $query->expr()->eq('s.session_id', $query->createNamedParameter($sessionId)),
761+
// $query->expr()->eq('a.id', 's.attendee_id')
762+
// ));
763+
// }
764+
765+
$result = $query->executeQuery();
766+
$row = $result->fetch();
767+
$result->closeCursor();
768+
769+
if ($row === false) {
770+
throw new RoomNotFoundException();
771+
}
772+
773+
if ($row['token'] === null) {
774+
// FIXME Temporary solution for the Talk6 release
775+
throw new RoomNotFoundException();
776+
}
777+
778+
$room = $this->createRoomObject($row);
779+
if ($actorType === Attendee::ACTOR_FEDERATED_USERS && isset($row['actor_id'])) {
780+
$room->setParticipant($row['actor_id'], $this->createParticipantObject($room, $row));
781+
}
782+
783+
return $room;
784+
}
785+
735786
/**
736787
* @param string $token
737788
* @param string|null $preloadUserId Load this participant's information if possible

Diff for: lib/Room.php

+1
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ public function isFederatedRemoteRoom(): bool {
467467
}
468468

469469
public function setParticipant(?string $userId, Participant $participant): void {
470+
// FIXME Also used with cloudId, need actorType checking?
470471
$this->currentUser = $userId;
471472
$this->participant = $participant;
472473
}

0 commit comments

Comments
 (0)