/** @var DateTimeImmutable|null */
private $clearAt;
- /**
- * UserStatus constructor.
- *
- * @param Db\UserStatus $status
- */
+ /** @var Db\UserStatus */
+ private $internalStatus;
+
public function __construct(Db\UserStatus $status) {
+ $this->internalStatus = $status;
$this->userId = $status->getUserId();
$this->status = $status->getStatus();
$this->message = $status->getCustomMessage();
public function getClearAt(): ?DateTimeImmutable {
return $this->clearAt;
}
+
+ public function getInternal(): Db\UserStatus {
+ return $this->internalStatus;
+ }
}
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
- $this->eventDispatcher->dispatchTyped(
- new UserLiveStatusEvent(
- $user,
- $status,
- $this->timeFactory->getTime()
- )
+ $event = new UserLiveStatusEvent(
+ $user,
+ $status,
+ $this->timeFactory->getTime()
);
- try {
- $userStatus = $this->service->findByUserId($user->getUID());
- } catch (DoesNotExistException $ex) {
+ $this->eventDispatcher->dispatchTyped($event);
+
+ $userStatus = $event->getUserStatus();
+ if (!$userStatus) {
return new JSONResponse([], Http::STATUS_NO_CONTENT);
}
- return new JSONResponse($this->formatStatus($userStatus));
+ /** @psalm-suppress UndefinedInterfaceMethod */
+ return new JSONResponse($this->formatStatus($userStatus->getInternal()));
}
private function formatStatus(UserStatus $status): array {
namespace OCA\UserStatus\Listener;
use OCA\UserStatus\Db\UserStatus;
+use OCA\UserStatus\Connector\UserStatus as ConnectorUserStatus;
use OCA\UserStatus\Db\UserStatusMapper;
use OCA\UserStatus\Service\StatusService;
use OCP\AppFramework\Db\DoesNotExistException;
* @package OCA\UserStatus\Listener
*/
class UserLiveStatusListener implements IEventListener {
+ private UserStatusMapper $mapper;
+ private ITimeFactory $timeFactory;
- /** @var UserStatusMapper */
- private $mapper;
-
- /** @var ITimeFactory */
- private $timeFactory;
-
- /**
- * UserLiveStatusListener constructor.
- *
- * @param UserStatusMapper $mapper
- * @param ITimeFactory $timeFactory
- */
public function __construct(UserStatusMapper $mapper,
ITimeFactory $timeFactory) {
$this->mapper = $mapper;
$this->mapper->update($userStatus);
}
}
+
+ $event->setUserStatus(new ConnectorUserStatus($userStatus));
}
}
use OCP\EventDispatcher\Event;
use OCP\IUser;
+use OCP\UserStatus\IUserStatus;
/**
* @since 20.0.0
*/
public const STATUS_OFFLINE = 'offline';
- /** @var IUser */
- private $user;
-
- /** @var string */
- private $status;
-
- /** @var int */
- private $timestamp;
+ private IUser $user;
+ private string $status;
+ private int $timestamp;
+ private ?IUserStatus $userStatus = null;
/**
- * @param IUser $user
- * @param string $status
- * @param int $timestamp
* @since 20.0.0
*/
public function __construct(IUser $user,
public function getTimestamp(): int {
return $this->timestamp;
}
+
+ /**
+ * Get the user status that might be available after processing the event
+ * @since 24.0.0
+ */
+ public function getUserStatus(): ?IUserStatus {
+ return $this->userStatus;
+ }
+
+ /**
+ * @since 24.0.0
+ */
+ public function setUserStatus(IUserStatus $userStatus) {
+ $this->userStatus = $userStatus;
+ }
}