Skip to content
Merged
Changes from all commits
Commits
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
Deduplicate getting the room and participant in case some annotations…
… are combined

Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Mar 4, 2022
commit b5bc9dd97f32f975aae3f59b69619f04114483c4
40 changes: 23 additions & 17 deletions lib/Middleware/InjectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,32 @@ protected function getLoggedIn(AEnvironmentAwareController $controller, bool $mo
* @throws ParticipantNotFoundException
*/
protected function getLoggedInOrGuest(AEnvironmentAwareController $controller, bool $moderatorRequired): void {
$token = $this->request->getParam('token');
$sessionId = $this->talkSession->getSessionForRoom($token);
$room = $this->manager->getRoomForUserByToken($token, $this->userId, $sessionId);
$controller->setRoom($room);
$participant = null;

if ($sessionId !== null) {
try {
$participant = $room->getParticipantBySession($sessionId);
} catch (ParticipantNotFoundException $e) {
// ignore and fall back in case a concurrent request might have
// invalidated the session
}
$room = $controller->getRoom();
if (!$room instanceof Room) {
$token = $this->request->getParam('token');
$sessionId = $this->talkSession->getSessionForRoom($token);
$room = $this->manager->getRoomForUserByToken($token, $this->userId, $sessionId);
$controller->setRoom($room);
}

if ($participant === null) {
$participant = $room->getParticipant($this->userId);
}
$participant = $controller->getParticipant();
if (!$participant instanceof Participant) {
$participant = null;
if ($sessionId !== null) {
try {
$participant = $room->getParticipantBySession($sessionId);
} catch (ParticipantNotFoundException $e) {
// ignore and fall back in case a concurrent request might have
// invalidated the session
}
}

$controller->setParticipant($participant);
if ($participant === null) {
$participant = $room->getParticipant($this->userId);
}

$controller->setParticipant($participant);
}

if ($moderatorRequired && !$participant->hasModeratorPermissions()) {
throw new NotAModeratorException();
Expand Down