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
path: root/lib
diff options
context:
space:
mode:
authorDaniel Rudolf <github.com@daniel-rudolf.de>2020-06-02 22:46:01 +0300
committerDaniel Rudolf <github.com@daniel-rudolf.de>2020-06-02 22:46:01 +0300
commitcebcfefac84715dfe4a88264b0622df5c939cfec (patch)
treeab830a33ec1961195c61d1f1fe1b0a74611e1ff8 /lib
parent08b7bf8b2f91b5b53e01f9e59db9a5c6b69d48a1 (diff)
parent0b13f861f82dd17d2b789f20884b5a4a67c01a6d (diff)
Merge branch 'feature/cmd-room-followup' into feature/cmd-room-followup-backport19
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/Room/Add.php48
-rw-r--r--lib/Command/Room/Create.php45
-rw-r--r--lib/Command/Room/Delete.php20
-rw-r--r--lib/Command/Room/Demote.php34
-rw-r--r--lib/Command/Room/Promote.php34
-rw-r--r--lib/Command/Room/Remove.php40
-rw-r--r--lib/Command/Room/TRoomCommand.php134
-rw-r--r--lib/Command/Room/Update.php42
-rw-r--r--lib/Manager.php37
-rw-r--r--lib/Room.php32
10 files changed, 286 insertions, 180 deletions
diff --git a/lib/Command/Room/Add.php b/lib/Command/Room/Add.php
index c48755aa4..d5d0b7338 100644
--- a/lib/Command/Room/Add.php
+++ b/lib/Command/Room/Add.php
@@ -25,12 +25,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 Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -39,19 +38,6 @@ 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) {
- parent::__construct();
-
- $this->userManager = $userManager;
- $this->manager = $manager;
- }
-
protected function configure(): void {
$this
->setName('talk:room:add')
@@ -70,11 +56,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'
);
}
@@ -82,7 +63,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);
@@ -99,8 +79,7 @@ class Add extends Base {
try {
$this->addRoomParticipants($room, $users);
$this->addRoomParticipantsByGroup($room, $groups);
- $this->addRoomParticipantsByCircle($room, $circles);
- } catch (Exception $e) {
+ } catch (InvalidArgumentException $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
return 1;
}
@@ -108,4 +87,25 @@ class Add extends Base {
$output->writeln('<info>Users successfully added to room.</info>');
return 0;
}
+
+ public function completeOptionValues($optionName, CompletionContext $context) {
+ switch ($optionName) {
+ case 'user':
+ return $this->completeUserValues($context);
+
+ case 'group':
+ return $this->completeGroupValues($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 bc708d838..f96ef7dd5 100644
--- a/lib/Command/Room/Create.php
+++ b/lib/Command/Room/Create.php
@@ -25,10 +25,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 Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -37,19 +36,6 @@ 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) {
- parent::__construct();
-
- $this->userManager = $userManager;
- $this->manager = $manager;
- }
-
protected function configure(): void {
$this
->setName('talk:room:create')
@@ -69,11 +55,6 @@ class Create extends Base {
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,
InputOption::VALUE_NONE,
@@ -105,7 +86,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');
@@ -114,7 +94,7 @@ class Create extends Base {
$name = trim($name);
if (!$this->validateRoomName($name)) {
- $output->writeln("<error>Invalid room name.</error>");
+ $output->writeln('<error>Invalid room name.</error>');
return 1;
}
@@ -129,13 +109,12 @@ class Create extends Base {
$this->addRoomParticipants($room, $users);
$this->addRoomParticipantsByGroup($room, $groups);
- $this->addRoomParticipantsByCircle($room, $circles);
$this->addRoomModerators($room, $moderators);
if ($owner !== null) {
$this->setRoomOwner($room, $owner);
}
- } catch (Exception $e) {
+ } catch (InvalidArgumentException $e) {
$room->deleteRoom();
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
@@ -145,4 +124,20 @@ class Create extends Base {
$output->writeln('<info>Room successfully created.</info>');
return 0;
}
+
+ public function completeOptionValues($optionName, CompletionContext $context) {
+ switch ($optionName) {
+ case 'user':
+ return $this->completeUserValues($context);
+
+ case 'group':
+ return $this->completeGroupValues($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..34b767cc3 100644
--- a/lib/Command/Room/Delete.php
+++ b/lib/Command/Room/Delete.php
@@ -27,21 +27,14 @@ 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;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Delete extends Base {
- /** @var Manager */
- public $manager;
-
- public function __construct(Manager $manager) {
- parent::__construct();
-
- $this->manager = $manager;
- }
+ use TRoomCommand;
protected function configure(): void {
$this
@@ -74,4 +67,13 @@ class Delete extends Base {
$output->writeln('<info>Room successfully deleted.</info>');
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 9bdb607db..e510f311b 100644
--- a/lib/Command/Room/Demote.php
+++ b/lib/Command/Room/Demote.php
@@ -25,12 +25,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 Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -38,19 +37,6 @@ 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) {
- parent::__construct();
-
- $this->userManager = $userManager;
- $this->manager = $manager;
- }
-
protected function configure(): void {
$this
->setName('talk:room:demote')
@@ -84,12 +70,24 @@ class Demote extends Base {
try {
$this->removeRoomModerators($room, $users);
- } catch (Exception $e) {
+ } catch (InvalidArgumentException $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
return 1;
}
- $output->writeln('<info>Users successfully remove from room.</info>');
+ $output->writeln('<info>Participants successfully demoted to regular users.</info>');
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 44b378c74..613d8d0b7 100644
--- a/lib/Command/Room/Promote.php
+++ b/lib/Command/Room/Promote.php
@@ -25,12 +25,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 Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -38,19 +37,6 @@ 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) {
- parent::__construct();
-
- $this->userManager = $userManager;
- $this->manager = $manager;
- }
-
protected function configure(): void {
$this
->setName('talk:room:promote')
@@ -84,12 +70,24 @@ class Promote extends Base {
try {
$this->addRoomModerators($room, $users);
- } catch (Exception $e) {
+ } catch (InvalidArgumentException $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
return 1;
}
- $output->writeln('<info>Users successfully added to room.</info>');
+ $output->writeln('<info>Participants successfully promoted to moderators.</info>');
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 aeb7313a6..b3cc192d2 100644
--- a/lib/Command/Room/Remove.php
+++ b/lib/Command/Room/Remove.php
@@ -25,12 +25,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 Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -38,19 +37,6 @@ 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) {
- parent::__construct();
-
- $this->userManager = $userManager;
- $this->manager = $manager;
- }
-
protected function configure(): void {
$this
->setName('talk:room:remove')
@@ -60,15 +46,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);
@@ -84,12 +70,24 @@ class Remove extends Base {
try {
$this->removeRoomParticipants($room, $users);
- } catch (Exception $e) {
+ } catch (InvalidArgumentException $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
return 1;
}
- $output->writeln('<info>Users successfully remove from room.</info>');
+ $output->writeln('<info>Users successfully removed from room.</info>');
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 1baf70793..cb8bb2daa 100644
--- a/lib/Command/Room/TRoomCommand.php
+++ b/lib/Command/Room/TRoomCommand.php
@@ -26,14 +26,44 @@ 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\Exceptions\RoomNotFoundException;
+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
@@ -136,6 +166,8 @@ trait TRoomCommand {
throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId));
}
+ $this->unsetRoomOwner($room);
+
$room->setParticipantType($participant, Participant::OWNER);
}
@@ -163,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));
}
@@ -184,43 +214,6 @@ trait TRoomCommand {
/**
* @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
*
* @throws InvalidArgumentException
@@ -230,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));
}
@@ -268,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 {
@@ -278,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) {
@@ -335,4 +324,53 @@ trait TRoomCommand {
$room->setParticipantType($participant, Participant::USER);
}
}
+
+ protected function completeTokenValues(CompletionContext $context): array {
+ return array_map(function (Room $room) {
+ return $room->getToken();
+ }, $this->manager->searchRoomsByToken($context->getCurrentWord()));
+ }
+
+ protected function completeUserValues(CompletionContext $context): array {
+ return array_map(function (IUser $user) {
+ return $user->getUID();
+ }, $this->userManager->search($context->getCurrentWord()));
+ }
+
+ protected function completeGroupValues(CompletionContext $context): array {
+ return array_map(function (IGroup $group) {
+ return $group->getGID();
+ }, $this->groupManager->search($context->getCurrentWord()));
+ }
+
+ 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 [];
+ }
+
+ try {
+ $room = $this->manager->getRoomByToken($token);
+ } catch (RoomNotFoundException $e) {
+ return [];
+ }
+
+ return array_map(function (Participant $participant) {
+ return $participant->getUser();
+ }, $room->searchParticipants($context->getCurrentWord()));
+ }
}
diff --git a/lib/Command/Room/Update.php b/lib/Command/Room/Update.php
index a75dd6a7f..48bbf1748 100644
--- a/lib/Command/Room/Update.php
+++ b/lib/Command/Room/Update.php
@@ -25,12 +25,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 Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -39,19 +38,6 @@ 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) {
- parent::__construct();
-
- $this->userManager = $userManager;
- $this->manager = $manager;
- }
-
protected function configure(): void {
$this
->setName('talk:room:update')
@@ -142,7 +128,7 @@ class Update extends Base {
$this->unsetRoomOwner($room);
}
}
- } catch (Exception $e) {
+ } catch (InvalidArgumentException $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
return 1;
}
@@ -150,4 +136,26 @@ class Update extends Base {
$output->writeln('<info>Room successfully updated.</info>');
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);
+ }
}
diff --git a/lib/Manager.php b/lib/Manager.php
index 43c4bf180..c96e5f2c8 100644
--- a/lib/Manager.php
+++ b/lib/Manager.php
@@ -225,6 +225,43 @@ class Manager {
}
/**
+ * @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('*')
+ ->from('talk_rooms')
+ ->setMaxResults(1);
+
+ if ($searchToken !== '') {
+ $query->where($query->expr()->iLike('token', $query->createNamedParameter(
+ '%' . $this->db->escapeLikeParameter($searchToken) . '%'
+ )));
+ }
+
+ $query->setMaxResults($limit)
+ ->setFirstResult($offset)
+ ->orderBy('token', 'ASC');
+ $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
* @return Room[]
diff --git a/lib/Room.php b/lib/Room.php
index d087a2112..d3e9795af 100644
--- a/lib/Room.php
+++ b/lib/Room.php
@@ -1016,6 +1016,38 @@ class Room {
}
/**
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return Participant[]
+ */
+ 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 ($search !== '') {
+ $query->where($query->expr()->iLike('user_id', $query->createNamedParameter(
+ '%' . $this->db->escapeLikeParameter($search) . '%'
+ )));
+ }
+
+ $query->setMaxResults($limit)
+ ->setFirstResult($offset)
+ ->orderBy('user_id', 'ASC');
+ $result = $query->execute();
+
+ $participants = [];
+ while ($row = $result->fetch()) {
+ $participants[] = $this->manager->createParticipantObject($this, $row);
+ }
+ $result->closeCursor();
+
+ return $participants;
+ }
+
+ /**
* @return Participant[]
*/
public function getParticipantsInCall(): array {