UserStatus.php 1.6 KB

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