UserStatusProvider.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\UserStatus\Connector;
  8. use OC\UserStatus\ISettableProvider;
  9. use OCA\UserStatus\Service\StatusService;
  10. use OCP\UserStatus\IProvider;
  11. class UserStatusProvider implements IProvider, ISettableProvider {
  12. /** @var StatusService */
  13. private $service;
  14. /**
  15. * UserStatusProvider constructor.
  16. *
  17. * @param StatusService $service
  18. */
  19. public function __construct(StatusService $service) {
  20. $this->service = $service;
  21. }
  22. /**
  23. * @inheritDoc
  24. */
  25. public function getUserStatuses(array $userIds): array {
  26. $statuses = $this->service->findByUserIds($userIds);
  27. $userStatuses = [];
  28. foreach ($statuses as $status) {
  29. $userStatuses[$status->getUserId()] = new UserStatus($status);
  30. }
  31. return $userStatuses;
  32. }
  33. public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup, ?string $customMessage = null): void {
  34. $this->service->setUserStatus($userId, $status, $messageId, $createBackup, $customMessage);
  35. }
  36. public function revertUserStatus(string $userId, string $messageId, string $status): void {
  37. $this->service->revertUserStatus($userId, $messageId);
  38. }
  39. public function revertMultipleUserStatus(array $userIds, string $messageId, string $status): void {
  40. $this->service->revertMultipleUserStatus($userIds, $messageId);
  41. }
  42. }