UPSTREAM BASELINE: nextcloud/spreed v22.0.12 (без изменений)
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Источник: https://github.com/nextcloud/spreed/archive/refs/tags/v22.0.12.tar.gz С этого коммита ветка официального Nextcloud Talk отрезана (решение владельца 2026-07-06). Все дальнейшие изменения — только наши; версии релизов: 22.0.12-f7.N.
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Command\Room;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OC\Core\Command\Base;
|
||||
use OCA\Talk\Exceptions\RoomNotFoundException;
|
||||
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;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class Add extends Base {
|
||||
use TRoomCommand;
|
||||
|
||||
#[\Override]
|
||||
protected function configure(): void {
|
||||
$this
|
||||
->setName('talk:room:add')
|
||||
->setDescription('Adds users to a room')
|
||||
->addArgument(
|
||||
'token',
|
||||
InputArgument::REQUIRED,
|
||||
'Token of the room to add users to'
|
||||
)->addOption(
|
||||
'user',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
|
||||
'Invites the given users to the room'
|
||||
)->addOption(
|
||||
'group',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
|
||||
'Invites all members of the given groups to the room'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$token = $input->getArgument('token');
|
||||
$users = $input->getOption('user');
|
||||
$groups = $input->getOption('group');
|
||||
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($token);
|
||||
} catch (RoomNotFoundException $e) {
|
||||
$output->writeln('<error>Room not found.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($room->isFederatedConversation()) {
|
||||
$output->writeln('<error>Room is a federated conversation.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (in_array($room->getType(), [Room::TYPE_ONE_TO_ONE, Room::TYPE_ONE_TO_ONE_FORMER], true)) {
|
||||
$output->writeln('<error>Room is a private (1 to 1) conversation.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->addRoomParticipants($room, $users);
|
||||
$this->addRoomParticipantsByGroup($room, $groups);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln('<info>Users successfully added to room.</info>');
|
||||
return 0;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
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);
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function completeArgumentValues($argumentName, CompletionContext $context) {
|
||||
switch ($argumentName) {
|
||||
case 'token':
|
||||
return $this->completeTokenValues($context);
|
||||
}
|
||||
|
||||
return parent::completeArgumentValues($argumentName, $context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Command\Room;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OC\Core\Command\Base;
|
||||
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;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class Create extends Base {
|
||||
use TRoomCommand;
|
||||
|
||||
#[\Override]
|
||||
protected function configure(): void {
|
||||
$this
|
||||
->setName('talk:room:create')
|
||||
->setDescription('Create a new room')
|
||||
->addArgument(
|
||||
'name',
|
||||
InputArgument::REQUIRED,
|
||||
'The name of the room to create'
|
||||
)->addOption(
|
||||
'description',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'The description of the room to create'
|
||||
)->addOption(
|
||||
'user',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
|
||||
'Invites the given users to the room to create'
|
||||
)->addOption(
|
||||
'group',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
|
||||
'Invites all members of the given group to the room to create'
|
||||
)->addOption(
|
||||
'public',
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
'Creates the room as public room if set'
|
||||
)->addOption(
|
||||
'readonly',
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
'Creates the room with read-only access only if set'
|
||||
)->addOption(
|
||||
'listable',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Creates the room with the given listable scope'
|
||||
)->addOption(
|
||||
'password',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Protects the room to create with the given password'
|
||||
)->addOption(
|
||||
'owner',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Sets the given user as owner of the room to create'
|
||||
)->addOption(
|
||||
'moderator',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
|
||||
'Promotes the given users to moderators'
|
||||
)->addOption(
|
||||
'message-expiration',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Seconds to expire a message after sent. If zero will disable the expire message duration.'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$name = $input->getArgument('name');
|
||||
$description = $input->getOption('description');
|
||||
$users = $input->getOption('user');
|
||||
$groups = $input->getOption('group');
|
||||
$public = $input->getOption('public');
|
||||
$readonly = $input->getOption('readonly');
|
||||
$listable = $input->getOption('listable');
|
||||
$password = $input->getOption('password');
|
||||
$owner = $input->getOption('owner');
|
||||
$moderators = $input->getOption('moderator');
|
||||
$messageExpiration = $input->getOption('message-expiration');
|
||||
|
||||
if (!in_array($listable, [
|
||||
null,
|
||||
(string)Room::LISTABLE_NONE,
|
||||
(string)Room::LISTABLE_USERS,
|
||||
(string)Room::LISTABLE_ALL,
|
||||
], true)) {
|
||||
$output->writeln('<error>Invalid value for option "--listable" given.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$roomType = $public ? Room::TYPE_PUBLIC : Room::TYPE_GROUP;
|
||||
try {
|
||||
$room = $this->roomService->createConversation($roomType, $name);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
if ($e->getMessage() === 'name') {
|
||||
$output->writeln('<error>Invalid room name.</error>');
|
||||
return 1;
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
try {
|
||||
if ($description !== null) {
|
||||
$this->setRoomDescription($room, $description);
|
||||
}
|
||||
|
||||
$this->setRoomReadOnly($room, $readonly);
|
||||
$this->setRoomListable($room, (int)$listable);
|
||||
|
||||
if ($password !== null) {
|
||||
$this->setRoomPassword($room, $password);
|
||||
}
|
||||
|
||||
$this->addRoomParticipants($room, $users);
|
||||
$this->addRoomParticipantsByGroup($room, $groups);
|
||||
$this->addRoomModerators($room, $moderators);
|
||||
|
||||
if ($owner !== null) {
|
||||
$this->setRoomOwner($room, $owner);
|
||||
}
|
||||
|
||||
if ($messageExpiration !== null) {
|
||||
$this->setMessageExpiration($room, (int)$messageExpiration);
|
||||
}
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$this->roomService->deleteRoom($room);
|
||||
|
||||
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
|
||||
return 1;
|
||||
}
|
||||
$output->writeln('Room token: ' . $room->getToken());
|
||||
|
||||
$output->writeln('<info>Room successfully created.</info>');
|
||||
return 0;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
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);
|
||||
case 'readonly':
|
||||
return [(string)Room::READ_ONLY, (string)Room::READ_WRITE];
|
||||
case 'listable':
|
||||
return [
|
||||
(string)Room::LISTABLE_ALL,
|
||||
(string)Room::LISTABLE_USERS,
|
||||
(string)Room::LISTABLE_NONE,
|
||||
];
|
||||
}
|
||||
|
||||
return parent::completeOptionValues($optionName, $context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Command\Room;
|
||||
|
||||
use OC\Core\Command\Base;
|
||||
use OCA\Talk\Exceptions\RoomNotFoundException;
|
||||
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;
|
||||
|
||||
#[\Override]
|
||||
protected function configure(): void {
|
||||
$this
|
||||
->setName('talk:room:delete')
|
||||
->setDescription('Deletes a room')
|
||||
->addArgument(
|
||||
'token',
|
||||
InputArgument::REQUIRED,
|
||||
'Token of the room to delete'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$token = $input->getArgument('token');
|
||||
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($token);
|
||||
} catch (RoomNotFoundException $e) {
|
||||
$output->writeln('<error>Room not found.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($room->isFederatedConversation()) {
|
||||
$output->writeln('<error>Room is a federated conversation.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (in_array($room->getType(), [Room::TYPE_ONE_TO_ONE], true)) {
|
||||
$output->writeln('<error>Room is a private (1 to 1) conversation.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->roomService->deleteRoom($room);
|
||||
|
||||
$output->writeln('<info>Room successfully deleted.</info>');
|
||||
return 0;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function completeArgumentValues($argumentName, CompletionContext $context) {
|
||||
switch ($argumentName) {
|
||||
case 'token':
|
||||
return $this->completeTokenValues($context);
|
||||
}
|
||||
|
||||
return parent::completeArgumentValues($argumentName, $context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Command\Room;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OC\Core\Command\Base;
|
||||
use OCA\Talk\Exceptions\RoomNotFoundException;
|
||||
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 Demote extends Base {
|
||||
use TRoomCommand;
|
||||
|
||||
#[\Override]
|
||||
protected function configure(): void {
|
||||
$this
|
||||
->setName('talk:room:demote')
|
||||
->setDescription('Demotes participants of a room to regular users')
|
||||
->addArgument(
|
||||
'token',
|
||||
InputArgument::REQUIRED,
|
||||
'Token of the room in which users should be demoted'
|
||||
)->addArgument(
|
||||
'participant',
|
||||
InputArgument::REQUIRED | InputArgument::IS_ARRAY,
|
||||
'Demotes the given participants of the room to regular users'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$token = $input->getArgument('token');
|
||||
$users = $input->getArgument('participant');
|
||||
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($token);
|
||||
} catch (RoomNotFoundException $e) {
|
||||
$output->writeln('<error>Room not found.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($room->isFederatedConversation()) {
|
||||
$output->writeln('<error>Room is a federated conversation.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (in_array($room->getType(), [Room::TYPE_ONE_TO_ONE, Room::TYPE_ONE_TO_ONE_FORMER], true)) {
|
||||
$output->writeln('<error>Room is a private (1 to 1) conversation.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->removeRoomModerators($room, $users);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln('<info>Participants successfully demoted to regular users.</info>');
|
||||
return 0;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Command\Room;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OC\Core\Command\Base;
|
||||
use OCA\Talk\Exceptions\RoomNotFoundException;
|
||||
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 Promote extends Base {
|
||||
use TRoomCommand;
|
||||
|
||||
#[\Override]
|
||||
protected function configure(): void {
|
||||
$this
|
||||
->setName('talk:room:promote')
|
||||
->setDescription('Promotes participants of a room to moderators')
|
||||
->addArgument(
|
||||
'token',
|
||||
InputArgument::REQUIRED,
|
||||
'Token of the room in which users should be promoted'
|
||||
)->addArgument(
|
||||
'participant',
|
||||
InputArgument::REQUIRED | InputArgument::IS_ARRAY,
|
||||
'Promotes the given participants of the room to moderators'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$token = $input->getArgument('token');
|
||||
$users = $input->getArgument('participant');
|
||||
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($token);
|
||||
} catch (RoomNotFoundException $e) {
|
||||
$output->writeln('<error>Room not found.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($room->isFederatedConversation()) {
|
||||
$output->writeln('<error>Room is a federated conversation.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (in_array($room->getType(), [Room::TYPE_ONE_TO_ONE, Room::TYPE_ONE_TO_ONE_FORMER], true)) {
|
||||
$output->writeln('<error>Room is a private (1 to 1) conversation.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->addRoomModerators($room, $users);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln('<info>Participants successfully promoted to moderators.</info>');
|
||||
return 0;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Command\Room;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OC\Core\Command\Base;
|
||||
use OCA\Talk\Exceptions\RoomNotFoundException;
|
||||
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 Remove extends Base {
|
||||
use TRoomCommand;
|
||||
|
||||
#[\Override]
|
||||
protected function configure(): void {
|
||||
$this
|
||||
->setName('talk:room:remove')
|
||||
->setDescription('Remove users from a room')
|
||||
->addArgument(
|
||||
'token',
|
||||
InputArgument::REQUIRED,
|
||||
'Token of the room to remove users from'
|
||||
)->addArgument(
|
||||
'participant',
|
||||
InputArgument::REQUIRED | InputArgument::IS_ARRAY,
|
||||
'Removes the given participants from the room'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$token = $input->getArgument('token');
|
||||
$users = $input->getArgument('participant');
|
||||
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($token);
|
||||
} catch (RoomNotFoundException $e) {
|
||||
$output->writeln('<error>Room not found.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($room->isFederatedConversation()) {
|
||||
$output->writeln('<error>Room is a federated conversation.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (in_array($room->getType(), [Room::TYPE_ONE_TO_ONE, Room::TYPE_ONE_TO_ONE_FORMER], true)) {
|
||||
$output->writeln('<error>Room is a private (1 to 1) conversation.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->removeRoomParticipants($room, $users);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln('<info>Users successfully removed from room.</info>');
|
||||
return 0;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,417 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Command\Room;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OCA\Talk\Events\AAttendeeRemovedEvent;
|
||||
use OCA\Talk\Exceptions\ParticipantNotFoundException;
|
||||
use OCA\Talk\Exceptions\RoomNotFoundException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\DescriptionException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\ListableException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\MessageExpirationException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\NameException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\PasswordException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\ReadOnlyException;
|
||||
use OCA\Talk\Exceptions\RoomProperty\TypeException;
|
||||
use OCA\Talk\Manager;
|
||||
use OCA\Talk\MatterbridgeManager;
|
||||
use OCA\Talk\Model\Attendee;
|
||||
use OCA\Talk\Participant;
|
||||
use OCA\Talk\Room;
|
||||
use OCA\Talk\Service\ParticipantService;
|
||||
use OCA\Talk\Service\RoomService;
|
||||
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 {
|
||||
|
||||
public function __construct(
|
||||
protected Manager $manager,
|
||||
protected RoomService $roomService,
|
||||
protected ParticipantService $participantService,
|
||||
protected IUserManager $userManager,
|
||||
protected IGroupManager $groupManager,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param string $name
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function setRoomName(Room $room, string $name): void {
|
||||
$name = trim($name);
|
||||
if ($name === $room->getName()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->validateRoomName($name)) {
|
||||
throw new InvalidArgumentException('Invalid room name.');
|
||||
}
|
||||
|
||||
try {
|
||||
$this->roomService->setName($room, $name);
|
||||
} catch (NameException) {
|
||||
throw new InvalidArgumentException('Unable to change room name.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function validateRoomName(string $name): bool {
|
||||
$name = trim($name);
|
||||
return (($name !== '') && !isset($name[255]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param string $description
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function setRoomDescription(Room $room, string $description): void {
|
||||
try {
|
||||
$this->roomService->setDescription($room, $description);
|
||||
} catch (DescriptionException $e) {
|
||||
throw new InvalidArgumentException('Invalid room description.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param bool $public
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function setRoomPublic(Room $room, bool $public): void {
|
||||
if ($public === ($room->getType() === Room::TYPE_PUBLIC)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->roomService->setType($room, $public ? Room::TYPE_PUBLIC : Room::TYPE_GROUP);
|
||||
} catch (TypeException) {
|
||||
throw new InvalidArgumentException('Unable to change room type.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param bool $readOnly
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function setRoomReadOnly(Room $room, bool $readOnly): void {
|
||||
if ($readOnly === ($room->getReadOnly() === Room::READ_ONLY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->roomService->setReadOnly($room, $readOnly ? Room::READ_ONLY : Room::READ_WRITE);
|
||||
} catch (ReadOnlyException) {
|
||||
throw new InvalidArgumentException('Unable to change room state.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param int $listable
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function setRoomListable(Room $room, int $listable): void {
|
||||
if ($room->getListable() === $listable) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->roomService->setListable($room, $listable);
|
||||
} catch (ListableException) {
|
||||
throw new InvalidArgumentException('Unable to change room state.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param string $password
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function setRoomPassword(Room $room, string $password): void {
|
||||
if ($room->hasPassword() ? $this->roomService->verifyPassword($room, $password)['result'] : ($password === '')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (($password !== '') && ($room->getType() !== Room::TYPE_PUBLIC)) {
|
||||
throw new InvalidArgumentException('Unable to add password protection to private room.');
|
||||
}
|
||||
|
||||
try {
|
||||
$this->roomService->setPassword($room, $password);
|
||||
} catch (PasswordException $e) {
|
||||
if ($e->getReason() === PasswordException::REASON_VALUE) {
|
||||
throw new InvalidArgumentException($e->getHint());
|
||||
}
|
||||
throw new InvalidArgumentException('Unable to change room password.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param string $userId
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function setRoomOwner(Room $room, string $userId): void {
|
||||
try {
|
||||
$participant = $this->participantService->getParticipant($room, $userId, false);
|
||||
} catch (ParticipantNotFoundException $e) {
|
||||
throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId));
|
||||
}
|
||||
|
||||
if ($userId === MatterbridgeManager::BRIDGE_BOT_USERID) {
|
||||
throw new InvalidArgumentException('Can not promote the bridge-bot user.');
|
||||
}
|
||||
|
||||
$this->unsetRoomOwner($room);
|
||||
|
||||
$this->participantService->updateParticipantType($room, $participant, Participant::OWNER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function unsetRoomOwner(Room $room): void {
|
||||
$participants = $this->participantService->getParticipantsForRoom($room);
|
||||
foreach ($participants as $participant) {
|
||||
if ($participant->getAttendee()->getParticipantType() === Participant::OWNER) {
|
||||
$this->participantService->updateParticipantType($room, $participant, Participant::USER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param string[] $groupIds
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function addRoomParticipantsByGroup(Room $room, array $groupIds): void {
|
||||
if (!$groupIds) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($groupIds as $groupId) {
|
||||
$group = $this->groupManager->get($groupId);
|
||||
if ($group === null) {
|
||||
throw new InvalidArgumentException(sprintf("Group '%s' not found.", $groupId));
|
||||
}
|
||||
|
||||
$this->participantService->addGroup($room, $group);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param string[] $userIds
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function addRoomParticipants(Room $room, array $userIds): void {
|
||||
if (!$userIds) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var array<string, array{actorType: string, actorId: string, displayName: string}> $participants */
|
||||
$participants = [];
|
||||
foreach ($userIds as $userId) {
|
||||
if ($userId === MatterbridgeManager::BRIDGE_BOT_USERID) {
|
||||
throw new InvalidArgumentException('Can not add the bridge-bot user.');
|
||||
}
|
||||
|
||||
$user = $this->userManager->get($userId);
|
||||
if ($user === null) {
|
||||
throw new InvalidArgumentException(sprintf("User '%s' not found.", $userId));
|
||||
}
|
||||
|
||||
if (isset($participants[$user->getUID()])) {
|
||||
// nothing to do, user is going to be a participant already
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->participantService->getParticipant($room, $user->getUID(), false);
|
||||
|
||||
// nothing to do, user is a participant already
|
||||
continue;
|
||||
} catch (ParticipantNotFoundException $e) {
|
||||
// we expect the user not to be a participant yet
|
||||
}
|
||||
|
||||
$participants[$user->getUID()] = [
|
||||
'actorType' => Attendee::ACTOR_USERS,
|
||||
'actorId' => $user->getUID(),
|
||||
'displayName' => $user->getDisplayName(),
|
||||
];
|
||||
}
|
||||
|
||||
$this->participantService->addUsers($room, $participants);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param string[] $userIds
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function removeRoomParticipants(Room $room, array $userIds): void {
|
||||
$users = [];
|
||||
foreach ($userIds as $userId) {
|
||||
try {
|
||||
$this->participantService->getParticipant($room, $userId, false);
|
||||
} catch (ParticipantNotFoundException $e) {
|
||||
throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId));
|
||||
}
|
||||
|
||||
$users[] = $this->userManager->get($userId);
|
||||
}
|
||||
|
||||
foreach ($users as $user) {
|
||||
$this->participantService->removeUser($room, $user, AAttendeeRemovedEvent::REASON_REMOVED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param string[] $userIds
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function addRoomModerators(Room $room, array $userIds): void {
|
||||
$participants = [];
|
||||
foreach ($userIds as $userId) {
|
||||
if ($userId === MatterbridgeManager::BRIDGE_BOT_USERID) {
|
||||
throw new InvalidArgumentException('Can not promote the bridge-bot user.');
|
||||
}
|
||||
|
||||
try {
|
||||
$participant = $this->participantService->getParticipant($room, $userId, false);
|
||||
} catch (ParticipantNotFoundException $e) {
|
||||
throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId));
|
||||
}
|
||||
|
||||
if ($participant->getAttendee()->getParticipantType() !== Participant::OWNER) {
|
||||
$participants[] = $participant;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($participants as $participant) {
|
||||
$this->participantService->updateParticipantType($room, $participant, Participant::MODERATOR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param string[] $userIds
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function removeRoomModerators(Room $room, array $userIds): void {
|
||||
$participants = [];
|
||||
foreach ($userIds as $userId) {
|
||||
try {
|
||||
$participant = $this->participantService->getParticipant($room, $userId, false);
|
||||
} catch (ParticipantNotFoundException $e) {
|
||||
throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId));
|
||||
}
|
||||
|
||||
if ($participant->getAttendee()->getParticipantType() === Participant::MODERATOR) {
|
||||
$participants[] = $participant;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($participants as $participant) {
|
||||
$this->participantService->updateParticipantType($room, $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) {
|
||||
if ($user->getUID() === MatterbridgeManager::BRIDGE_BOT_USERID) {
|
||||
return '';
|
||||
}
|
||||
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_filter($this->participantService->getParticipantUserIds($room), static function ($userId) use ($context) {
|
||||
return stripos($userId, $context->getCurrentWord()) !== false;
|
||||
});
|
||||
}
|
||||
|
||||
protected function setMessageExpiration(Room $room, int $seconds): void {
|
||||
try {
|
||||
$this->roomService->setMessageExpiration($room, $seconds);
|
||||
} catch (MessageExpirationException) {
|
||||
throw new InvalidArgumentException('Unable to change message expiration.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Command\Room;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OC\Core\Command\Base;
|
||||
use OCA\Talk\Exceptions\RoomNotFoundException;
|
||||
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;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class Update extends Base {
|
||||
use TRoomCommand;
|
||||
|
||||
#[\Override]
|
||||
protected function configure(): void {
|
||||
$this
|
||||
->setName('talk:room:update')
|
||||
->setDescription('Updates a room')
|
||||
->addArgument(
|
||||
'token',
|
||||
InputArgument::REQUIRED,
|
||||
'The token of the room to update'
|
||||
)->addOption(
|
||||
'name',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Sets a new name for the room'
|
||||
)->addOption(
|
||||
'description',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Sets a new description for the room'
|
||||
)->addOption(
|
||||
'public',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Modifies the room to be a public room (value 1) or private room (value 0)'
|
||||
)->addOption(
|
||||
'readonly',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Modifies the room to be read-only (value 1) or read-write (value 0)'
|
||||
)->addOption(
|
||||
'listable',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Modifies the room\'s listable scope'
|
||||
)->addOption(
|
||||
'password',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Sets a new password for the room; pass an empty value to remove password protection'
|
||||
)->addOption(
|
||||
'owner',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Sets the given user as owner of the room; pass an empty value to remove the owner'
|
||||
)->addOption(
|
||||
'message-expiration',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Seconds to expire a message after sent. If zero will disable the expire message duration.'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$token = $input->getArgument('token');
|
||||
$name = $input->getOption('name');
|
||||
$description = $input->getOption('description');
|
||||
$public = $input->getOption('public');
|
||||
$readOnly = $input->getOption('readonly');
|
||||
$listable = $input->getOption('listable');
|
||||
$password = $input->getOption('password');
|
||||
$owner = $input->getOption('owner');
|
||||
$messageExpiration = $input->getOption('message-expiration');
|
||||
|
||||
if (!in_array($public, [null, '0', '1'], true)) {
|
||||
$output->writeln('<error>Invalid value for option "--public" given.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!in_array($readOnly, [null, (string)Room::READ_WRITE, (string)Room::READ_ONLY], true)) {
|
||||
$output->writeln('<error>Invalid value for option "--readonly" given.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!in_array($listable, [
|
||||
null,
|
||||
(string)Room::LISTABLE_NONE,
|
||||
(string)Room::LISTABLE_USERS,
|
||||
(string)Room::LISTABLE_ALL,
|
||||
], true)) {
|
||||
$output->writeln('<error>Invalid value for option "--listable" given.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
$room = $this->manager->getRoomByToken($token);
|
||||
} catch (RoomNotFoundException $e) {
|
||||
$output->writeln('<error>Room not found.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($room->isFederatedConversation()) {
|
||||
$output->writeln('<error>Room is a federated conversation.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (in_array($room->getType(), [Room::TYPE_ONE_TO_ONE, Room::TYPE_ONE_TO_ONE_FORMER], true)) {
|
||||
$output->writeln('<error>Room is a private (1 to 1) conversation.</error>');
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
if ($name !== null) {
|
||||
$this->setRoomName($room, $name);
|
||||
}
|
||||
|
||||
if ($description !== null) {
|
||||
$this->setRoomDescription($room, $description);
|
||||
}
|
||||
|
||||
if ($public !== null) {
|
||||
$this->setRoomPublic($room, ($public === '1'));
|
||||
}
|
||||
|
||||
if ($readOnly !== null) {
|
||||
$this->setRoomReadOnly($room, ($readOnly === '1'));
|
||||
}
|
||||
|
||||
if ($listable !== null) {
|
||||
$this->setRoomListable($room, (int)$listable);
|
||||
}
|
||||
|
||||
if ($password !== null) {
|
||||
$this->setRoomPassword($room, $password);
|
||||
}
|
||||
|
||||
if ($owner !== null) {
|
||||
if ($owner !== '') {
|
||||
$this->setRoomOwner($room, $owner);
|
||||
} else {
|
||||
$this->unsetRoomOwner($room);
|
||||
}
|
||||
}
|
||||
|
||||
if ($messageExpiration !== null) {
|
||||
$this->setMessageExpiration($room, (int)$messageExpiration);
|
||||
}
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln('<info>Room successfully updated.</info>');
|
||||
return 0;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function completeOptionValues($optionName, CompletionContext $context) {
|
||||
switch ($optionName) {
|
||||
case 'public':
|
||||
case 'readonly':
|
||||
return [(string)Room::READ_ONLY, (string)Room::READ_WRITE];
|
||||
case 'listable':
|
||||
return [
|
||||
(string)Room::LISTABLE_ALL,
|
||||
(string)Room::LISTABLE_USERS,
|
||||
(string)Room::LISTABLE_NONE,
|
||||
];
|
||||
|
||||
case 'owner':
|
||||
return $this->completeParticipantValues($context);
|
||||
}
|
||||
|
||||
return parent::completeOptionValues($optionName, $context);
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function completeArgumentValues($argumentName, CompletionContext $context) {
|
||||
switch ($argumentName) {
|
||||
case 'token':
|
||||
return $this->completeTokenValues($context);
|
||||
}
|
||||
|
||||
return parent::completeArgumentValues($argumentName, $context);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user