UserStatus.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020, Georg Ehrke
  5. *
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\UserStatus\Connector;
  25. use DateTimeImmutable;
  26. use OCA\UserStatus\Db;
  27. use OCP\UserStatus\IUserStatus;
  28. class UserStatus implements IUserStatus {
  29. /** @var string */
  30. private $userId;
  31. /** @var string */
  32. private $status;
  33. /** @var string|null */
  34. private $message;
  35. /** @var string|null */
  36. private $icon;
  37. /** @var DateTimeImmutable|null */
  38. private $clearAt;
  39. /** @var Db\UserStatus */
  40. private $internalStatus;
  41. public function __construct(Db\UserStatus $status) {
  42. $this->internalStatus = $status;
  43. $this->userId = $status->getUserId();
  44. $this->status = $status->getStatus();
  45. $this->message = $status->getCustomMessage();
  46. $this->icon = $status->getCustomIcon();
  47. if ($status->getStatus() === IUserStatus::INVISIBLE) {
  48. $this->status = IUserStatus::OFFLINE;
  49. }
  50. if ($status->getClearAt() !== null) {
  51. $this->clearAt = DateTimeImmutable::createFromFormat('U', (string)$status->getClearAt());
  52. }
  53. }
  54. /**
  55. * @inheritDoc
  56. */
  57. public function getUserId(): string {
  58. return $this->userId;
  59. }
  60. /**
  61. * @inheritDoc
  62. */
  63. public function getStatus(): string {
  64. return $this->status;
  65. }
  66. /**
  67. * @inheritDoc
  68. */
  69. public function getMessage(): ?string {
  70. return $this->message;
  71. }
  72. /**
  73. * @inheritDoc
  74. */
  75. public function getIcon(): ?string {
  76. return $this->icon;
  77. }
  78. /**
  79. * @inheritDoc
  80. */
  81. public function getClearAt(): ?DateTimeImmutable {
  82. return $this->clearAt;
  83. }
  84. public function getInternal(): Db\UserStatus {
  85. return $this->internalStatus;
  86. }
  87. }