@@ -40,74 +40,74 @@ |
||
40 | 40 | |
41 | 41 | class HeartbeatController extends Controller { |
42 | 42 | |
43 | - /** @var IEventDispatcher */ |
|
44 | - private $eventDispatcher; |
|
43 | + /** @var IEventDispatcher */ |
|
44 | + private $eventDispatcher; |
|
45 | 45 | |
46 | - /** @var IUserSession */ |
|
47 | - private $userSession; |
|
46 | + /** @var IUserSession */ |
|
47 | + private $userSession; |
|
48 | 48 | |
49 | - /** @var ITimeFactory */ |
|
50 | - private $timeFactory; |
|
49 | + /** @var ITimeFactory */ |
|
50 | + private $timeFactory; |
|
51 | 51 | |
52 | - /** @var StatusService */ |
|
53 | - private $service; |
|
52 | + /** @var StatusService */ |
|
53 | + private $service; |
|
54 | 54 | |
55 | - public function __construct(string $appName, |
|
56 | - IRequest $request, |
|
57 | - IEventDispatcher $eventDispatcher, |
|
58 | - IUserSession $userSession, |
|
59 | - ITimeFactory $timeFactory, |
|
60 | - StatusService $service) { |
|
61 | - parent::__construct($appName, $request); |
|
62 | - $this->eventDispatcher = $eventDispatcher; |
|
63 | - $this->userSession = $userSession; |
|
64 | - $this->timeFactory = $timeFactory; |
|
65 | - $this->service = $service; |
|
66 | - } |
|
55 | + public function __construct(string $appName, |
|
56 | + IRequest $request, |
|
57 | + IEventDispatcher $eventDispatcher, |
|
58 | + IUserSession $userSession, |
|
59 | + ITimeFactory $timeFactory, |
|
60 | + StatusService $service) { |
|
61 | + parent::__construct($appName, $request); |
|
62 | + $this->eventDispatcher = $eventDispatcher; |
|
63 | + $this->userSession = $userSession; |
|
64 | + $this->timeFactory = $timeFactory; |
|
65 | + $this->service = $service; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @NoAdminRequired |
|
70 | - * |
|
71 | - * @param string $status |
|
72 | - * @return JSONResponse |
|
73 | - */ |
|
74 | - public function heartbeat(string $status): JSONResponse { |
|
75 | - if (!\in_array($status, [IUserStatus::ONLINE, IUserStatus::AWAY], true)) { |
|
76 | - return new JSONResponse([], Http::STATUS_BAD_REQUEST); |
|
77 | - } |
|
68 | + /** |
|
69 | + * @NoAdminRequired |
|
70 | + * |
|
71 | + * @param string $status |
|
72 | + * @return JSONResponse |
|
73 | + */ |
|
74 | + public function heartbeat(string $status): JSONResponse { |
|
75 | + if (!\in_array($status, [IUserStatus::ONLINE, IUserStatus::AWAY], true)) { |
|
76 | + return new JSONResponse([], Http::STATUS_BAD_REQUEST); |
|
77 | + } |
|
78 | 78 | |
79 | - $user = $this->userSession->getUser(); |
|
80 | - if ($user === null) { |
|
81 | - return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
82 | - } |
|
79 | + $user = $this->userSession->getUser(); |
|
80 | + if ($user === null) { |
|
81 | + return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
82 | + } |
|
83 | 83 | |
84 | - $this->eventDispatcher->dispatchTyped( |
|
85 | - new UserLiveStatusEvent( |
|
86 | - $user, |
|
87 | - $status, |
|
88 | - $this->timeFactory->getTime() |
|
89 | - ) |
|
90 | - ); |
|
84 | + $this->eventDispatcher->dispatchTyped( |
|
85 | + new UserLiveStatusEvent( |
|
86 | + $user, |
|
87 | + $status, |
|
88 | + $this->timeFactory->getTime() |
|
89 | + ) |
|
90 | + ); |
|
91 | 91 | |
92 | - try { |
|
93 | - $userStatus = $this->service->findByUserId($user->getUID()); |
|
94 | - } catch (DoesNotExistException $ex) { |
|
95 | - return new JSONResponse([], Http::STATUS_NO_CONTENT); |
|
96 | - } |
|
92 | + try { |
|
93 | + $userStatus = $this->service->findByUserId($user->getUID()); |
|
94 | + } catch (DoesNotExistException $ex) { |
|
95 | + return new JSONResponse([], Http::STATUS_NO_CONTENT); |
|
96 | + } |
|
97 | 97 | |
98 | - return new JSONResponse($this->formatStatus($userStatus)); |
|
99 | - } |
|
98 | + return new JSONResponse($this->formatStatus($userStatus)); |
|
99 | + } |
|
100 | 100 | |
101 | - private function formatStatus(UserStatus $status): array { |
|
102 | - return [ |
|
103 | - 'userId' => $status->getUserId(), |
|
104 | - 'message' => $status->getCustomMessage(), |
|
105 | - 'messageId' => $status->getMessageId(), |
|
106 | - 'messageIsPredefined' => $status->getMessageId() !== null, |
|
107 | - 'icon' => $status->getCustomIcon(), |
|
108 | - 'clearAt' => $status->getClearAt(), |
|
109 | - 'status' => $status->getStatus(), |
|
110 | - 'statusIsUserDefined' => $status->getIsUserDefined(), |
|
111 | - ]; |
|
112 | - } |
|
101 | + private function formatStatus(UserStatus $status): array { |
|
102 | + return [ |
|
103 | + 'userId' => $status->getUserId(), |
|
104 | + 'message' => $status->getCustomMessage(), |
|
105 | + 'messageId' => $status->getMessageId(), |
|
106 | + 'messageIsPredefined' => $status->getMessageId() !== null, |
|
107 | + 'icon' => $status->getCustomIcon(), |
|
108 | + 'clearAt' => $status->getClearAt(), |
|
109 | + 'status' => $status->getStatus(), |
|
110 | + 'statusIsUserDefined' => $status->getIsUserDefined(), |
|
111 | + ]; |
|
112 | + } |
|
113 | 113 | } |