diff options
Diffstat (limited to 'lib/private/UserStatus/Manager.php')
-rw-r--r-- | lib/private/UserStatus/Manager.php | 90 |
1 files changed, 42 insertions, 48 deletions
diff --git a/lib/private/UserStatus/Manager.php b/lib/private/UserStatus/Manager.php index aeef8df27f9..4cfd1c18e79 100644 --- a/lib/private/UserStatus/Manager.php +++ b/lib/private/UserStatus/Manager.php @@ -3,59 +3,26 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2020, Georg Ehrke - * - * @author Georg Ehrke <oc.list@georgehrke.com> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OC\UserStatus; -use OCP\ILogger; -use OCP\IServerContainer; use OCP\UserStatus\IManager; use OCP\UserStatus\IProvider; use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; +use Psr\Log\LoggerInterface; class Manager implements IManager { - - /** @var IServerContainer */ - private $container; - - /** @var ILogger */ - private $logger; - - /** @var null */ - private $providerClass; - - /** @var IProvider */ - private $provider; - - /** - * Manager constructor. - * - * @param IServerContainer $container - * @param ILogger $logger - */ - public function __construct(IServerContainer $container, - ILogger $logger) { - $this->container = $container; - $this->logger = $logger; + /** @var ?class-string */ + private ?string $providerClass = null; + private ?IProvider $provider = null; + + public function __construct( + private ContainerInterface $container, + private LoggerInterface $logger, + ) { } /** @@ -91,16 +58,43 @@ class Manager implements IManager { return; } + /** + * @psalm-suppress InvalidCatch + */ try { $provider = $this->container->get($this->providerClass); } catch (ContainerExceptionInterface $e) { - $this->logger->logException($e, [ - 'message' => 'Could not load user-status provider dynamically: ' . $e->getMessage(), - 'level' => ILogger::ERROR, + $this->logger->error('Could not load user-status "' . $this->providerClass . '" provider dynamically: ' . $e->getMessage(), [ + 'exception' => $e, ]); return; } $this->provider = $provider; } + + public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false, ?string $customMessage = null): void { + $this->setupProvider(); + if (!$this->provider instanceof ISettableProvider) { + return; + } + + $this->provider->setUserStatus($userId, $messageId, $status, $createBackup, $customMessage); + } + + public function revertUserStatus(string $userId, string $messageId, string $status): void { + $this->setupProvider(); + if (!$this->provider instanceof ISettableProvider) { + return; + } + $this->provider->revertUserStatus($userId, $messageId, $status); + } + + public function revertMultipleUserStatus(array $userIds, string $messageId, string $status): void { + $this->setupProvider(); + if (!$this->provider instanceof ISettableProvider) { + return; + } + $this->provider->revertMultipleUserStatus($userIds, $messageId, $status); + } } |