From 4ef48ab3252648413505f38cb53e08b962b777c3 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 12 May 2020 14:05:14 +0200 Subject: Remove unused code Signed-off-by: Daniel Rudolf --- lib/Command/Room/Add.php | 6 +----- lib/Command/Room/Create.php | 6 +----- lib/Command/Room/Demote.php | 6 +----- lib/Command/Room/Promote.php | 6 +----- lib/Command/Room/Remove.php | 6 +----- lib/Command/Room/Update.php | 6 +----- 6 files changed, 6 insertions(+), 30 deletions(-) (limited to 'lib') diff --git a/lib/Command/Room/Add.php b/lib/Command/Room/Add.php index d213beb1e..04355b93d 100644 --- a/lib/Command/Room/Add.php +++ b/lib/Command/Room/Add.php @@ -38,16 +38,12 @@ use Symfony\Component\Console\Output\OutputInterface; class Add extends Base { use TRoomCommand; - /** @var IUserManager */ - public $userManager; - /** @var Manager */ public $manager; - public function __construct(IUserManager $userManager, Manager $manager) { + public function __construct(Manager $manager) { parent::__construct(); - $this->userManager = $userManager; $this->manager = $manager; } diff --git a/lib/Command/Room/Create.php b/lib/Command/Room/Create.php index f2003e45d..95a395158 100644 --- a/lib/Command/Room/Create.php +++ b/lib/Command/Room/Create.php @@ -36,16 +36,12 @@ use Symfony\Component\Console\Output\OutputInterface; class Create extends Base { use TRoomCommand; - /** @var IUserManager */ - public $userManager; - /** @var Manager */ public $manager; - public function __construct(IUserManager $userManager, Manager $manager) { + public function __construct(Manager $manager) { parent::__construct(); - $this->userManager = $userManager; $this->manager = $manager; } diff --git a/lib/Command/Room/Demote.php b/lib/Command/Room/Demote.php index 008030811..cc470b7b1 100644 --- a/lib/Command/Room/Demote.php +++ b/lib/Command/Room/Demote.php @@ -37,16 +37,12 @@ use Symfony\Component\Console\Output\OutputInterface; class Demote extends Base { use TRoomCommand; - /** @var IUserManager */ - public $userManager; - /** @var Manager */ public $manager; - public function __construct(IUserManager $userManager, Manager $manager) { + public function __construct(Manager $manager) { parent::__construct(); - $this->userManager = $userManager; $this->manager = $manager; } diff --git a/lib/Command/Room/Promote.php b/lib/Command/Room/Promote.php index c55315343..3f30621d2 100644 --- a/lib/Command/Room/Promote.php +++ b/lib/Command/Room/Promote.php @@ -37,16 +37,12 @@ use Symfony\Component\Console\Output\OutputInterface; class Promote extends Base { use TRoomCommand; - /** @var IUserManager */ - public $userManager; - /** @var Manager */ public $manager; - public function __construct(IUserManager $userManager, Manager $manager) { + public function __construct(Manager $manager) { parent::__construct(); - $this->userManager = $userManager; $this->manager = $manager; } diff --git a/lib/Command/Room/Remove.php b/lib/Command/Room/Remove.php index 0c0f77012..c054e36db 100644 --- a/lib/Command/Room/Remove.php +++ b/lib/Command/Room/Remove.php @@ -37,16 +37,12 @@ use Symfony\Component\Console\Output\OutputInterface; class Remove extends Base { use TRoomCommand; - /** @var IUserManager */ - public $userManager; - /** @var Manager */ public $manager; - public function __construct(IUserManager $userManager, Manager $manager) { + public function __construct(Manager $manager) { parent::__construct(); - $this->userManager = $userManager; $this->manager = $manager; } diff --git a/lib/Command/Room/Update.php b/lib/Command/Room/Update.php index 500e898a8..b04b76cb6 100644 --- a/lib/Command/Room/Update.php +++ b/lib/Command/Room/Update.php @@ -38,16 +38,12 @@ use Symfony\Component\Console\Output\OutputInterface; class Update extends Base { use TRoomCommand; - /** @var IUserManager */ - public $userManager; - /** @var Manager */ public $manager; - public function __construct(IUserManager $userManager, Manager $manager) { + public function __construct(Manager $manager) { parent::__construct(); - $this->userManager = $userManager; $this->manager = $manager; } -- cgit v1.2.3 From 2efadfb80d5eec9266c02a69939917bd85335ccf Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 12 May 2020 14:18:26 +0200 Subject: Various small improvements Signed-off-by: Daniel Rudolf --- lib/Command/Room/Add.php | 5 ++--- lib/Command/Room/Create.php | 7 +++---- lib/Command/Room/Demote.php | 5 ++--- lib/Command/Room/Promote.php | 5 ++--- lib/Command/Room/Remove.php | 5 ++--- lib/Command/Room/Update.php | 5 ++--- 6 files changed, 13 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/Command/Room/Add.php b/lib/Command/Room/Add.php index 04355b93d..3001127ea 100644 --- a/lib/Command/Room/Add.php +++ b/lib/Command/Room/Add.php @@ -24,12 +24,11 @@ declare(strict_types=1); namespace OCA\Talk\Command\Room; -use Exception; +use InvalidArgumentException; use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Room; -use OCP\IUserManager; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -95,7 +94,7 @@ class Add extends Base { $this->addRoomParticipants($room, $users); $this->addRoomParticipantsByGroup($room, $groups); $this->addRoomParticipantsByCircle($room, $circles); - } catch (Exception $e) { + } catch (InvalidArgumentException $e) { $output->writeln(sprintf('%s', $e->getMessage())); return 1; } diff --git a/lib/Command/Room/Create.php b/lib/Command/Room/Create.php index 95a395158..26b197dff 100644 --- a/lib/Command/Room/Create.php +++ b/lib/Command/Room/Create.php @@ -24,10 +24,9 @@ declare(strict_types=1); namespace OCA\Talk\Command\Room; -use Exception; +use InvalidArgumentException; use OC\Core\Command\Base; use OCA\Talk\Manager; -use OCP\IUserManager; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -109,7 +108,7 @@ class Create extends Base { $name = trim($name); if (!$this->validateRoomName($name)) { - $output->writeln("Invalid room name."); + $output->writeln('Invalid room name.'); return 1; } @@ -130,7 +129,7 @@ class Create extends Base { if ($owner !== null) { $this->setRoomOwner($room, $owner); } - } catch (Exception $e) { + } catch (InvalidArgumentException $e) { $room->deleteRoom(); $output->writeln(sprintf('%s', $e->getMessage())); diff --git a/lib/Command/Room/Demote.php b/lib/Command/Room/Demote.php index cc470b7b1..0b4f8bac4 100644 --- a/lib/Command/Room/Demote.php +++ b/lib/Command/Room/Demote.php @@ -24,12 +24,11 @@ declare(strict_types=1); namespace OCA\Talk\Command\Room; -use Exception; +use InvalidArgumentException; use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Room; -use OCP\IUserManager; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -79,7 +78,7 @@ class Demote extends Base { try { $this->removeRoomModerators($room, $users); - } catch (Exception $e) { + } catch (InvalidArgumentException $e) { $output->writeln(sprintf('%s', $e->getMessage())); return 1; } diff --git a/lib/Command/Room/Promote.php b/lib/Command/Room/Promote.php index 3f30621d2..e978e8dae 100644 --- a/lib/Command/Room/Promote.php +++ b/lib/Command/Room/Promote.php @@ -24,12 +24,11 @@ declare(strict_types=1); namespace OCA\Talk\Command\Room; -use Exception; +use InvalidArgumentException; use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Room; -use OCP\IUserManager; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -79,7 +78,7 @@ class Promote extends Base { try { $this->addRoomModerators($room, $users); - } catch (Exception $e) { + } catch (InvalidArgumentException $e) { $output->writeln(sprintf('%s', $e->getMessage())); return 1; } diff --git a/lib/Command/Room/Remove.php b/lib/Command/Room/Remove.php index c054e36db..016e8c608 100644 --- a/lib/Command/Room/Remove.php +++ b/lib/Command/Room/Remove.php @@ -24,12 +24,11 @@ declare(strict_types=1); namespace OCA\Talk\Command\Room; -use Exception; +use InvalidArgumentException; use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Room; -use OCP\IUserManager; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -79,7 +78,7 @@ class Remove extends Base { try { $this->removeRoomParticipants($room, $users); - } catch (Exception $e) { + } catch (InvalidArgumentException $e) { $output->writeln(sprintf('%s', $e->getMessage())); return 1; } diff --git a/lib/Command/Room/Update.php b/lib/Command/Room/Update.php index b04b76cb6..84d52bd92 100644 --- a/lib/Command/Room/Update.php +++ b/lib/Command/Room/Update.php @@ -24,12 +24,11 @@ declare(strict_types=1); namespace OCA\Talk\Command\Room; -use Exception; +use InvalidArgumentException; use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Room; -use OCP\IUserManager; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -137,7 +136,7 @@ class Update extends Base { $this->unsetRoomOwner($room); } } - } catch (Exception $e) { + } catch (InvalidArgumentException $e) { $output->writeln(sprintf('%s', $e->getMessage())); return 1; } -- cgit v1.2.3 From a238208d3a9bde0717c8277ff66e9ff96f7e00dc Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 12 May 2020 15:38:05 +0200 Subject: Fix `talk:room:update --owner` adding multiple owners Signed-off-by: Daniel Rudolf --- lib/Command/Room/TRoomCommand.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/Command/Room/TRoomCommand.php b/lib/Command/Room/TRoomCommand.php index 1b65d8d0d..0fb341ef5 100644 --- a/lib/Command/Room/TRoomCommand.php +++ b/lib/Command/Room/TRoomCommand.php @@ -136,6 +136,8 @@ trait TRoomCommand throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId)); } + $this->unsetRoomOwner($room); + $room->setParticipantType($participant, Participant::OWNER); } -- cgit v1.2.3 From 44a24353fe1ae1a0c6abbf1e1b8d0ccfc088746b Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Wed, 13 May 2020 15:52:10 +0200 Subject: Fix success messages for talk:room:* commands Signed-off-by: Daniel Rudolf --- lib/Command/Room/Demote.php | 2 +- lib/Command/Room/Promote.php | 2 +- lib/Command/Room/Remove.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Command/Room/Demote.php b/lib/Command/Room/Demote.php index 0b4f8bac4..a3a7bc625 100644 --- a/lib/Command/Room/Demote.php +++ b/lib/Command/Room/Demote.php @@ -83,7 +83,7 @@ class Demote extends Base { return 1; } - $output->writeln('Users successfully remove from room.'); + $output->writeln('Participants successfully demoted to regular users.'); return 0; } } diff --git a/lib/Command/Room/Promote.php b/lib/Command/Room/Promote.php index e978e8dae..08356cd62 100644 --- a/lib/Command/Room/Promote.php +++ b/lib/Command/Room/Promote.php @@ -83,7 +83,7 @@ class Promote extends Base { return 1; } - $output->writeln('Users successfully added to room.'); + $output->writeln('Participants successfully promoted to moderators.'); return 0; } } diff --git a/lib/Command/Room/Remove.php b/lib/Command/Room/Remove.php index 016e8c608..1966e35d6 100644 --- a/lib/Command/Room/Remove.php +++ b/lib/Command/Room/Remove.php @@ -83,7 +83,7 @@ class Remove extends Base { return 1; } - $output->writeln('Users successfully remove from room.'); + $output->writeln('Users successfully removed from room.'); return 0; } } -- cgit v1.2.3 From 349793e11d25b77e58a6e63798c0673e73f8d647 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Wed, 13 May 2020 19:21:43 +0200 Subject: Rename argument 'user' of talk:room:remove command to 'participant' Signed-off-by: Daniel Rudolf --- lib/Command/Room/Remove.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Command/Room/Remove.php b/lib/Command/Room/Remove.php index 3bc0edadf..3f93d5c08 100644 --- a/lib/Command/Room/Remove.php +++ b/lib/Command/Room/Remove.php @@ -55,15 +55,15 @@ class Remove extends Base { InputArgument::REQUIRED, 'Token of the room to remove users from' )->addArgument( - 'user', + 'participant', InputArgument::REQUIRED | InputArgument::IS_ARRAY, - 'Removes the given users from the room' + 'Removes the given participants from the room' ); } protected function execute(InputInterface $input, OutputInterface $output): ?int { $token = $input->getArgument('token'); - $users = $input->getArgument('user'); + $users = $input->getArgument('participant'); try { $room = $this->manager->getRoomByToken($token); -- cgit v1.2.3 From a6d0d02d1d70e25a1d07b666cefb65aff0fcbb45 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Wed, 13 May 2020 21:27:33 +0200 Subject: Add Manager::searchRoomsByToken() Signed-off-by: Daniel Rudolf --- lib/Manager.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'lib') diff --git a/lib/Manager.php b/lib/Manager.php index aa539299b..c937262c9 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -224,6 +224,42 @@ class Manager { $result->closeCursor(); } + /** + * @param string $searchToken + * @param int $limit + * @param int $offset + * @return Room[] + */ + public function searchRoomsByToken(string $searchToken = '', int $limit = null, int $offset = null): array { + $query = $this->db->getQueryBuilder(); + $query->select('r.*') + ->from('talk_rooms', 'r') + ->setMaxResults(1); + + if ($searchToken !== '') { + $query->where($query->expr()->iLike('r.token', $query->createNamedParameter( + $this->db->escapeLikeParameter($searchToken) . '%' + ))); + } + + $query->setMaxResults($limit) + ->setFirstResult($offset); + $result = $query->execute(); + + $rooms = []; + while ($row = $result->fetch()) { + if ($row['token'] === null) { + // FIXME Temporary solution for the Talk6 release + continue; + } + + $rooms[] = $this->createRoomObject($row); + } + $result->closeCursor(); + + return $rooms; + } + /** * @param string $participant * @param bool $includeLastMessage -- cgit v1.2.3 From d4f0d2e443d1e42b875338bc1077614be60af1a9 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Wed, 13 May 2020 21:29:26 +0200 Subject: Add bash autocompletion for talk:room:* commands Implementations for option "--circle" and participant options/arguments is still pending, i.e. this is work in progress. Signed-off-by: Daniel Rudolf --- lib/Command/Room/Add.php | 25 +++++++++++++++++++++++++ lib/Command/Room/Create.php | 20 ++++++++++++++++++++ lib/Command/Room/Delete.php | 12 ++++++++++++ lib/Command/Room/Demote.php | 13 +++++++++++++ lib/Command/Room/Promote.php | 13 +++++++++++++ lib/Command/Room/Remove.php | 13 +++++++++++++ lib/Command/Room/TRoomCommand.php | 35 +++++++++++++++++++++++++++++++++++ lib/Command/Room/Update.php | 23 +++++++++++++++++++++++ 8 files changed, 154 insertions(+) (limited to 'lib') diff --git a/lib/Command/Room/Add.php b/lib/Command/Room/Add.php index f9d532d05..0e63e7453 100644 --- a/lib/Command/Room/Add.php +++ b/lib/Command/Room/Add.php @@ -30,6 +30,7 @@ use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Room; +use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -103,4 +104,28 @@ class Add extends Base { $output->writeln('Users successfully added to room.'); return 0; } + + public function completeOptionValues($optionName, CompletionContext $context) { + switch ($optionName) { + case 'user': + return $this->completeUserValues($context); + + case 'group': + return $this->completeGroupValues($context); + + case 'circle': + return $this->completeCircleValues($context); + } + + return parent::completeOptionValues($optionName, $context); + } + + public function completeArgumentValues($argumentName, CompletionContext $context) { + switch ($argumentName) { + case 'token': + return $this->completeTokenValues($context); + } + + return parent::completeArgumentValues($argumentName, $context); + } } diff --git a/lib/Command/Room/Create.php b/lib/Command/Room/Create.php index ead258479..2e9e3882a 100644 --- a/lib/Command/Room/Create.php +++ b/lib/Command/Room/Create.php @@ -28,6 +28,7 @@ namespace OCA\Talk\Command\Room; use InvalidArgumentException; use OC\Core\Command\Base; use OCA\Talk\Manager; +use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -140,4 +141,23 @@ class Create extends Base { $output->writeln('Room successfully created.'); return 0; } + + public function completeOptionValues($optionName, CompletionContext $context) { + switch ($optionName) { + case 'user': + return $this->completeUserValues($context); + + case 'group': + return $this->completeGroupValues($context); + + case 'circle': + return $this->completeCircleValues($context); + + case 'owner': + case 'moderator': + return $this->completeParticipantValues($context); + } + + return parent::completeOptionValues($optionName, $context); + } } diff --git a/lib/Command/Room/Delete.php b/lib/Command/Room/Delete.php index 986ca67a4..6e659e2f5 100644 --- a/lib/Command/Room/Delete.php +++ b/lib/Command/Room/Delete.php @@ -29,11 +29,14 @@ use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Room; +use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class Delete extends Base { + use TRoomCommand; + /** @var Manager */ public $manager; @@ -74,4 +77,13 @@ class Delete extends Base { $output->writeln('Room successfully deleted.'); return 0; } + + public function completeArgumentValues($argumentName, CompletionContext $context) { + switch ($argumentName) { + case 'token': + return $this->completeTokenValues($context); + } + + return parent::completeArgumentValues($argumentName, $context); + } } diff --git a/lib/Command/Room/Demote.php b/lib/Command/Room/Demote.php index a3b2ce69d..3fc180457 100644 --- a/lib/Command/Room/Demote.php +++ b/lib/Command/Room/Demote.php @@ -30,6 +30,7 @@ use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Room; +use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -87,4 +88,16 @@ class Demote extends Base { $output->writeln('Participants successfully demoted to regular users.'); return 0; } + + public function completeArgumentValues($argumentName, CompletionContext $context) { + switch ($argumentName) { + case 'token': + return $this->completeTokenValues($context); + + case 'participant': + return $this->completeParticipantValues($context); + } + + return parent::completeArgumentValues($argumentName, $context); + } } diff --git a/lib/Command/Room/Promote.php b/lib/Command/Room/Promote.php index 4f4070dde..31e48c34a 100644 --- a/lib/Command/Room/Promote.php +++ b/lib/Command/Room/Promote.php @@ -30,6 +30,7 @@ use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Room; +use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -87,4 +88,16 @@ class Promote extends Base { $output->writeln('Participants successfully promoted to moderators.'); return 0; } + + public function completeArgumentValues($argumentName, CompletionContext $context) { + switch ($argumentName) { + case 'token': + return $this->completeTokenValues($context); + + case 'participant': + return $this->completeParticipantValues($context); + } + + return parent::completeArgumentValues($argumentName, $context); + } } diff --git a/lib/Command/Room/Remove.php b/lib/Command/Room/Remove.php index 3f93d5c08..19b2ac678 100644 --- a/lib/Command/Room/Remove.php +++ b/lib/Command/Room/Remove.php @@ -30,6 +30,7 @@ use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Room; +use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -87,4 +88,16 @@ class Remove extends Base { $output->writeln('Users successfully removed from room.'); return 0; } + + public function completeArgumentValues($argumentName, CompletionContext $context) { + switch ($argumentName) { + case 'token': + return $this->completeTokenValues($context); + + case 'participant': + return $this->completeParticipantValues($context); + } + + return parent::completeArgumentValues($argumentName, $context); + } } diff --git a/lib/Command/Room/TRoomCommand.php b/lib/Command/Room/TRoomCommand.php index ae12bbdeb..f2066a2e0 100644 --- a/lib/Command/Room/TRoomCommand.php +++ b/lib/Command/Room/TRoomCommand.php @@ -29,9 +29,12 @@ use InvalidArgumentException; use OCA\Circles\Api\v1\Circles; use OCA\Circles\Model\Member; use OCA\Talk\Exceptions\ParticipantNotFoundException; +use OCA\Talk\Manager; use OCA\Talk\Participant; use OCA\Talk\Room; +use OCP\IGroup; use OCP\IUser; +use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; trait TRoomCommand { /** @@ -337,4 +340,36 @@ trait TRoomCommand { $room->setParticipantType($participant, Participant::USER); } } + + protected function completeTokenValues(CompletionContext $context): array { + /** @var Manager $roomManager */ + $roomManager = \OC::$server->query(Manager::class); + return array_map(function (Room $room) { + return $room->getToken(); + }, $roomManager->searchRoomsByToken($context->getCurrentWord())); + } + + protected function completeUserValues(CompletionContext $context): array { + $userManager = \OC::$server->getUserManager(); + return array_map(function (IUser $user) { + return $user->getUID(); + }, $userManager->search($context->getCurrentWord())); + } + + protected function completeGroupValues(CompletionContext $context): array { + $groupManager = \OC::$server->getGroupManager(); + return array_map(function (IGroup $group) { + return $group->getGID(); + }, $groupManager->search($context->getCurrentWord())); + } + + protected function completeCircleValues(CompletionContext $context): array { + // TODO: implement me! + return []; + } + + protected function completeParticipantValues(CompletionContext $context): array { + // TODO: implement me! + return []; + } } diff --git a/lib/Command/Room/Update.php b/lib/Command/Room/Update.php index b50e1c8d3..1a769a5da 100644 --- a/lib/Command/Room/Update.php +++ b/lib/Command/Room/Update.php @@ -30,6 +30,7 @@ use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Room; +use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -145,4 +146,26 @@ class Update extends Base { $output->writeln('Room successfully updated.'); return 0; } + + public function completeOptionValues($optionName, CompletionContext $context) { + switch ($optionName) { + case 'public': + case 'readonly': + return ['1', '0']; + + case 'owner': + return $this->completeParticipantValues($context); + } + + return parent::completeOptionValues($optionName, $context); + } + + public function completeArgumentValues($argumentName, CompletionContext $context) { + switch ($argumentName) { + case 'token': + return $this->completeTokenValues($context); + } + + return parent::completeArgumentValues($argumentName, $context); + } } -- cgit v1.2.3 From ac41ca22a310c341bbdd7ed79a6d9ea8f4b1c442 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 21 May 2020 11:14:58 +0200 Subject: Remove --circle options from talk:room:create and talk:room:add commands See https://github.com/nextcloud/spreed/pull/3505#issuecomment-631969201 for a reasoning Signed-off-by: Daniel Rudolf --- lib/Command/Room/Add.php | 10 --------- lib/Command/Room/Create.php | 10 --------- lib/Command/Room/TRoomCommand.php | 44 --------------------------------------- 3 files changed, 64 deletions(-) (limited to 'lib') diff --git a/lib/Command/Room/Add.php b/lib/Command/Room/Add.php index 0e63e7453..2b2a449b9 100644 --- a/lib/Command/Room/Add.php +++ b/lib/Command/Room/Add.php @@ -66,11 +66,6 @@ class Add extends Base { null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Invites all members of the given groups to the room' - )->addOption( - 'circle', - null, - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'Invites all members of the given circles to the room' ); } @@ -78,7 +73,6 @@ class Add extends Base { $token = $input->getArgument('token'); $users = $input->getOption('user'); $groups = $input->getOption('group'); - $circles = $input->getOption('circle'); try { $room = $this->manager->getRoomByToken($token); @@ -95,7 +89,6 @@ class Add extends Base { try { $this->addRoomParticipants($room, $users); $this->addRoomParticipantsByGroup($room, $groups); - $this->addRoomParticipantsByCircle($room, $circles); } catch (InvalidArgumentException $e) { $output->writeln(sprintf('%s', $e->getMessage())); return 1; @@ -112,9 +105,6 @@ class Add extends Base { case 'group': return $this->completeGroupValues($context); - - case 'circle': - return $this->completeCircleValues($context); } return parent::completeOptionValues($optionName, $context); diff --git a/lib/Command/Room/Create.php b/lib/Command/Room/Create.php index 2e9e3882a..c987e1211 100644 --- a/lib/Command/Room/Create.php +++ b/lib/Command/Room/Create.php @@ -64,11 +64,6 @@ class Create extends Base { null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Invites all members of the given group to the room to create' - )->addOption( - 'circle', - null, - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'Invites all members of the given circle to the room to create' )->addOption( 'public', null, @@ -101,7 +96,6 @@ class Create extends Base { $name = $input->getArgument('name'); $users = $input->getOption('user'); $groups = $input->getOption('group'); - $circles = $input->getOption('circle'); $public = $input->getOption('public'); $readonly = $input->getOption('readonly'); $password = $input->getOption('password'); @@ -125,7 +119,6 @@ class Create extends Base { $this->addRoomParticipants($room, $users); $this->addRoomParticipantsByGroup($room, $groups); - $this->addRoomParticipantsByCircle($room, $circles); $this->addRoomModerators($room, $moderators); if ($owner !== null) { @@ -150,9 +143,6 @@ class Create extends Base { case 'group': return $this->completeGroupValues($context); - case 'circle': - return $this->completeCircleValues($context); - case 'owner': case 'moderator': return $this->completeParticipantValues($context); diff --git a/lib/Command/Room/TRoomCommand.php b/lib/Command/Room/TRoomCommand.php index f2066a2e0..bffa4e5e6 100644 --- a/lib/Command/Room/TRoomCommand.php +++ b/lib/Command/Room/TRoomCommand.php @@ -26,8 +26,6 @@ declare(strict_types=1); namespace OCA\Talk\Command\Room; use InvalidArgumentException; -use OCA\Circles\Api\v1\Circles; -use OCA\Circles\Model\Member; use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Participant; @@ -187,43 +185,6 @@ trait TRoomCommand { $this->addRoomParticipants($room, $users); } - /** - * @param Room $room - * @param string[] $circleIds - * - * @throws InvalidArgumentException - */ - protected function addRoomParticipantsByCircle(Room $room, array $circleIds): void { - if (!$circleIds) { - return; - } - - if (!\OC::$server->getAppManager()->isEnabledForUser('circles')) { - throw new InvalidArgumentException("App 'circles' is not enabled."); - } - - $users = []; - foreach ($circleIds as $circleId) { - try { - $circle = Circles::detailsCircle($circleId); - } catch (\Exception $e) { - throw new InvalidArgumentException(sprintf("Circle '%s' not found.", $circleId)); - } - - $circleUsers = array_filter($circle->getMembers(), function (Member $member) { - if (($member->getType() !== Member::TYPE_USER) || ($member->getUserId() === '')) { - return false; - } - - return in_array($member->getStatus(), [Member::STATUS_INVITED, Member::STATUS_MEMBER], true); - }); - - $users = array_merge($users, $circleUsers); - } - - $this->addRoomParticipants($room, $users); - } - /** * @param Room $room * @param string[] $userIds @@ -363,11 +324,6 @@ trait TRoomCommand { }, $groupManager->search($context->getCurrentWord())); } - protected function completeCircleValues(CompletionContext $context): array { - // TODO: implement me! - return []; - } - protected function completeParticipantValues(CompletionContext $context): array { // TODO: implement me! return []; -- cgit v1.2.3 From db4caaf2aee8b437798cb7388c59335263e6c063 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 21 May 2020 12:18:39 +0200 Subject: Add Room::searchParticipants() Signed-off-by: Daniel Rudolf --- lib/Room.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lib') diff --git a/lib/Room.php b/lib/Room.php index d087a2112..ef0be8f5b 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -1015,6 +1015,41 @@ class Room { return $participants; } + /** + * @param string $searchUserId + * @param int $limit + * @param int $offset + * @return Participant[] + */ + public function searchParticipants(string $searchUserId = '', int $limit = null, int $offset = null): array { + $query = $this->db->getQueryBuilder(); + $query->select('*') + ->from('talk_participants') + ->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId()))); + + if ($searchUserId !== '') { + $query->where($query->expr()->iLike('user_id', $query->createNamedParameter( + '%' . $this->db->escapeLikeParameter($searchUserId) . '%' + ))); + } + + $query->setMaxResults($limit) + ->setFirstResult($offset); + $result = $query->execute(); + + $participants = []; + while ($row = $result->fetch()) { + $participants[] = $this->manager->createParticipantObject($this, $row); + } + $result->closeCursor(); + + uasort($participants, function (Participant $a, Participant $b) { + return strcasecmp($a->getUser(), $b->getUser()); + }); + + return $participants; + } + /** * @return Participant[] */ -- cgit v1.2.3 From bbdfc442f2c2401c514c8160fbaf5fd486c3d2c2 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 21 May 2020 12:18:47 +0200 Subject: Implement TRoomCommand::completeParticipantValues() Signed-off-by: Daniel Rudolf --- lib/Command/Room/TRoomCommand.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/Command/Room/TRoomCommand.php b/lib/Command/Room/TRoomCommand.php index bffa4e5e6..df598a6e2 100644 --- a/lib/Command/Room/TRoomCommand.php +++ b/lib/Command/Room/TRoomCommand.php @@ -27,12 +27,14 @@ namespace OCA\Talk\Command\Room; use InvalidArgumentException; use OCA\Talk\Exceptions\ParticipantNotFoundException; +use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Manager; use OCA\Talk\Participant; use OCA\Talk\Room; use OCP\IGroup; use OCP\IUser; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; +use Symfony\Component\Console\Input\ArgvInput; trait TRoomCommand { /** @@ -325,7 +327,22 @@ trait TRoomCommand { } protected function completeParticipantValues(CompletionContext $context): array { - // TODO: implement me! - return []; + /** @var Manager $roomManager */ + $roomManager = \OC::$server->query(Manager::class); + + // drop `./occ talk:room:*`, but re-prepend command name for ArgvInput + $args = array_merge([$context->getWordAtIndex(0)], array_slice($context->getWords(), 2)); + $input = new ArgvInput($args, $this->getDefinition()); + + try { + $token = $input->getArgument('token'); + $room = $roomManager->getRoomByToken($token); + } catch (RoomNotFoundException $e) { + return []; + } + + return array_map(function (Participant $participant) { + return $participant->getUser(); + }, $room->searchParticipants($context->getCurrentWord())); } } -- cgit v1.2.3 From 9c052b4a066fb45644f5c50662f1d7fae0fb6e46 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 21 May 2020 13:51:50 +0200 Subject: Sort results of Manager::searchRoomsByToken() and Room::searchParticipants() Signed-off-by: Daniel Rudolf --- lib/Manager.php | 11 ++++++----- lib/Room.php | 15 ++++++--------- 2 files changed, 12 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/Manager.php b/lib/Manager.php index c937262c9..2c5c0a8dd 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -232,18 +232,19 @@ class Manager { */ public function searchRoomsByToken(string $searchToken = '', int $limit = null, int $offset = null): array { $query = $this->db->getQueryBuilder(); - $query->select('r.*') - ->from('talk_rooms', 'r') + $query->select('*') + ->from('talk_rooms') ->setMaxResults(1); if ($searchToken !== '') { - $query->where($query->expr()->iLike('r.token', $query->createNamedParameter( - $this->db->escapeLikeParameter($searchToken) . '%' + $query->where($query->expr()->iLike('token', $query->createNamedParameter( + '%' . $this->db->escapeLikeParameter($searchToken) . '%' ))); } $query->setMaxResults($limit) - ->setFirstResult($offset); + ->setFirstResult($offset) + ->orderBy('token', 'ASC'); $result = $query->execute(); $rooms = []; diff --git a/lib/Room.php b/lib/Room.php index ef0be8f5b..d3e9795af 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -1016,25 +1016,26 @@ class Room { } /** - * @param string $searchUserId + * @param string $search * @param int $limit * @param int $offset * @return Participant[] */ - public function searchParticipants(string $searchUserId = '', int $limit = null, int $offset = null): array { + public function searchParticipants(string $search = '', int $limit = null, int $offset = null): array { $query = $this->db->getQueryBuilder(); $query->select('*') ->from('talk_participants') ->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId()))); - if ($searchUserId !== '') { + if ($search !== '') { $query->where($query->expr()->iLike('user_id', $query->createNamedParameter( - '%' . $this->db->escapeLikeParameter($searchUserId) . '%' + '%' . $this->db->escapeLikeParameter($search) . '%' ))); } $query->setMaxResults($limit) - ->setFirstResult($offset); + ->setFirstResult($offset) + ->orderBy('user_id', 'ASC'); $result = $query->execute(); $participants = []; @@ -1043,10 +1044,6 @@ class Room { } $result->closeCursor(); - uasort($participants, function (Participant $a, Participant $b) { - return strcasecmp($a->getUser(), $b->getUser()); - }); - return $participants; } -- cgit v1.2.3 From 63a883c6d8b5e30b9bf38a9697525ae9fd6d358a Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 21 May 2020 13:57:20 +0200 Subject: Use a properly set up input definition for TRoomCommand::completeParticipantValues() Signed-off-by: Daniel Rudolf --- lib/Command/Room/TRoomCommand.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/Command/Room/TRoomCommand.php b/lib/Command/Room/TRoomCommand.php index df598a6e2..1c6ae780b 100644 --- a/lib/Command/Room/TRoomCommand.php +++ b/lib/Command/Room/TRoomCommand.php @@ -35,6 +35,7 @@ use OCP\IGroup; use OCP\IUser; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Console\Input\InputDefinition; trait TRoomCommand { /** @@ -327,15 +328,29 @@ trait TRoomCommand { } protected function completeParticipantValues(CompletionContext $context): array { + $definition = new InputDefinition(); + + if ($this->getApplication() !== null) { + $definition->addArguments($this->getApplication()->getDefinition()->getArguments()); + $definition->addOptions($this->getApplication()->getDefinition()->getOptions()); + } + + $definition->addArguments($this->getDefinition()->getArguments()); + $definition->addOptions($this->getDefinition()->getOptions()); + + $input = new ArgvInput($context->getWords(), $definition); + if ($input->hasArgument('token')) { + $token = $input->getArgument('token'); + } elseif ($input->hasOption('token')) { + $token = $input->getOption('token'); + } else { + return []; + } + /** @var Manager $roomManager */ $roomManager = \OC::$server->query(Manager::class); - // drop `./occ talk:room:*`, but re-prepend command name for ArgvInput - $args = array_merge([$context->getWordAtIndex(0)], array_slice($context->getWords(), 2)); - $input = new ArgvInput($args, $this->getDefinition()); - try { - $token = $input->getArgument('token'); $room = $roomManager->getRoomByToken($token); } catch (RoomNotFoundException $e) { return []; -- cgit v1.2.3 From 0b13f861f82dd17d2b789f20884b5a4a67c01a6d Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Fri, 29 May 2020 19:04:04 +0200 Subject: Move talk:room:* command and unit test DI to traits Signed-off-by: Daniel Rudolf --- lib/Command/Room/Add.php | 10 -------- lib/Command/Room/Create.php | 10 -------- lib/Command/Room/Delete.php | 10 -------- lib/Command/Room/Demote.php | 10 -------- lib/Command/Room/Promote.php | 10 -------- lib/Command/Room/Remove.php | 10 -------- lib/Command/Room/TRoomCommand.php | 53 ++++++++++++++++++++++++--------------- lib/Command/Room/Update.php | 10 -------- 8 files changed, 33 insertions(+), 90 deletions(-) (limited to 'lib') diff --git a/lib/Command/Room/Add.php b/lib/Command/Room/Add.php index 2b2a449b9..d5d0b7338 100644 --- a/lib/Command/Room/Add.php +++ b/lib/Command/Room/Add.php @@ -28,7 +28,6 @@ namespace OCA\Talk\Command\Room; use InvalidArgumentException; use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; -use OCA\Talk\Manager; use OCA\Talk\Room; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; @@ -39,15 +38,6 @@ use Symfony\Component\Console\Output\OutputInterface; class Add extends Base { use TRoomCommand; - /** @var Manager */ - public $manager; - - public function __construct(Manager $manager) { - parent::__construct(); - - $this->manager = $manager; - } - protected function configure(): void { $this ->setName('talk:room:add') diff --git a/lib/Command/Room/Create.php b/lib/Command/Room/Create.php index c987e1211..f96ef7dd5 100644 --- a/lib/Command/Room/Create.php +++ b/lib/Command/Room/Create.php @@ -27,7 +27,6 @@ namespace OCA\Talk\Command\Room; use InvalidArgumentException; use OC\Core\Command\Base; -use OCA\Talk\Manager; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -37,15 +36,6 @@ use Symfony\Component\Console\Output\OutputInterface; class Create extends Base { use TRoomCommand; - /** @var Manager */ - public $manager; - - public function __construct(Manager $manager) { - parent::__construct(); - - $this->manager = $manager; - } - protected function configure(): void { $this ->setName('talk:room:create') diff --git a/lib/Command/Room/Delete.php b/lib/Command/Room/Delete.php index 6e659e2f5..34b767cc3 100644 --- a/lib/Command/Room/Delete.php +++ b/lib/Command/Room/Delete.php @@ -27,7 +27,6 @@ namespace OCA\Talk\Command\Room; use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; -use OCA\Talk\Manager; use OCA\Talk\Room; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; @@ -37,15 +36,6 @@ use Symfony\Component\Console\Output\OutputInterface; class Delete extends Base { use TRoomCommand; - /** @var Manager */ - public $manager; - - public function __construct(Manager $manager) { - parent::__construct(); - - $this->manager = $manager; - } - protected function configure(): void { $this ->setName('talk:room:delete') diff --git a/lib/Command/Room/Demote.php b/lib/Command/Room/Demote.php index 3fc180457..e510f311b 100644 --- a/lib/Command/Room/Demote.php +++ b/lib/Command/Room/Demote.php @@ -28,7 +28,6 @@ namespace OCA\Talk\Command\Room; use InvalidArgumentException; use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; -use OCA\Talk\Manager; use OCA\Talk\Room; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; @@ -38,15 +37,6 @@ use Symfony\Component\Console\Output\OutputInterface; class Demote extends Base { use TRoomCommand; - /** @var Manager */ - public $manager; - - public function __construct(Manager $manager) { - parent::__construct(); - - $this->manager = $manager; - } - protected function configure(): void { $this ->setName('talk:room:demote') diff --git a/lib/Command/Room/Promote.php b/lib/Command/Room/Promote.php index 31e48c34a..613d8d0b7 100644 --- a/lib/Command/Room/Promote.php +++ b/lib/Command/Room/Promote.php @@ -28,7 +28,6 @@ namespace OCA\Talk\Command\Room; use InvalidArgumentException; use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; -use OCA\Talk\Manager; use OCA\Talk\Room; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; @@ -38,15 +37,6 @@ use Symfony\Component\Console\Output\OutputInterface; class Promote extends Base { use TRoomCommand; - /** @var Manager */ - public $manager; - - public function __construct(Manager $manager) { - parent::__construct(); - - $this->manager = $manager; - } - protected function configure(): void { $this ->setName('talk:room:promote') diff --git a/lib/Command/Room/Remove.php b/lib/Command/Room/Remove.php index 19b2ac678..b3cc192d2 100644 --- a/lib/Command/Room/Remove.php +++ b/lib/Command/Room/Remove.php @@ -28,7 +28,6 @@ namespace OCA\Talk\Command\Room; use InvalidArgumentException; use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; -use OCA\Talk\Manager; use OCA\Talk\Room; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; @@ -38,15 +37,6 @@ use Symfony\Component\Console\Output\OutputInterface; class Remove extends Base { use TRoomCommand; - /** @var Manager */ - public $manager; - - public function __construct(Manager $manager) { - parent::__construct(); - - $this->manager = $manager; - } - protected function configure(): void { $this ->setName('talk:room:remove') diff --git a/lib/Command/Room/TRoomCommand.php b/lib/Command/Room/TRoomCommand.php index 1c6ae780b..cb8bb2daa 100644 --- a/lib/Command/Room/TRoomCommand.php +++ b/lib/Command/Room/TRoomCommand.php @@ -32,12 +32,38 @@ use OCA\Talk\Manager; use OCA\Talk\Participant; use OCA\Talk\Room; use OCP\IGroup; +use OCP\IGroupManager; use OCP\IUser; +use OCP\IUserManager; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\InputDefinition; trait TRoomCommand { + /** @var Manager */ + protected $manager; + + /** @var IUserManager */ + protected $userManager; + + /** @var IGroupManager */ + protected $groupManager; + + /** + * TRoomCommand constructor. + * + * @param Manager $manager + * @param IUserManager $userManager + * @param IGroupManager $groupManager + */ + public function __construct(Manager $manager, IUserManager $userManager, IGroupManager $groupManager) { + parent::__construct(); + + $this->manager = $manager; + $this->userManager = $userManager; + $this->groupManager = $groupManager; + } + /** * @param Room $room * @param string $name @@ -169,11 +195,9 @@ trait TRoomCommand { return; } - $groupManager = \OC::$server->getGroupManager(); - $users = []; foreach ($groupIds as $groupId) { - $group = $groupManager->get($groupId); + $group = $this->groupManager->get($groupId); if ($group === null) { throw new InvalidArgumentException(sprintf("Group '%s' not found.", $groupId)); } @@ -199,11 +223,9 @@ trait TRoomCommand { return; } - $userManager = \OC::$server->getUserManager(); - $participants = []; foreach ($userIds as $userId) { - $user = $userManager->get($userId); + $user = $this->userManager->get($userId); if ($user === null) { throw new InvalidArgumentException(sprintf("User '%s' not found.", $userId)); } @@ -237,8 +259,6 @@ trait TRoomCommand { * @throws InvalidArgumentException */ protected function removeRoomParticipants(Room $room, array $userIds): void { - $userManager = \OC::$server->getUserManager(); - $users = []; foreach ($userIds as $userId) { try { @@ -247,7 +267,7 @@ trait TRoomCommand { throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId)); } - $users[] = $userManager->get($userId); + $users[] = $this->userManager->get($userId); } foreach ($users as $user) { @@ -306,25 +326,21 @@ trait TRoomCommand { } protected function completeTokenValues(CompletionContext $context): array { - /** @var Manager $roomManager */ - $roomManager = \OC::$server->query(Manager::class); return array_map(function (Room $room) { return $room->getToken(); - }, $roomManager->searchRoomsByToken($context->getCurrentWord())); + }, $this->manager->searchRoomsByToken($context->getCurrentWord())); } protected function completeUserValues(CompletionContext $context): array { - $userManager = \OC::$server->getUserManager(); return array_map(function (IUser $user) { return $user->getUID(); - }, $userManager->search($context->getCurrentWord())); + }, $this->userManager->search($context->getCurrentWord())); } protected function completeGroupValues(CompletionContext $context): array { - $groupManager = \OC::$server->getGroupManager(); return array_map(function (IGroup $group) { return $group->getGID(); - }, $groupManager->search($context->getCurrentWord())); + }, $this->groupManager->search($context->getCurrentWord())); } protected function completeParticipantValues(CompletionContext $context): array { @@ -347,11 +363,8 @@ trait TRoomCommand { return []; } - /** @var Manager $roomManager */ - $roomManager = \OC::$server->query(Manager::class); - try { - $room = $roomManager->getRoomByToken($token); + $room = $this->manager->getRoomByToken($token); } catch (RoomNotFoundException $e) { return []; } diff --git a/lib/Command/Room/Update.php b/lib/Command/Room/Update.php index 1a769a5da..48bbf1748 100644 --- a/lib/Command/Room/Update.php +++ b/lib/Command/Room/Update.php @@ -28,7 +28,6 @@ namespace OCA\Talk\Command\Room; use InvalidArgumentException; use OC\Core\Command\Base; use OCA\Talk\Exceptions\RoomNotFoundException; -use OCA\Talk\Manager; use OCA\Talk\Room; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; @@ -39,15 +38,6 @@ use Symfony\Component\Console\Output\OutputInterface; class Update extends Base { use TRoomCommand; - /** @var Manager */ - public $manager; - - public function __construct(Manager $manager) { - parent::__construct(); - - $this->manager = $manager; - } - protected function configure(): void { $this ->setName('talk:room:update') -- cgit v1.2.3