Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-02-12 00:20:31 +0300
committerJoas Schilling <coding@schilljs.com>2021-02-12 12:46:35 +0300
commite9bc0ad78aa1a3f530ea4c1a52d34ea05e45e707 (patch)
tree58a3d2a200caff7b7454db0a5f1aaf13ea691de8
parentc39f2c7ce93ffc0b6de2c72fc84094eff738d0f8 (diff)
Reuse existing attendee when a guest refreshes
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--lib/Controller/RoomController.php2
-rw-r--r--lib/Service/ParticipantService.php34
2 files changed, 21 insertions, 15 deletions
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php
index 2fa28da53..113583337 100644
--- a/lib/Controller/RoomController.php
+++ b/lib/Controller/RoomController.php
@@ -1618,7 +1618,7 @@ class RoomController extends AEnvironmentAwareController {
$participant = $this->participantService->joinRoom($room, $user, $password, $result['result']);
$this->participantService->generatePinForParticipant($room, $participant);
} else {
- $participant = $this->participantService->joinRoomAsNewGuest($room, $password, $result['result']);
+ $participant = $this->participantService->joinRoomAsNewGuest($room, $password, $result['result'], $previousParticipant);
}
} catch (InvalidPasswordException $e) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php
index 3da1c82be..6e1d99588 100644
--- a/lib/Service/ParticipantService.php
+++ b/lib/Service/ParticipantService.php
@@ -213,11 +213,12 @@ class ParticipantService {
* @param Room $room
* @param string $password
* @param bool $passedPasswordProtection
+ * @param ?Participant $previousParticipant
* @return Participant
* @throws InvalidPasswordException
* @throws UnauthorizedException
*/
- public function joinRoomAsNewGuest(Room $room, string $password, bool $passedPasswordProtection = false): Participant {
+ public function joinRoomAsNewGuest(Room $room, string $password, bool $passedPasswordProtection = false, ?Participant $previousParticipant = null): Participant {
$event = new JoinRoomGuestEvent($room, $password, $passedPasswordProtection);
$this->dispatcher->dispatch(Room::EVENT_BEFORE_GUEST_CONNECT, $event);
@@ -234,21 +235,27 @@ class ParticipantService {
$lastMessage = (int) $room->getLastMessage()->getId();
}
- $randomActorId = $this->secureRandom->generate(255);
+ if ($previousParticipant instanceof Participant) {
+ $attendee = $previousParticipant->getAttendee();
+ } else {
+ $randomActorId = $this->secureRandom->generate(255);
- $attendee = new Attendee();
- $attendee->setRoomId($room->getId());
- $attendee->setActorType(Attendee::ACTOR_GUESTS);
- $attendee->setActorId($randomActorId);
- $attendee->setParticipantType(Participant::GUEST);
- $attendee->setLastReadMessage($lastMessage);
- $this->attendeeMapper->insert($attendee);
+ $attendee = new Attendee();
+ $attendee->setRoomId($room->getId());
+ $attendee->setActorType(Attendee::ACTOR_GUESTS);
+ $attendee->setActorId($randomActorId);
+ $attendee->setParticipantType(Participant::GUEST);
+ $attendee->setLastReadMessage($lastMessage);
+ $this->attendeeMapper->insert($attendee);
+ }
$session = $this->sessionService->createSessionForAttendee($attendee);
- // Update the random guest id
- $attendee->setActorId(sha1($session->getSessionId()));
- $this->attendeeMapper->update($attendee);
+ if (!$previousParticipant instanceof Participant) {
+ // Update the random guest id
+ $attendee->setActorId(sha1($session->getSessionId()));
+ $this->attendeeMapper->update($attendee);
+ }
$this->dispatcher->dispatch(Room::EVENT_AFTER_GUEST_CONNECT, $event);
@@ -381,8 +388,7 @@ class ParticipantService {
$this->sessionMapper->deleteByAttendeeId($participant->getAttendee()->getId());
}
- if ($participant->getAttendee()->getActorType() === Attendee::ACTOR_GUESTS
- || $participant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED) {
+ if ($participant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED) {
$this->attendeeMapper->delete($participant->getAttendee());
}