Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6d9c838
Replace the former unique attendee key with a normal index
nickvergessen Feb 17, 2021
4031c18
Prepare selecting the correct session in case there are multiple
nickvergessen Feb 17, 2021
1caca56
Don't load session on getRoomsForUser when not needed
nickvergessen Feb 18, 2021
0e20ca5
Don't load the session by default on getParticipantsForRoom
nickvergessen Feb 18, 2021
c97f55e
Group multiple sessions of the same attendee
nickvergessen Feb 18, 2021
6ad31df
Fix selecting the session when there could be multiple
nickvergessen Feb 18, 2021
783fb00
Don't clear previous sessions when joining
nickvergessen Feb 25, 2021
723d47f
Fix session selection in signaling code
nickvergessen Feb 18, 2021
a545cff
Only load sessions on the room list for this PHP session
nickvergessen Feb 25, 2021
6184127
Make the UI handle the call state on it's interactions instead of the…
nickvergessen Feb 25, 2021
6902e57
Show a "Connecting …" screen until we finished joining
nickvergessen Feb 25, 2021
5bff56f
Move listed rooms to API v4
nickvergessen Mar 3, 2021
79d52e6
Move lobby and SIP to v4
nickvergessen Mar 3, 2021
7673f4f
Move conversation creation to v4
nickvergessen Mar 3, 2021
1b4b1c6
Move get rooms to API v4
nickvergessen Mar 3, 2021
174789f
Check users on correct endpoint
nickvergessen Mar 4, 2021
8eae2e8
Move get participants to API v4
nickvergessen Mar 4, 2021
5ba0871
Add API version to files/share integration tests
nickvergessen Mar 4, 2021
e331d29
Make joining a room API v4
nickvergessen Mar 4, 2021
6c0246b
Make leaving a room API v4
nickvergessen Mar 4, 2021
3a680dc
Move removing paricipants to v4
nickvergessen Mar 4, 2021
db7c09e
Move deleting and getting a room to v4
nickvergessen Mar 4, 2021
0aedba5
Move room modifications to API v4
nickvergessen Mar 4, 2021
4aee4e9
Move other participant handling to API v4
nickvergessen Mar 4, 2021
7eaafce
Move other room APIs to v4
nickvergessen Mar 4, 2021
3fed42b
Move call API to v4
nickvergessen Mar 4, 2021
64a28fa
Chat, Settings and Guests are v1 api only atm
nickvergessen Mar 4, 2021
7b1a8ee
Document return types as well
nickvergessen Mar 4, 2021
ba52825
Statuses are integers now
nickvergessen Mar 4, 2021
8136513
We have the full room data already
nickvergessen Mar 4, 2021
5ed91b8
Add conversation-v4 capability
nickvergessen Mar 4, 2021
a3cf504
Move to APIv4
nickvergessen Mar 4, 2021
84fa567
Remove old API version handlings
nickvergessen Mar 4, 2021
5f29407
Check the participants on the correct endpoint
nickvergessen Mar 4, 2021
1dd9297
Fix integration tests by saving the attendee id or loading it
nickvergessen Mar 5, 2021
928e047
Handle all getParticipants with multi sessions
nickvergessen Mar 5, 2021
baa1547
Trespassing only with session
nickvergessen Mar 5, 2021
1bb090a
No duplicate session warning per se
nickvergessen Mar 8, 2021
2183ffc
Leaving with a session as guest is now also not quiting anymore
nickvergessen Mar 8, 2021
12a48be
Fix HPB missing event when a session is terminated only
nickvergessen Mar 8, 2021
1e9c21e
Fix removing yourself and promoting a stranger
nickvergessen Mar 9, 2021
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
Prev Previous commit
Next Next commit
Prepare selecting the correct session in case there are multiple
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Mar 8, 2021
commit 4031c182dfde9b2d70f4a1f37b39a39b763fe6aa
2 changes: 1 addition & 1 deletion lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function index(string $token = '', string $callUser = '', string $passwor
if ($room instanceof Room && $room->hasPassword()) {
// If the user joined themselves or is not found, they need the password.
try {
$participant = $room->getParticipant($this->userId);
$participant = $room->getParticipant($this->userId, false);
$requirePassword = $participant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED;
} catch (ParticipantNotFoundException $e) {
$requirePassword = true;
Expand Down
15 changes: 8 additions & 7 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,15 @@ public function getSingleRoom(string $token): DataResponse {
$includeLastMessage = !$isSIPBridgeRequest;

try {
$room = $this->manager->getRoomForUserByToken($token, $this->userId, $includeLastMessage, $isSIPBridgeRequest);
$sessionId = $this->session->getSessionForRoom($token);
$room = $this->manager->getRoomForUserByToken($token, $this->userId, $sessionId, $includeLastMessage, $isSIPBridgeRequest);

$participant = null;
try {
$participant = $room->getParticipant($this->userId);
} catch (ParticipantNotFoundException $e) {
try {
$participant = $room->getParticipantBySession($this->session->getSessionForRoom($token));
$participant = $room->getParticipantBySession($sessionId);
} catch (ParticipantNotFoundException $e) {
}
}
Expand Down Expand Up @@ -1568,8 +1569,9 @@ public function setPassword(string $password): DataResponse {
* @return DataResponse
*/
public function joinRoom(string $token, string $password = '', bool $force = true): DataResponse {
$sessionId = $this->session->getSessionForRoom($token);
try {
$room = $this->manager->getRoomForUserByToken($token, $this->userId);
$room = $this->manager->getRoomForUserByToken($token, $this->userId, $sessionId);
} catch (RoomNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
Expand All @@ -1585,17 +1587,16 @@ public function joinRoom(string $token, string $password = '', bool $force = tru
} catch (ParticipantNotFoundException $e) {
}
} else {
$sessionForToken = $this->session->getSessionForRoom($token);
try {
$previousParticipant = $room->getParticipantBySession($sessionForToken);
$previousParticipant = $room->getParticipantBySession($sessionId);
$previousSession = $previousParticipant->getSession();
} catch (ParticipantNotFoundException $e) {
}
}

if ($previousSession instanceof Session && $previousSession->getSessionId() !== '0') {
if ($force === false && $previousSession->getInCall() !== Participant::FLAG_DISCONNECTED) {
// Previous session was active in the call, show a warning
// Previous session is/was active in the call, show a warning
return new DataResponse([
'sessionId' => $previousSession->getSessionId(),
'inCall' => $previousSession->getInCall(),
Expand Down Expand Up @@ -1672,7 +1673,7 @@ public function leaveRoom(string $token): DataResponse {
$this->session->removeSessionForRoom($token);

try {
$room = $this->manager->getRoomForUserByToken($token, $this->userId);
$room = $this->manager->getRoomForUserByToken($token, $this->userId, $sessionId);
$participant = $room->getParticipantBySession($sessionId);
$this->participantService->leaveRoomAsSession($room, $participant);
} catch (RoomNotFoundException $e) {
Expand Down
35 changes: 19 additions & 16 deletions lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public function searchRoomsByToken(string $searchToken = '', int $limit = null,
* @return Room[]
*/
public function getRoomsForUser(string $userId, bool $includeLastMessage = false): array {
// FIXME hand in a list of sessions or how do we want to do it here?
$query = $this->db->getQueryBuilder();
$helper = new SelectHelper();
$helper->selectRoomsTable($query);
Expand Down Expand Up @@ -391,9 +392,6 @@ public function getListedRoomsForUser(string $userId, string $term = ''): array
$query->expr()->eq('a.actor_type', $query->createNamedParameter(Attendee::ACTOR_USERS)),
$query->expr()->eq('a.room_id', 'r.id')
))
->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
$query->expr()->eq('a.id', 's.attendee_id')
))
->where($query->expr()->isNull('a.id'))
->andWhere($query->expr()->in('r.type', $query->createNamedParameter($allowedRoomTypes, IQueryBuilder::PARAM_INT_ARRAY)))
->andWhere($query->expr()->in('r.listable', $query->createNamedParameter($allowedListedTypes, IQueryBuilder::PARAM_INT_ARRAY)));
Expand Down Expand Up @@ -435,15 +433,11 @@ public function getRoomForUser(int $roomId, ?string $userId): Room {
if ($userId !== null) {
// Non guest user
$helper->selectAttendeesTable($query);
$helper->selectSessionsTable($query);
$query->leftJoin('r', 'talk_attendees', 'a', $query->expr()->andX(
$query->expr()->eq('a.actor_id', $query->createNamedParameter($userId)),
$query->expr()->eq('a.actor_type', $query->createNamedParameter(Attendee::ACTOR_USERS)),
$query->expr()->eq('a.room_id', 'r.id')
))
->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
$query->expr()->eq('a.id', 's.attendee_id')
))
->andWhere($query->expr()->isNotNull('a.id'));
}

Expand Down Expand Up @@ -483,12 +477,13 @@ public function getRoomForUser(int $roomId, ?string $userId): Room {
*
* @param string $token
* @param string|null $userId
* @param string|null $sessionId
* @param bool $includeLastMessage
* @param bool $isSIPBridgeRequest
* @return Room
* @throws RoomNotFoundException
*/
public function getRoomForUserByToken(string $token, ?string $userId, bool $includeLastMessage = false, bool $isSIPBridgeRequest = false): Room {
public function getRoomForUserByToken(string $token, ?string $userId, ?string $sessionId = null, bool $includeLastMessage = false, bool $isSIPBridgeRequest = false): Room {
$query = $this->db->getQueryBuilder();
$helper = new SelectHelper();
$helper->selectRoomsTable($query);
Expand All @@ -499,15 +494,18 @@ public function getRoomForUserByToken(string $token, ?string $userId, bool $incl
if ($userId !== null) {
// Non guest user
$helper->selectAttendeesTable($query);
$helper->selectSessionsTable($query);
$query->leftJoin('r', 'talk_attendees', 'a', $query->expr()->andX(
$query->expr()->eq('a.actor_id', $query->createNamedParameter($userId)),
$query->expr()->eq('a.actor_type', $query->createNamedParameter(Attendee::ACTOR_USERS)),
$query->expr()->eq('a.room_id', 'r.id')
))
->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
));
if ($sessionId !== null) {
$helper->selectSessionsTable($query);
$query->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
$query->expr()->eq('s.session_id', $query->createNamedParameter($sessionId)),
$query->expr()->eq('a.id', 's.attendee_id')
));
}
}

if ($includeLastMessage) {
Expand Down Expand Up @@ -584,26 +582,31 @@ public function getRoomById(int $roomId): Room {
* @param string $token
* @param string $actorType
* @param string $actorId
* @param string|null $sessionId
* @return Room
* @throws RoomNotFoundException
*/
public function getRoomByActor(string $token, string $actorType, string $actorId): Room {
public function getRoomByActor(string $token, string $actorType, string $actorId, ?string $sessionId = null): Room {
$query = $this->db->getQueryBuilder();
$helper = new SelectHelper();
$helper->selectRoomsTable($query);
$helper->selectAttendeesTable($query);
$helper->selectSessionsTable($query);
$query->from('talk_rooms', 'r')
->leftJoin('r', 'talk_attendees', 'a', $query->expr()->andX(
$query->expr()->eq('a.actor_type', $query->createNamedParameter($actorType)),
$query->expr()->eq('a.actor_id', $query->createNamedParameter($actorId)),
$query->expr()->eq('a.room_id', 'r.id')
))
->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
$query->expr()->eq('a.id', 's.attendee_id')
))
->where($query->expr()->eq('r.token', $query->createNamedParameter($token)));

if ($sessionId !== null) {
$helper->selectSessionsTable($query);
$query->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
$query->expr()->eq('s.session_id', $query->createNamedParameter($sessionId)),
$query->expr()->eq('a.id', 's.attendee_id')
));
}

$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
Expand Down
10 changes: 6 additions & 4 deletions lib/Middleware/InjectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function beforeController($controller, $methodName): void {
*/
protected function getRoom(AEnvironmentAwareController $controller): void {
$token = $this->request->getParam('token');
$room = $this->manager->getRoomByToken($token, $this->userId);
$room = $this->manager->getRoomByToken($token);
$controller->setRoom($room);
}

Expand All @@ -130,7 +130,8 @@ protected function getRoom(AEnvironmentAwareController $controller): void {
*/
protected function getLoggedIn(AEnvironmentAwareController $controller, bool $moderatorRequired): void {
$token = $this->request->getParam('token');
$room = $this->manager->getRoomForUserByToken($token, $this->userId);
$sessionId = $this->talkSession->getSessionForRoom($token);
$room = $this->manager->getRoomForUserByToken($token, $this->userId, $sessionId);
$controller->setRoom($room);

$participant = $room->getParticipant($this->userId);
Expand All @@ -149,13 +150,14 @@ protected function getLoggedIn(AEnvironmentAwareController $controller, bool $mo
*/
protected function getLoggedInOrGuest(AEnvironmentAwareController $controller, bool $moderatorRequired): void {
$token = $this->request->getParam('token');
$room = $this->manager->getRoomForUserByToken($token, $this->userId);
$sessionId = $this->talkSession->getSessionForRoom($token);
$room = $this->manager->getRoomForUserByToken($token, $this->userId, $sessionId);
$controller->setRoom($room);

$sessionId = $this->talkSession->getSessionForRoom($token);
if ($sessionId !== null) {
$participant = $room->getParticipantBySession($sessionId);
} else {
// FIXME is this still needed? Maybe for users joining public links?
$participant = $room->getParticipant($this->userId);
}
$controller->setParticipant($participant);
Expand Down
69 changes: 57 additions & 12 deletions lib/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\SelectHelper;
use OCA\Talk\Model\Session;
use OCA\Talk\Service\ParticipantService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Comments\IComment;
Expand Down Expand Up @@ -402,28 +403,46 @@ public function getPropertiesForSignaling(string $userId, bool $roomModified = t

/**
* @param string|null $userId
* @param string|null|false $sessionId Set to false if you don't want to load a session (and save resources),
* string to try loading a specific session
* null to try loading "any"
* @return Participant
* @throws ParticipantNotFoundException When the user is not a participant
*/
public function getParticipant(?string $userId): Participant {
public function getParticipant(?string $userId, $sessionId = null): Participant {
if (!is_string($userId) || $userId === '') {
throw new ParticipantNotFoundException('Not a user');
}

if ($this->currentUser === $userId && $this->participant instanceof Participant) {
return $this->participant;
if (!$sessionId
|| ($this->participant->getSession() instanceof Session
&& $this->participant->getSession()->getSessionId() === $sessionId)) {
return $this->participant;
}
}

$query = $this->db->getQueryBuilder();
$helper = new SelectHelper();
$helper->selectAttendeesTable($query);
$helper->selectSessionsTable($query);
$query->from('talk_attendees', 'a')
->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'))
->where($query->expr()->eq('a.actor_type', $query->createNamedParameter(Attendee::ACTOR_USERS)))
->andWhere($query->expr()->eq('a.actor_id', $query->createNamedParameter($userId)))
->andWhere($query->expr()->eq('a.room_id', $query->createNamedParameter($this->getId())))
->setMaxResults(1);

if ($sessionId !== false) {
$helper->selectSessionsTable($query);
if ($sessionId !== null) {
$query->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
$query->expr()->eq('s.session_id', $query->createNamedParameter($sessionId)),
$query->expr()->eq('a.id', 's.attendee_id')
));
} else {
$query->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'));
}
}

$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
Expand Down Expand Up @@ -479,9 +498,7 @@ public function getParticipantByPin(string $pin): Participant {
$query = $this->db->getQueryBuilder();
$helper = new SelectHelper();
$helper->selectAttendeesTable($query);
$helper->selectSessionsTable($query);
$query->from('talk_attendees', 'a')
->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'))
->andWhere($query->expr()->eq('a.pin', $query->createNamedParameter($pin)))
->andWhere($query->expr()->eq('a.room_id', $query->createNamedParameter($this->getId())))
->setMaxResults(1);
Expand All @@ -498,19 +515,33 @@ public function getParticipantByPin(string $pin): Participant {

/**
* @param int $attendeeId
* @param string|null|false $sessionId Set to false if you don't want to load a session (and save resources),
* string to try loading a specific session
* null to try loading "any"
* @return Participant
* @throws ParticipantNotFoundException When the pin is not valid (has no participant assigned)
*/
public function getParticipantByAttendeeId(int $attendeeId): Participant {
public function getParticipantByAttendeeId(int $attendeeId, $sessionId = null): Participant {
$query = $this->db->getQueryBuilder();
$helper = new SelectHelper();
$helper->selectAttendeesTable($query);
$helper->selectSessionsTable($query);
$query->from('talk_attendees', 'a')
->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'))
->andWhere($query->expr()->eq('a.id', $query->createNamedParameter($attendeeId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('a.room_id', $query->createNamedParameter($this->getId())))
->setMaxResults(1);

if ($sessionId !== false) {
$helper->selectSessionsTable($query);
if ($sessionId !== null) {
$query->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
$query->expr()->eq('s.session_id', $query->createNamedParameter($sessionId)),
$query->expr()->eq('a.id', 's.attendee_id')
));
} else {
$query->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'));
}
}

$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
Expand All @@ -525,24 +556,38 @@ public function getParticipantByAttendeeId(int $attendeeId): Participant {
/**
* @param string $actorType
* @param string $actorId
* @param string|null|false $sessionId Set to false if you don't want to load a session (and save resources),
* string to try loading a specific session
* null to try loading "any"
* @return Participant
* @throws ParticipantNotFoundException When the pin is not valid (has no participant assigned)
*/
public function getParticipantByActor(string $actorType, string $actorId): Participant {
public function getParticipantByActor(string $actorType, string $actorId, $sessionId = null): Participant {
if ($actorType === Attendee::ACTOR_USERS) {
return $this->getParticipant($actorId);
}

$query = $this->db->getQueryBuilder();
$helper = new SelectHelper();
$helper->selectAttendeesTable($query);
$helper->selectSessionsTable($query);
$query->from('talk_attendees', 'a')
->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'))
->andWhere($query->expr()->eq('a.actor_type', $query->createNamedParameter($actorType)))
->andWhere($query->expr()->eq('a.actor_id', $query->createNamedParameter($actorId)))
->andWhere($query->expr()->eq('a.room_id', $query->createNamedParameter($this->getId())))
->setMaxResults(1);

if ($sessionId !== false) {
$helper->selectSessionsTable($query);
if ($sessionId !== null) {
$query->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
$query->expr()->eq('s.session_id', $query->createNamedParameter($sessionId)),
$query->expr()->eq('a.id', 's.attendee_id')
));
} else {
$query->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id'));
}
}

$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();
Expand Down
12 changes: 7 additions & 5 deletions lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ public function getLastCommonReadChatMessageForMultipleRooms(array $roomIds): ar
* @return Participant[]
*/
public function getParticipantsForRoom(Room $room): 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();
Expand Down Expand Up @@ -665,6 +666,7 @@ public function getParticipantsByNotificationLevel(Room $room, int $notification
$helper->selectAttendeesTable($query);
$helper->selectSessionsTable($query);
$query->from('talk_attendees', 'a')
// Currently we only care if the user has a session at all, so we can select any: #ThisIsFine
->leftJoin(
'a', 'talk_sessions', 's',
$query->expr()->eq('s.attendee_id', 'a.id')
Expand Down Expand Up @@ -739,14 +741,14 @@ public function getParticipantUserIdsNotInCall(Room $room): array {
->from('talk_attendees', 'a')
->leftJoin(
'a', 'talk_sessions', 's',
$query->expr()->eq('s.attendee_id', 'a.id')
$query->expr()->andX(
$query->expr()->eq('s.attendee_id', 'a.id'),
$query->expr()->neq('s.in_call', $query->createNamedParameter(Participant::FLAG_DISCONNECTED)),
)
)
->where($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('a.actor_type', $query->createNamedParameter(Attendee::ACTOR_USERS)))
->andWhere($query->expr()->orX(
$query->expr()->eq('s.in_call', $query->createNamedParameter(Participant::FLAG_DISCONNECTED)),
$query->expr()->isNull('s.in_call')
));
->andWhere($query->expr()->isNull('s.in_call'));

$userIds = [];
$result = $query->execute();
Expand Down
Loading