UserStatus.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 DateTimeImmutable;
  9. use OCA\UserStatus\Db;
  10. use OCP\UserStatus\IUserStatus;
  11. class UserStatus implements IUserStatus {
  12. /** @var string */
  13. private $userId;
  14. /** @var string */
  15. private $status;
  16. /** @var string|null */
  17. private $message;
  18. /** @var string|null */
  19. private $icon;
  20. /** @var DateTimeImmutable|null */
  21. private $clearAt;
  22. public function __construct(
  23. private Db\UserStatus $internalStatus,
  24. ) {
  25. $this->userId = $this->internalStatus->getUserId();
  26. $this->status = $this->internalStatus->getStatus();
  27. $this->message = $this->internalStatus->getCustomMessage();
  28. $this->icon = $this->internalStatus->getCustomIcon();
  29. if ($this->internalStatus->getStatus() === IUserStatus::INVISIBLE) {
  30. $this->status = IUserStatus::OFFLINE;
  31. }
  32. if ($this->internalStatus->getClearAt() !== null) {
  33. $this->clearAt = DateTimeImmutable::createFromFormat('U', (string)$this->internalStatus->getClearAt());
  34. }
  35. }
  36. /**
  37. * @inheritDoc
  38. */
  39. public function getUserId(): string {
  40. return $this->userId;
  41. }
  42. /**
  43. * @inheritDoc
  44. */
  45. public function getStatus(): string {
  46. return $this->status;
  47. }
  48. /**
  49. * @inheritDoc
  50. */
  51. public function getMessage(): ?string {
  52. return $this->message;
  53. }
  54. /**
  55. * @inheritDoc
  56. */
  57. public function getIcon(): ?string {
  58. return $this->icon;
  59. }
  60. /**
  61. * @inheritDoc
  62. */
  63. public function getClearAt(): ?DateTimeImmutable {
  64. return $this->clearAt;
  65. }
  66. public function getInternal(): Db\UserStatus {
  67. return $this->internalStatus;
  68. }
  69. }