diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2019-08-13 01:51:08 +0300 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2019-08-16 21:18:30 +0300 |
commit | 878962d6afbcd61d9552b66596ba25688b0285c1 (patch) | |
tree | 3ed25ed474a085d48f930b9d9516ddbf58bf958a /lib | |
parent | 9fb2de46317c6aba0e844d67577becb653505483 (diff) |
Add user to file room when joining it instead of when getting its token
This fixes the code so it behaves as stated in the documentation.
In practice currently this should make no difference, as in the Files
app the user joins the room immediately after getting its token;
however, this makes possible to get the token without joining the room,
which will be needed in the future to improve the UX of the Files app.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/FilesController.php | 6 | ||||
-rw-r--r-- | lib/Files/Listener.php | 23 |
2 files changed, 23 insertions, 6 deletions
diff --git a/lib/Controller/FilesController.php b/lib/Controller/FilesController.php index 451086c35..bc45eda10 100644 --- a/lib/Controller/FilesController.php +++ b/lib/Controller/FilesController.php @@ -104,12 +104,6 @@ class FilesController extends OCSController { $room = $this->manager->createPublicRoom($name, 'file', $fileId); } - try { - $room->getParticipant($this->currentUser); - } catch (ParticipantNotFoundException $e) { - $room->addUsers(['userId' => $this->currentUser]); - } - return new DataResponse([ 'token' => $room->getToken() ]); diff --git a/lib/Files/Listener.php b/lib/Files/Listener.php index dbd2b57e7..8b169cb94 100644 --- a/lib/Files/Listener.php +++ b/lib/Files/Listener.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace OCA\Spreed\Files; +use OCA\Spreed\Exceptions\ParticipantNotFoundException; use OCA\Spreed\Exceptions\UnauthorizedException; use OCA\Spreed\Room; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -61,6 +62,7 @@ class Listener { try { $listener->preventUsersWithoutDirectAccessToTheFileFromJoining($room, $event->getArgument('userId')); + $listener->addUserAsPersistentParticipant($room, $event->getArgument('userId')); } catch (UnauthorizedException $e) { $event->setArgument('cancel', true); } @@ -105,6 +107,27 @@ class Listener { } /** + * Add user as a persistent participant of a file room. + * + * This method should be called before a user joins a room, but only if the + * user should be able to join the room. + * + * @param Room $room + * @param string $userId + */ + public function addUserAsPersistentParticipant(Room $room, string $userId) { + if ($room->getObjectType() !== 'file') { + return; + } + + try { + $room->getParticipant($userId); + } catch (ParticipantNotFoundException $e) { + $room->addUsers(['userId' => $userId]); + } + } + + /** * Prevents guests from joining the room. * * This method should be called before a guest joins a room. |