@@ -35,73 +35,73 @@ |
||
35 | 35 | |
36 | 36 | class StatusesController extends OCSController { |
37 | 37 | |
38 | - /** @var StatusService */ |
|
39 | - private $service; |
|
38 | + /** @var StatusService */ |
|
39 | + private $service; |
|
40 | 40 | |
41 | - /** |
|
42 | - * StatusesController constructor. |
|
43 | - * |
|
44 | - * @param string $appName |
|
45 | - * @param IRequest $request |
|
46 | - * @param StatusService $service |
|
47 | - */ |
|
48 | - public function __construct(string $appName, |
|
49 | - IRequest $request, |
|
50 | - StatusService $service) { |
|
51 | - parent::__construct($appName, $request); |
|
52 | - $this->service = $service; |
|
53 | - } |
|
41 | + /** |
|
42 | + * StatusesController constructor. |
|
43 | + * |
|
44 | + * @param string $appName |
|
45 | + * @param IRequest $request |
|
46 | + * @param StatusService $service |
|
47 | + */ |
|
48 | + public function __construct(string $appName, |
|
49 | + IRequest $request, |
|
50 | + StatusService $service) { |
|
51 | + parent::__construct($appName, $request); |
|
52 | + $this->service = $service; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @NoAdminRequired |
|
57 | - * |
|
58 | - * @param int|null $limit |
|
59 | - * @param int|null $offset |
|
60 | - * @return DataResponse |
|
61 | - */ |
|
62 | - public function findAll(?int $limit=null, ?int $offset=null): DataResponse { |
|
63 | - $allStatuses = $this->service->findAll($limit, $offset); |
|
55 | + /** |
|
56 | + * @NoAdminRequired |
|
57 | + * |
|
58 | + * @param int|null $limit |
|
59 | + * @param int|null $offset |
|
60 | + * @return DataResponse |
|
61 | + */ |
|
62 | + public function findAll(?int $limit=null, ?int $offset=null): DataResponse { |
|
63 | + $allStatuses = $this->service->findAll($limit, $offset); |
|
64 | 64 | |
65 | - return new DataResponse(array_map(function ($userStatus) { |
|
66 | - return $this->formatStatus($userStatus); |
|
67 | - }, $allStatuses)); |
|
68 | - } |
|
65 | + return new DataResponse(array_map(function ($userStatus) { |
|
66 | + return $this->formatStatus($userStatus); |
|
67 | + }, $allStatuses)); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @NoAdminRequired |
|
72 | - * |
|
73 | - * @param string $userId |
|
74 | - * @return DataResponse |
|
75 | - * @throws OCSNotFoundException |
|
76 | - */ |
|
77 | - public function find(string $userId): DataResponse { |
|
78 | - try { |
|
79 | - $userStatus = $this->service->findByUserId($userId); |
|
80 | - } catch (DoesNotExistException $ex) { |
|
81 | - throw new OCSNotFoundException('No status for the requested userId'); |
|
82 | - } |
|
70 | + /** |
|
71 | + * @NoAdminRequired |
|
72 | + * |
|
73 | + * @param string $userId |
|
74 | + * @return DataResponse |
|
75 | + * @throws OCSNotFoundException |
|
76 | + */ |
|
77 | + public function find(string $userId): DataResponse { |
|
78 | + try { |
|
79 | + $userStatus = $this->service->findByUserId($userId); |
|
80 | + } catch (DoesNotExistException $ex) { |
|
81 | + throw new OCSNotFoundException('No status for the requested userId'); |
|
82 | + } |
|
83 | 83 | |
84 | - return new DataResponse($this->formatStatus($userStatus)); |
|
85 | - } |
|
84 | + return new DataResponse($this->formatStatus($userStatus)); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @NoAdminRequired |
|
89 | - * |
|
90 | - * @param UserStatus $status |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - private function formatStatus(UserStatus $status): array { |
|
94 | - $visibleStatus = $status->getStatus(); |
|
95 | - if ($visibleStatus === 'invisible') { |
|
96 | - $visibleStatus = 'offline'; |
|
97 | - } |
|
87 | + /** |
|
88 | + * @NoAdminRequired |
|
89 | + * |
|
90 | + * @param UserStatus $status |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + private function formatStatus(UserStatus $status): array { |
|
94 | + $visibleStatus = $status->getStatus(); |
|
95 | + if ($visibleStatus === 'invisible') { |
|
96 | + $visibleStatus = 'offline'; |
|
97 | + } |
|
98 | 98 | |
99 | - return [ |
|
100 | - 'userId' => $status->getUserId(), |
|
101 | - 'message' => $status->getCustomMessage(), |
|
102 | - 'icon' => $status->getCustomIcon(), |
|
103 | - 'clearAt' => $status->getClearAt(), |
|
104 | - 'status' => $visibleStatus, |
|
105 | - ]; |
|
106 | - } |
|
99 | + return [ |
|
100 | + 'userId' => $status->getUserId(), |
|
101 | + 'message' => $status->getCustomMessage(), |
|
102 | + 'icon' => $status->getCustomIcon(), |
|
103 | + 'clearAt' => $status->getClearAt(), |
|
104 | + 'status' => $visibleStatus, |
|
105 | + ]; |
|
106 | + } |
|
107 | 107 | } |
@@ -37,29 +37,29 @@ |
||
37 | 37 | */ |
38 | 38 | class PredefinedStatusController extends OCSController { |
39 | 39 | |
40 | - /** @var PredefinedStatusService */ |
|
41 | - private $predefinedStatusService; |
|
40 | + /** @var PredefinedStatusService */ |
|
41 | + private $predefinedStatusService; |
|
42 | 42 | |
43 | - /** |
|
44 | - * AStatusController constructor. |
|
45 | - * |
|
46 | - * @param string $appName |
|
47 | - * @param IRequest $request |
|
48 | - * @param PredefinedStatusService $predefinedStatusService |
|
49 | - */ |
|
50 | - public function __construct(string $appName, |
|
51 | - IRequest $request, |
|
52 | - PredefinedStatusService $predefinedStatusService) { |
|
53 | - parent::__construct($appName, $request); |
|
54 | - $this->predefinedStatusService = $predefinedStatusService; |
|
55 | - } |
|
43 | + /** |
|
44 | + * AStatusController constructor. |
|
45 | + * |
|
46 | + * @param string $appName |
|
47 | + * @param IRequest $request |
|
48 | + * @param PredefinedStatusService $predefinedStatusService |
|
49 | + */ |
|
50 | + public function __construct(string $appName, |
|
51 | + IRequest $request, |
|
52 | + PredefinedStatusService $predefinedStatusService) { |
|
53 | + parent::__construct($appName, $request); |
|
54 | + $this->predefinedStatusService = $predefinedStatusService; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @NoAdminRequired |
|
59 | - * |
|
60 | - * @return DataResponse |
|
61 | - */ |
|
62 | - public function findAll():DataResponse { |
|
63 | - return new DataResponse($this->predefinedStatusService->getDefaultStatuses()); |
|
64 | - } |
|
57 | + /** |
|
58 | + * @NoAdminRequired |
|
59 | + * |
|
60 | + * @return DataResponse |
|
61 | + */ |
|
62 | + public function findAll():DataResponse { |
|
63 | + return new DataResponse($this->predefinedStatusService->getDefaultStatuses()); |
|
64 | + } |
|
65 | 65 | } |
@@ -36,57 +36,57 @@ |
||
36 | 36 | |
37 | 37 | class HeartbeatController extends Controller { |
38 | 38 | |
39 | - /** @var IEventDispatcher */ |
|
40 | - private $eventDispatcher; |
|
39 | + /** @var IEventDispatcher */ |
|
40 | + private $eventDispatcher; |
|
41 | 41 | |
42 | - /** @var IUserSession */ |
|
43 | - private $userSession; |
|
42 | + /** @var IUserSession */ |
|
43 | + private $userSession; |
|
44 | 44 | |
45 | - /** @var ITimeFactory */ |
|
46 | - private $timeFactory; |
|
45 | + /** @var ITimeFactory */ |
|
46 | + private $timeFactory; |
|
47 | 47 | |
48 | - /** |
|
49 | - * HeartbeatController constructor. |
|
50 | - * |
|
51 | - * @param string $appName |
|
52 | - * @param IRequest $request |
|
53 | - * @param IEventDispatcher $eventDispatcher |
|
54 | - */ |
|
55 | - public function __construct(string $appName, |
|
56 | - IRequest $request, |
|
57 | - IEventDispatcher $eventDispatcher, |
|
58 | - IUserSession $userSession, |
|
59 | - ITimeFactory $timeFactory) { |
|
60 | - parent::__construct($appName, $request); |
|
61 | - $this->eventDispatcher = $eventDispatcher; |
|
62 | - $this->userSession = $userSession; |
|
63 | - $this->timeFactory = $timeFactory; |
|
64 | - } |
|
48 | + /** |
|
49 | + * HeartbeatController constructor. |
|
50 | + * |
|
51 | + * @param string $appName |
|
52 | + * @param IRequest $request |
|
53 | + * @param IEventDispatcher $eventDispatcher |
|
54 | + */ |
|
55 | + public function __construct(string $appName, |
|
56 | + IRequest $request, |
|
57 | + IEventDispatcher $eventDispatcher, |
|
58 | + IUserSession $userSession, |
|
59 | + ITimeFactory $timeFactory) { |
|
60 | + parent::__construct($appName, $request); |
|
61 | + $this->eventDispatcher = $eventDispatcher; |
|
62 | + $this->userSession = $userSession; |
|
63 | + $this->timeFactory = $timeFactory; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @NoAdminRequired |
|
68 | - * |
|
69 | - * @param string $status |
|
70 | - * @return JSONResponse |
|
71 | - */ |
|
72 | - public function heartbeat(string $status): JSONResponse { |
|
73 | - if (!\in_array($status, ['online', 'away'])) { |
|
74 | - return new JSONResponse([], Http::STATUS_BAD_REQUEST); |
|
75 | - } |
|
66 | + /** |
|
67 | + * @NoAdminRequired |
|
68 | + * |
|
69 | + * @param string $status |
|
70 | + * @return JSONResponse |
|
71 | + */ |
|
72 | + public function heartbeat(string $status): JSONResponse { |
|
73 | + if (!\in_array($status, ['online', 'away'])) { |
|
74 | + return new JSONResponse([], Http::STATUS_BAD_REQUEST); |
|
75 | + } |
|
76 | 76 | |
77 | - $user = $this->userSession->getUser(); |
|
78 | - if ($user === null) { |
|
79 | - return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
80 | - } |
|
77 | + $user = $this->userSession->getUser(); |
|
78 | + if ($user === null) { |
|
79 | + return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
80 | + } |
|
81 | 81 | |
82 | - $this->eventDispatcher->dispatchTyped( |
|
83 | - new UserLiveStatusEvent( |
|
84 | - $user, |
|
85 | - $status, |
|
86 | - $this->timeFactory->getTime() |
|
87 | - ) |
|
88 | - ); |
|
82 | + $this->eventDispatcher->dispatchTyped( |
|
83 | + new UserLiveStatusEvent( |
|
84 | + $user, |
|
85 | + $status, |
|
86 | + $this->timeFactory->getTime() |
|
87 | + ) |
|
88 | + ); |
|
89 | 89 | |
90 | - return new JSONResponse([], Http::STATUS_NO_CONTENT); |
|
91 | - } |
|
90 | + return new JSONResponse([], Http::STATUS_NO_CONTENT); |
|
91 | + } |
|
92 | 92 | } |
@@ -41,151 +41,151 @@ |
||
41 | 41 | |
42 | 42 | class UserStatusController extends OCSController { |
43 | 43 | |
44 | - /** @var string */ |
|
45 | - private $userId; |
|
46 | - |
|
47 | - /** @var ILogger */ |
|
48 | - private $logger; |
|
49 | - |
|
50 | - /** @var StatusService */ |
|
51 | - private $service; |
|
52 | - |
|
53 | - /** |
|
54 | - * StatusesController constructor. |
|
55 | - * |
|
56 | - * @param string $appName |
|
57 | - * @param IRequest $request |
|
58 | - * @param string $userId |
|
59 | - * @param ILogger $logger; |
|
60 | - * @param StatusService $service |
|
61 | - */ |
|
62 | - public function __construct(string $appName, |
|
63 | - IRequest $request, |
|
64 | - string $userId, |
|
65 | - ILogger $logger, |
|
66 | - StatusService $service) { |
|
67 | - parent::__construct($appName, $request); |
|
68 | - $this->userId = $userId; |
|
69 | - $this->logger = $logger; |
|
70 | - $this->service = $service; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @NoAdminRequired |
|
75 | - * |
|
76 | - * @return DataResponse |
|
77 | - * @throws OCSNotFoundException |
|
78 | - */ |
|
79 | - public function getStatus(): DataResponse { |
|
80 | - try { |
|
81 | - $userStatus = $this->service->findByUserId($this->userId); |
|
82 | - } catch (DoesNotExistException $ex) { |
|
83 | - throw new OCSNotFoundException('No status for the current user'); |
|
84 | - } |
|
85 | - |
|
86 | - return new DataResponse($this->formatStatus($userStatus)); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @NoAdminRequired |
|
91 | - * |
|
92 | - * @param string $statusType |
|
93 | - * @return DataResponse |
|
94 | - * @throws OCSBadRequestException |
|
95 | - */ |
|
96 | - public function setStatus(string $statusType): DataResponse { |
|
97 | - try { |
|
98 | - $status = $this->service->setStatus($this->userId, $statusType, null, true); |
|
99 | - return new DataResponse($this->formatStatus($status)); |
|
100 | - } catch (InvalidStatusTypeException $ex) { |
|
101 | - $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid status type "' . $statusType . '"'); |
|
102 | - throw new OCSBadRequestException($ex->getMessage(), $ex); |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @NoAdminRequired |
|
108 | - * |
|
109 | - * @param string $messageId |
|
110 | - * @param int|null $clearAt |
|
111 | - * @return DataResponse |
|
112 | - * @throws OCSBadRequestException |
|
113 | - */ |
|
114 | - public function setPredefinedMessage(string $messageId, |
|
115 | - ?int $clearAt): DataResponse { |
|
116 | - try { |
|
117 | - $status = $this->service->setPredefinedMessage($this->userId, $messageId, $clearAt); |
|
118 | - return new DataResponse($this->formatStatus($status)); |
|
119 | - } catch (InvalidClearAtException $ex) { |
|
120 | - $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid clearAt value "' . $clearAt . '"'); |
|
121 | - throw new OCSBadRequestException($ex->getMessage(), $ex); |
|
122 | - } catch (InvalidMessageIdException $ex) { |
|
123 | - $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid message-id "' . $messageId . '"'); |
|
124 | - throw new OCSBadRequestException($ex->getMessage(), $ex); |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @NoAdminRequired |
|
130 | - * |
|
131 | - * @param string|null $statusIcon |
|
132 | - * @param string $message |
|
133 | - * @param int|null $clearAt |
|
134 | - * @return DataResponse |
|
135 | - * @throws OCSBadRequestException |
|
136 | - */ |
|
137 | - public function setCustomMessage(?string $statusIcon, |
|
138 | - string $message, |
|
139 | - ?int $clearAt): DataResponse { |
|
140 | - try { |
|
141 | - $status = $this->service->setCustomMessage($this->userId, $statusIcon, $message, $clearAt); |
|
142 | - return new DataResponse($this->formatStatus($status)); |
|
143 | - } catch (InvalidClearAtException $ex) { |
|
144 | - $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid clearAt value "' . $clearAt . '"'); |
|
145 | - throw new OCSBadRequestException($ex->getMessage(), $ex); |
|
146 | - } catch (InvalidStatusIconException $ex) { |
|
147 | - $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid icon value "' . $statusIcon . '"'); |
|
148 | - throw new OCSBadRequestException($ex->getMessage(), $ex); |
|
149 | - } catch (StatusMessageTooLongException $ex) { |
|
150 | - $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to a too long status message.'); |
|
151 | - throw new OCSBadRequestException($ex->getMessage(), $ex); |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @NoAdminRequired |
|
157 | - * |
|
158 | - * @return DataResponse |
|
159 | - */ |
|
160 | - public function clearStatus(): DataResponse { |
|
161 | - $this->service->clearStatus($this->userId); |
|
162 | - return new DataResponse([]); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @NoAdminRequired |
|
167 | - * |
|
168 | - * @return DataResponse |
|
169 | - */ |
|
170 | - public function clearMessage(): DataResponse { |
|
171 | - $this->service->clearMessage($this->userId); |
|
172 | - return new DataResponse([]); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @param UserStatus $status |
|
177 | - * @return array |
|
178 | - */ |
|
179 | - private function formatStatus(UserStatus $status): array { |
|
180 | - return [ |
|
181 | - 'userId' => $status->getUserId(), |
|
182 | - 'message' => $status->getCustomMessage(), |
|
183 | - 'messageId' => $status->getMessageId(), |
|
184 | - 'messageIsPredefined' => $status->getMessageId() !== null, |
|
185 | - 'icon' => $status->getCustomIcon(), |
|
186 | - 'clearAt' => $status->getClearAt(), |
|
187 | - 'status' => $status->getStatus(), |
|
188 | - 'statusIsUserDefined' => $status->getIsUserDefined(), |
|
189 | - ]; |
|
190 | - } |
|
44 | + /** @var string */ |
|
45 | + private $userId; |
|
46 | + |
|
47 | + /** @var ILogger */ |
|
48 | + private $logger; |
|
49 | + |
|
50 | + /** @var StatusService */ |
|
51 | + private $service; |
|
52 | + |
|
53 | + /** |
|
54 | + * StatusesController constructor. |
|
55 | + * |
|
56 | + * @param string $appName |
|
57 | + * @param IRequest $request |
|
58 | + * @param string $userId |
|
59 | + * @param ILogger $logger; |
|
60 | + * @param StatusService $service |
|
61 | + */ |
|
62 | + public function __construct(string $appName, |
|
63 | + IRequest $request, |
|
64 | + string $userId, |
|
65 | + ILogger $logger, |
|
66 | + StatusService $service) { |
|
67 | + parent::__construct($appName, $request); |
|
68 | + $this->userId = $userId; |
|
69 | + $this->logger = $logger; |
|
70 | + $this->service = $service; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @NoAdminRequired |
|
75 | + * |
|
76 | + * @return DataResponse |
|
77 | + * @throws OCSNotFoundException |
|
78 | + */ |
|
79 | + public function getStatus(): DataResponse { |
|
80 | + try { |
|
81 | + $userStatus = $this->service->findByUserId($this->userId); |
|
82 | + } catch (DoesNotExistException $ex) { |
|
83 | + throw new OCSNotFoundException('No status for the current user'); |
|
84 | + } |
|
85 | + |
|
86 | + return new DataResponse($this->formatStatus($userStatus)); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @NoAdminRequired |
|
91 | + * |
|
92 | + * @param string $statusType |
|
93 | + * @return DataResponse |
|
94 | + * @throws OCSBadRequestException |
|
95 | + */ |
|
96 | + public function setStatus(string $statusType): DataResponse { |
|
97 | + try { |
|
98 | + $status = $this->service->setStatus($this->userId, $statusType, null, true); |
|
99 | + return new DataResponse($this->formatStatus($status)); |
|
100 | + } catch (InvalidStatusTypeException $ex) { |
|
101 | + $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid status type "' . $statusType . '"'); |
|
102 | + throw new OCSBadRequestException($ex->getMessage(), $ex); |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @NoAdminRequired |
|
108 | + * |
|
109 | + * @param string $messageId |
|
110 | + * @param int|null $clearAt |
|
111 | + * @return DataResponse |
|
112 | + * @throws OCSBadRequestException |
|
113 | + */ |
|
114 | + public function setPredefinedMessage(string $messageId, |
|
115 | + ?int $clearAt): DataResponse { |
|
116 | + try { |
|
117 | + $status = $this->service->setPredefinedMessage($this->userId, $messageId, $clearAt); |
|
118 | + return new DataResponse($this->formatStatus($status)); |
|
119 | + } catch (InvalidClearAtException $ex) { |
|
120 | + $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid clearAt value "' . $clearAt . '"'); |
|
121 | + throw new OCSBadRequestException($ex->getMessage(), $ex); |
|
122 | + } catch (InvalidMessageIdException $ex) { |
|
123 | + $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid message-id "' . $messageId . '"'); |
|
124 | + throw new OCSBadRequestException($ex->getMessage(), $ex); |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @NoAdminRequired |
|
130 | + * |
|
131 | + * @param string|null $statusIcon |
|
132 | + * @param string $message |
|
133 | + * @param int|null $clearAt |
|
134 | + * @return DataResponse |
|
135 | + * @throws OCSBadRequestException |
|
136 | + */ |
|
137 | + public function setCustomMessage(?string $statusIcon, |
|
138 | + string $message, |
|
139 | + ?int $clearAt): DataResponse { |
|
140 | + try { |
|
141 | + $status = $this->service->setCustomMessage($this->userId, $statusIcon, $message, $clearAt); |
|
142 | + return new DataResponse($this->formatStatus($status)); |
|
143 | + } catch (InvalidClearAtException $ex) { |
|
144 | + $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid clearAt value "' . $clearAt . '"'); |
|
145 | + throw new OCSBadRequestException($ex->getMessage(), $ex); |
|
146 | + } catch (InvalidStatusIconException $ex) { |
|
147 | + $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to an invalid icon value "' . $statusIcon . '"'); |
|
148 | + throw new OCSBadRequestException($ex->getMessage(), $ex); |
|
149 | + } catch (StatusMessageTooLongException $ex) { |
|
150 | + $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to a too long status message.'); |
|
151 | + throw new OCSBadRequestException($ex->getMessage(), $ex); |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @NoAdminRequired |
|
157 | + * |
|
158 | + * @return DataResponse |
|
159 | + */ |
|
160 | + public function clearStatus(): DataResponse { |
|
161 | + $this->service->clearStatus($this->userId); |
|
162 | + return new DataResponse([]); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @NoAdminRequired |
|
167 | + * |
|
168 | + * @return DataResponse |
|
169 | + */ |
|
170 | + public function clearMessage(): DataResponse { |
|
171 | + $this->service->clearMessage($this->userId); |
|
172 | + return new DataResponse([]); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * @param UserStatus $status |
|
177 | + * @return array |
|
178 | + */ |
|
179 | + private function formatStatus(UserStatus $status): array { |
|
180 | + return [ |
|
181 | + 'userId' => $status->getUserId(), |
|
182 | + 'message' => $status->getCustomMessage(), |
|
183 | + 'messageId' => $status->getMessageId(), |
|
184 | + 'messageIsPredefined' => $status->getMessageId() !== null, |
|
185 | + 'icon' => $status->getCustomIcon(), |
|
186 | + 'clearAt' => $status->getClearAt(), |
|
187 | + 'status' => $status->getStatus(), |
|
188 | + 'statusIsUserDefined' => $status->getIsUserDefined(), |
|
189 | + ]; |
|
190 | + } |
|
191 | 191 | } |
@@ -34,42 +34,42 @@ |
||
34 | 34 | |
35 | 35 | class BeforeTemplateRenderedListener implements IEventListener { |
36 | 36 | |
37 | - /** @var IInitialStateService */ |
|
38 | - private $initialState; |
|
37 | + /** @var IInitialStateService */ |
|
38 | + private $initialState; |
|
39 | 39 | |
40 | - /** @var JSDataService */ |
|
41 | - private $jsDataService; |
|
40 | + /** @var JSDataService */ |
|
41 | + private $jsDataService; |
|
42 | 42 | |
43 | - /** |
|
44 | - * BeforeTemplateRenderedListener constructor. |
|
45 | - * |
|
46 | - * @param IInitialStateService $initialState |
|
47 | - * @param JSDataService $jsDataService |
|
48 | - */ |
|
49 | - public function __construct(IInitialStateService $initialState, |
|
50 | - JSDataService $jsDataService) { |
|
51 | - $this->initialState = $initialState; |
|
52 | - $this->jsDataService = $jsDataService; |
|
53 | - } |
|
43 | + /** |
|
44 | + * BeforeTemplateRenderedListener constructor. |
|
45 | + * |
|
46 | + * @param IInitialStateService $initialState |
|
47 | + * @param JSDataService $jsDataService |
|
48 | + */ |
|
49 | + public function __construct(IInitialStateService $initialState, |
|
50 | + JSDataService $jsDataService) { |
|
51 | + $this->initialState = $initialState; |
|
52 | + $this->jsDataService = $jsDataService; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @inheritDoc |
|
57 | - */ |
|
58 | - public function handle(Event $event): void { |
|
59 | - if (!($event instanceof BeforeTemplateRenderedEvent)) { |
|
60 | - // Unrelated |
|
61 | - return; |
|
62 | - } |
|
55 | + /** |
|
56 | + * @inheritDoc |
|
57 | + */ |
|
58 | + public function handle(Event $event): void { |
|
59 | + if (!($event instanceof BeforeTemplateRenderedEvent)) { |
|
60 | + // Unrelated |
|
61 | + return; |
|
62 | + } |
|
63 | 63 | |
64 | - if (!$event->isLoggedIn()) { |
|
65 | - return; |
|
66 | - } |
|
64 | + if (!$event->isLoggedIn()) { |
|
65 | + return; |
|
66 | + } |
|
67 | 67 | |
68 | - $this->initialState->provideLazyInitialState(Application::APP_ID, 'status', function () { |
|
69 | - return $this->jsDataService; |
|
70 | - }); |
|
68 | + $this->initialState->provideLazyInitialState(Application::APP_ID, 'status', function () { |
|
69 | + return $this->jsDataService; |
|
70 | + }); |
|
71 | 71 | |
72 | - \OCP\Util::addScript('user_status', 'user-status-menu'); |
|
73 | - \OCP\Util::addStyle('user_status', 'user-status-menu'); |
|
74 | - } |
|
72 | + \OCP\Util::addScript('user_status', 'user-status-menu'); |
|
73 | + \OCP\Util::addStyle('user_status', 'user-status-menu'); |
|
74 | + } |
|
75 | 75 | } |
@@ -40,94 +40,94 @@ |
||
40 | 40 | */ |
41 | 41 | class UserLiveStatusListener implements IEventListener { |
42 | 42 | |
43 | - /** @var UserStatusMapper */ |
|
44 | - private $mapper; |
|
45 | - |
|
46 | - /** @var ITimeFactory */ |
|
47 | - private $timeFactory; |
|
48 | - |
|
49 | - /** @var string[] */ |
|
50 | - private $priorityOrderedStatuses = [ |
|
51 | - 'online', |
|
52 | - 'away', |
|
53 | - 'dnd', |
|
54 | - 'invisible', |
|
55 | - 'offline' |
|
56 | - ]; |
|
57 | - |
|
58 | - /** @var string[] */ |
|
59 | - private $persistentUserStatuses = [ |
|
60 | - 'away', |
|
61 | - 'dnd', |
|
62 | - 'invisible', |
|
63 | - ]; |
|
64 | - |
|
65 | - /** @var int */ |
|
66 | - private $offlineThreshold = 300; |
|
67 | - |
|
68 | - /** |
|
69 | - * UserLiveStatusListener constructor. |
|
70 | - * |
|
71 | - * @param UserStatusMapper $mapper |
|
72 | - * @param ITimeFactory $timeFactory |
|
73 | - */ |
|
74 | - public function __construct(UserStatusMapper $mapper, |
|
75 | - ITimeFactory $timeFactory) { |
|
76 | - $this->mapper = $mapper; |
|
77 | - $this->timeFactory = $timeFactory; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @inheritDoc |
|
82 | - */ |
|
83 | - public function handle(Event $event): void { |
|
84 | - if (!($event instanceof UserLiveStatusEvent)) { |
|
85 | - // Unrelated |
|
86 | - return; |
|
87 | - } |
|
88 | - |
|
89 | - $user = $event->getUser(); |
|
90 | - try { |
|
91 | - $userStatus = $this->mapper->findByUserId($user->getUID()); |
|
92 | - } catch (DoesNotExistException $ex) { |
|
93 | - $userStatus = new UserStatus(); |
|
94 | - $userStatus->setUserId($user->getUID()); |
|
95 | - $userStatus->setStatus('offline'); |
|
96 | - $userStatus->setStatusTimestamp(0); |
|
97 | - $userStatus->setIsUserDefined(false); |
|
98 | - } |
|
99 | - |
|
100 | - // If the status is user-defined and one of the persistent statuses, we |
|
101 | - // will not override it. |
|
102 | - if ($userStatus->getIsUserDefined() && |
|
103 | - \in_array($userStatus->getStatus(), $this->persistentUserStatuses, true)) { |
|
104 | - return; |
|
105 | - } |
|
106 | - |
|
107 | - $needsUpdate = false; |
|
108 | - |
|
109 | - // If the current status is older than 5 minutes, |
|
110 | - // treat it as outdated and update |
|
111 | - if ($userStatus->getStatusTimestamp() < ($this->timeFactory->getTime() - $this->offlineThreshold)) { |
|
112 | - $needsUpdate = true; |
|
113 | - } |
|
114 | - |
|
115 | - // If the emitted status is more important than the current status |
|
116 | - // treat it as outdated and update |
|
117 | - if (array_search($event->getStatus(), $this->priorityOrderedStatuses) < array_search($userStatus->getStatus(), $this->priorityOrderedStatuses)) { |
|
118 | - $needsUpdate = true; |
|
119 | - } |
|
120 | - |
|
121 | - if ($needsUpdate) { |
|
122 | - $userStatus->setStatus($event->getStatus()); |
|
123 | - $userStatus->setStatusTimestamp($event->getTimestamp()); |
|
124 | - $userStatus->setIsUserDefined(false); |
|
125 | - |
|
126 | - if ($userStatus->getId() === null) { |
|
127 | - $this->mapper->insert($userStatus); |
|
128 | - } else { |
|
129 | - $this->mapper->update($userStatus); |
|
130 | - } |
|
131 | - } |
|
132 | - } |
|
43 | + /** @var UserStatusMapper */ |
|
44 | + private $mapper; |
|
45 | + |
|
46 | + /** @var ITimeFactory */ |
|
47 | + private $timeFactory; |
|
48 | + |
|
49 | + /** @var string[] */ |
|
50 | + private $priorityOrderedStatuses = [ |
|
51 | + 'online', |
|
52 | + 'away', |
|
53 | + 'dnd', |
|
54 | + 'invisible', |
|
55 | + 'offline' |
|
56 | + ]; |
|
57 | + |
|
58 | + /** @var string[] */ |
|
59 | + private $persistentUserStatuses = [ |
|
60 | + 'away', |
|
61 | + 'dnd', |
|
62 | + 'invisible', |
|
63 | + ]; |
|
64 | + |
|
65 | + /** @var int */ |
|
66 | + private $offlineThreshold = 300; |
|
67 | + |
|
68 | + /** |
|
69 | + * UserLiveStatusListener constructor. |
|
70 | + * |
|
71 | + * @param UserStatusMapper $mapper |
|
72 | + * @param ITimeFactory $timeFactory |
|
73 | + */ |
|
74 | + public function __construct(UserStatusMapper $mapper, |
|
75 | + ITimeFactory $timeFactory) { |
|
76 | + $this->mapper = $mapper; |
|
77 | + $this->timeFactory = $timeFactory; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @inheritDoc |
|
82 | + */ |
|
83 | + public function handle(Event $event): void { |
|
84 | + if (!($event instanceof UserLiveStatusEvent)) { |
|
85 | + // Unrelated |
|
86 | + return; |
|
87 | + } |
|
88 | + |
|
89 | + $user = $event->getUser(); |
|
90 | + try { |
|
91 | + $userStatus = $this->mapper->findByUserId($user->getUID()); |
|
92 | + } catch (DoesNotExistException $ex) { |
|
93 | + $userStatus = new UserStatus(); |
|
94 | + $userStatus->setUserId($user->getUID()); |
|
95 | + $userStatus->setStatus('offline'); |
|
96 | + $userStatus->setStatusTimestamp(0); |
|
97 | + $userStatus->setIsUserDefined(false); |
|
98 | + } |
|
99 | + |
|
100 | + // If the status is user-defined and one of the persistent statuses, we |
|
101 | + // will not override it. |
|
102 | + if ($userStatus->getIsUserDefined() && |
|
103 | + \in_array($userStatus->getStatus(), $this->persistentUserStatuses, true)) { |
|
104 | + return; |
|
105 | + } |
|
106 | + |
|
107 | + $needsUpdate = false; |
|
108 | + |
|
109 | + // If the current status is older than 5 minutes, |
|
110 | + // treat it as outdated and update |
|
111 | + if ($userStatus->getStatusTimestamp() < ($this->timeFactory->getTime() - $this->offlineThreshold)) { |
|
112 | + $needsUpdate = true; |
|
113 | + } |
|
114 | + |
|
115 | + // If the emitted status is more important than the current status |
|
116 | + // treat it as outdated and update |
|
117 | + if (array_search($event->getStatus(), $this->priorityOrderedStatuses) < array_search($userStatus->getStatus(), $this->priorityOrderedStatuses)) { |
|
118 | + $needsUpdate = true; |
|
119 | + } |
|
120 | + |
|
121 | + if ($needsUpdate) { |
|
122 | + $userStatus->setStatus($event->getStatus()); |
|
123 | + $userStatus->setStatusTimestamp($event->getTimestamp()); |
|
124 | + $userStatus->setIsUserDefined(false); |
|
125 | + |
|
126 | + if ($userStatus->getId() === null) { |
|
127 | + $this->mapper->insert($userStatus); |
|
128 | + } else { |
|
129 | + $this->mapper->update($userStatus); |
|
130 | + } |
|
131 | + } |
|
132 | + } |
|
133 | 133 | } |
@@ -37,29 +37,29 @@ |
||
37 | 37 | */ |
38 | 38 | class UserDeletedListener implements IEventListener { |
39 | 39 | |
40 | - /** @var StatusService */ |
|
41 | - private $service; |
|
40 | + /** @var StatusService */ |
|
41 | + private $service; |
|
42 | 42 | |
43 | - /** |
|
44 | - * UserDeletedListener constructor. |
|
45 | - * |
|
46 | - * @param StatusService $service |
|
47 | - */ |
|
48 | - public function __construct(StatusService $service) { |
|
49 | - $this->service = $service; |
|
50 | - } |
|
43 | + /** |
|
44 | + * UserDeletedListener constructor. |
|
45 | + * |
|
46 | + * @param StatusService $service |
|
47 | + */ |
|
48 | + public function __construct(StatusService $service) { |
|
49 | + $this->service = $service; |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @inheritDoc |
|
55 | - */ |
|
56 | - public function handle(Event $event): void { |
|
57 | - if (!($event instanceof UserDeletedEvent)) { |
|
58 | - // Unrelated |
|
59 | - return; |
|
60 | - } |
|
53 | + /** |
|
54 | + * @inheritDoc |
|
55 | + */ |
|
56 | + public function handle(Event $event): void { |
|
57 | + if (!($event instanceof UserDeletedEvent)) { |
|
58 | + // Unrelated |
|
59 | + return; |
|
60 | + } |
|
61 | 61 | |
62 | - $user = $event->getUser(); |
|
63 | - $this->service->removeUserStatus($user->getUID()); |
|
64 | - } |
|
62 | + $user = $event->getUser(); |
|
63 | + $this->service->removeUserStatus($user->getUID()); |
|
64 | + } |
|
65 | 65 | } |
@@ -24,20 +24,20 @@ |
||
24 | 24 | */ |
25 | 25 | |
26 | 26 | return [ |
27 | - 'ocs' => [ |
|
28 | - // Routes for querying statuses |
|
29 | - ['name' => 'Statuses#findAll', 'url' => '/api/v1/statuses', 'verb' => 'GET'], |
|
30 | - ['name' => 'Statuses#find', 'url' => '/api/v1/statuses/{userId}', 'verb' => 'GET'], |
|
31 | - // Routes for manipulating your own status |
|
32 | - ['name' => 'UserStatus#getStatus', 'url' => '/api/v1/user_status', 'verb' => 'GET'], |
|
33 | - ['name' => 'UserStatus#setStatus', 'url' => '/api/v1/user_status/status', 'verb' => 'PUT'], |
|
34 | - ['name' => 'UserStatus#setPredefinedMessage', 'url' => '/api/v1/user_status/message/predefined', 'verb' => 'PUT'], |
|
35 | - ['name' => 'UserStatus#setCustomMessage', 'url' => '/api/v1/user_status/message/custom', 'verb' => 'PUT'], |
|
36 | - ['name' => 'UserStatus#clearMessage', 'url' => '/api/v1/user_status/message', 'verb' => 'DELETE'], |
|
37 | - // Routes for listing default routes |
|
38 | - ['name' => 'PredefinedStatus#findAll', 'url' => '/api/v1/predefined_statuses/', 'verb' => 'GET'] |
|
39 | - ], |
|
40 | - 'routes' => [ |
|
41 | - ['name' => 'Heartbeat#heartbeat', 'url' => '/heartbeat', 'verb' => 'PUT'], |
|
42 | - ], |
|
27 | + 'ocs' => [ |
|
28 | + // Routes for querying statuses |
|
29 | + ['name' => 'Statuses#findAll', 'url' => '/api/v1/statuses', 'verb' => 'GET'], |
|
30 | + ['name' => 'Statuses#find', 'url' => '/api/v1/statuses/{userId}', 'verb' => 'GET'], |
|
31 | + // Routes for manipulating your own status |
|
32 | + ['name' => 'UserStatus#getStatus', 'url' => '/api/v1/user_status', 'verb' => 'GET'], |
|
33 | + ['name' => 'UserStatus#setStatus', 'url' => '/api/v1/user_status/status', 'verb' => 'PUT'], |
|
34 | + ['name' => 'UserStatus#setPredefinedMessage', 'url' => '/api/v1/user_status/message/predefined', 'verb' => 'PUT'], |
|
35 | + ['name' => 'UserStatus#setCustomMessage', 'url' => '/api/v1/user_status/message/custom', 'verb' => 'PUT'], |
|
36 | + ['name' => 'UserStatus#clearMessage', 'url' => '/api/v1/user_status/message', 'verb' => 'DELETE'], |
|
37 | + // Routes for listing default routes |
|
38 | + ['name' => 'PredefinedStatus#findAll', 'url' => '/api/v1/predefined_statuses/', 'verb' => 'GET'] |
|
39 | + ], |
|
40 | + 'routes' => [ |
|
41 | + ['name' => 'Heartbeat#heartbeat', 'url' => '/heartbeat', 'verb' => 'PUT'], |
|
42 | + ], |
|
43 | 43 | ]; |
@@ -46,290 +46,290 @@ |
||
46 | 46 | */ |
47 | 47 | |
48 | 48 | class NavigationManager implements INavigationManager { |
49 | - protected $entries = []; |
|
50 | - protected $closureEntries = []; |
|
51 | - protected $activeEntry; |
|
52 | - /** @var bool */ |
|
53 | - protected $init = false; |
|
54 | - /** @var IAppManager|AppManager */ |
|
55 | - protected $appManager; |
|
56 | - /** @var IURLGenerator */ |
|
57 | - private $urlGenerator; |
|
58 | - /** @var IFactory */ |
|
59 | - private $l10nFac; |
|
60 | - /** @var IUserSession */ |
|
61 | - private $userSession; |
|
62 | - /** @var IGroupManager|Manager */ |
|
63 | - private $groupManager; |
|
64 | - /** @var IConfig */ |
|
65 | - private $config; |
|
49 | + protected $entries = []; |
|
50 | + protected $closureEntries = []; |
|
51 | + protected $activeEntry; |
|
52 | + /** @var bool */ |
|
53 | + protected $init = false; |
|
54 | + /** @var IAppManager|AppManager */ |
|
55 | + protected $appManager; |
|
56 | + /** @var IURLGenerator */ |
|
57 | + private $urlGenerator; |
|
58 | + /** @var IFactory */ |
|
59 | + private $l10nFac; |
|
60 | + /** @var IUserSession */ |
|
61 | + private $userSession; |
|
62 | + /** @var IGroupManager|Manager */ |
|
63 | + private $groupManager; |
|
64 | + /** @var IConfig */ |
|
65 | + private $config; |
|
66 | 66 | |
67 | - public function __construct(IAppManager $appManager, |
|
68 | - IURLGenerator $urlGenerator, |
|
69 | - IFactory $l10nFac, |
|
70 | - IUserSession $userSession, |
|
71 | - IGroupManager $groupManager, |
|
72 | - IConfig $config) { |
|
73 | - $this->appManager = $appManager; |
|
74 | - $this->urlGenerator = $urlGenerator; |
|
75 | - $this->l10nFac = $l10nFac; |
|
76 | - $this->userSession = $userSession; |
|
77 | - $this->groupManager = $groupManager; |
|
78 | - $this->config = $config; |
|
79 | - } |
|
67 | + public function __construct(IAppManager $appManager, |
|
68 | + IURLGenerator $urlGenerator, |
|
69 | + IFactory $l10nFac, |
|
70 | + IUserSession $userSession, |
|
71 | + IGroupManager $groupManager, |
|
72 | + IConfig $config) { |
|
73 | + $this->appManager = $appManager; |
|
74 | + $this->urlGenerator = $urlGenerator; |
|
75 | + $this->l10nFac = $l10nFac; |
|
76 | + $this->userSession = $userSession; |
|
77 | + $this->groupManager = $groupManager; |
|
78 | + $this->config = $config; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Creates a new navigation entry |
|
83 | - * |
|
84 | - * @param array|\Closure $entry Array containing: id, name, order, icon and href key |
|
85 | - * The use of a closure is preferred, because it will avoid |
|
86 | - * loading the routing of your app, unless required. |
|
87 | - * @return void |
|
88 | - */ |
|
89 | - public function add($entry) { |
|
90 | - if ($entry instanceof \Closure) { |
|
91 | - $this->closureEntries[] = $entry; |
|
92 | - return; |
|
93 | - } |
|
81 | + /** |
|
82 | + * Creates a new navigation entry |
|
83 | + * |
|
84 | + * @param array|\Closure $entry Array containing: id, name, order, icon and href key |
|
85 | + * The use of a closure is preferred, because it will avoid |
|
86 | + * loading the routing of your app, unless required. |
|
87 | + * @return void |
|
88 | + */ |
|
89 | + public function add($entry) { |
|
90 | + if ($entry instanceof \Closure) { |
|
91 | + $this->closureEntries[] = $entry; |
|
92 | + return; |
|
93 | + } |
|
94 | 94 | |
95 | - $entry['active'] = false; |
|
96 | - if (!isset($entry['icon'])) { |
|
97 | - $entry['icon'] = ''; |
|
98 | - } |
|
99 | - if (!isset($entry['classes'])) { |
|
100 | - $entry['classes'] = ''; |
|
101 | - } |
|
102 | - if (!isset($entry['type'])) { |
|
103 | - $entry['type'] = 'link'; |
|
104 | - } |
|
105 | - $this->entries[$entry['id']] = $entry; |
|
106 | - } |
|
95 | + $entry['active'] = false; |
|
96 | + if (!isset($entry['icon'])) { |
|
97 | + $entry['icon'] = ''; |
|
98 | + } |
|
99 | + if (!isset($entry['classes'])) { |
|
100 | + $entry['classes'] = ''; |
|
101 | + } |
|
102 | + if (!isset($entry['type'])) { |
|
103 | + $entry['type'] = 'link'; |
|
104 | + } |
|
105 | + $this->entries[$entry['id']] = $entry; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Get a list of navigation entries |
|
110 | - * |
|
111 | - * @param string $type type of the navigation entries |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - public function getAll(string $type = 'link'): array { |
|
115 | - $this->init(); |
|
116 | - foreach ($this->closureEntries as $c) { |
|
117 | - $this->add($c()); |
|
118 | - } |
|
119 | - $this->closureEntries = []; |
|
108 | + /** |
|
109 | + * Get a list of navigation entries |
|
110 | + * |
|
111 | + * @param string $type type of the navigation entries |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + public function getAll(string $type = 'link'): array { |
|
115 | + $this->init(); |
|
116 | + foreach ($this->closureEntries as $c) { |
|
117 | + $this->add($c()); |
|
118 | + } |
|
119 | + $this->closureEntries = []; |
|
120 | 120 | |
121 | - $result = $this->entries; |
|
122 | - if ($type !== 'all') { |
|
123 | - $result = array_filter($this->entries, function ($entry) use ($type) { |
|
124 | - return $entry['type'] === $type; |
|
125 | - }); |
|
126 | - } |
|
121 | + $result = $this->entries; |
|
122 | + if ($type !== 'all') { |
|
123 | + $result = array_filter($this->entries, function ($entry) use ($type) { |
|
124 | + return $entry['type'] === $type; |
|
125 | + }); |
|
126 | + } |
|
127 | 127 | |
128 | - return $this->proceedNavigation($result); |
|
129 | - } |
|
128 | + return $this->proceedNavigation($result); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Sort navigation entries by order, name and set active flag |
|
133 | - * |
|
134 | - * @param array $list |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - private function proceedNavigation(array $list): array { |
|
138 | - uasort($list, function ($a, $b) { |
|
139 | - if (isset($a['order']) && isset($b['order'])) { |
|
140 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
141 | - } elseif (isset($a['order']) || isset($b['order'])) { |
|
142 | - return isset($a['order']) ? -1 : 1; |
|
143 | - } else { |
|
144 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
145 | - } |
|
146 | - }); |
|
131 | + /** |
|
132 | + * Sort navigation entries by order, name and set active flag |
|
133 | + * |
|
134 | + * @param array $list |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + private function proceedNavigation(array $list): array { |
|
138 | + uasort($list, function ($a, $b) { |
|
139 | + if (isset($a['order']) && isset($b['order'])) { |
|
140 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
141 | + } elseif (isset($a['order']) || isset($b['order'])) { |
|
142 | + return isset($a['order']) ? -1 : 1; |
|
143 | + } else { |
|
144 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
145 | + } |
|
146 | + }); |
|
147 | 147 | |
148 | - $activeApp = $this->getActiveEntry(); |
|
149 | - if ($activeApp !== null) { |
|
150 | - foreach ($list as $index => &$navEntry) { |
|
151 | - if ($navEntry['id'] == $activeApp) { |
|
152 | - $navEntry['active'] = true; |
|
153 | - } else { |
|
154 | - $navEntry['active'] = false; |
|
155 | - } |
|
156 | - } |
|
157 | - unset($navEntry); |
|
158 | - } |
|
148 | + $activeApp = $this->getActiveEntry(); |
|
149 | + if ($activeApp !== null) { |
|
150 | + foreach ($list as $index => &$navEntry) { |
|
151 | + if ($navEntry['id'] == $activeApp) { |
|
152 | + $navEntry['active'] = true; |
|
153 | + } else { |
|
154 | + $navEntry['active'] = false; |
|
155 | + } |
|
156 | + } |
|
157 | + unset($navEntry); |
|
158 | + } |
|
159 | 159 | |
160 | - return $list; |
|
161 | - } |
|
160 | + return $list; |
|
161 | + } |
|
162 | 162 | |
163 | 163 | |
164 | - /** |
|
165 | - * removes all the entries |
|
166 | - */ |
|
167 | - public function clear($loadDefaultLinks = true) { |
|
168 | - $this->entries = []; |
|
169 | - $this->closureEntries = []; |
|
170 | - $this->init = !$loadDefaultLinks; |
|
171 | - } |
|
164 | + /** |
|
165 | + * removes all the entries |
|
166 | + */ |
|
167 | + public function clear($loadDefaultLinks = true) { |
|
168 | + $this->entries = []; |
|
169 | + $this->closureEntries = []; |
|
170 | + $this->init = !$loadDefaultLinks; |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * Sets the current navigation entry of the currently running app |
|
175 | - * @param string $id of the app entry to activate (from added $entry) |
|
176 | - */ |
|
177 | - public function setActiveEntry($id) { |
|
178 | - $this->activeEntry = $id; |
|
179 | - } |
|
173 | + /** |
|
174 | + * Sets the current navigation entry of the currently running app |
|
175 | + * @param string $id of the app entry to activate (from added $entry) |
|
176 | + */ |
|
177 | + public function setActiveEntry($id) { |
|
178 | + $this->activeEntry = $id; |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * gets the active Menu entry |
|
183 | - * @return string id or empty string |
|
184 | - * |
|
185 | - * This function returns the id of the active navigation entry (set by |
|
186 | - * setActiveEntry |
|
187 | - */ |
|
188 | - public function getActiveEntry() { |
|
189 | - return $this->activeEntry; |
|
190 | - } |
|
181 | + /** |
|
182 | + * gets the active Menu entry |
|
183 | + * @return string id or empty string |
|
184 | + * |
|
185 | + * This function returns the id of the active navigation entry (set by |
|
186 | + * setActiveEntry |
|
187 | + */ |
|
188 | + public function getActiveEntry() { |
|
189 | + return $this->activeEntry; |
|
190 | + } |
|
191 | 191 | |
192 | - private function init() { |
|
193 | - if ($this->init) { |
|
194 | - return; |
|
195 | - } |
|
196 | - $this->init = true; |
|
192 | + private function init() { |
|
193 | + if ($this->init) { |
|
194 | + return; |
|
195 | + } |
|
196 | + $this->init = true; |
|
197 | 197 | |
198 | - $l = $this->l10nFac->get('lib'); |
|
199 | - if ($this->config->getSystemValue('knowledgebaseenabled', true)) { |
|
200 | - $this->add([ |
|
201 | - 'type' => 'settings', |
|
202 | - 'id' => 'help', |
|
203 | - 'order' => 6, |
|
204 | - 'href' => $this->urlGenerator->linkToRoute('settings.Help.help'), |
|
205 | - 'name' => $l->t('Help'), |
|
206 | - 'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'), |
|
207 | - ]); |
|
208 | - } |
|
198 | + $l = $this->l10nFac->get('lib'); |
|
199 | + if ($this->config->getSystemValue('knowledgebaseenabled', true)) { |
|
200 | + $this->add([ |
|
201 | + 'type' => 'settings', |
|
202 | + 'id' => 'help', |
|
203 | + 'order' => 6, |
|
204 | + 'href' => $this->urlGenerator->linkToRoute('settings.Help.help'), |
|
205 | + 'name' => $l->t('Help'), |
|
206 | + 'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'), |
|
207 | + ]); |
|
208 | + } |
|
209 | 209 | |
210 | - if ($this->userSession->isLoggedIn()) { |
|
211 | - if ($this->isAdmin()) { |
|
212 | - // App management |
|
213 | - $this->add([ |
|
214 | - 'type' => 'settings', |
|
215 | - 'id' => 'core_apps', |
|
216 | - 'order' => 4, |
|
217 | - 'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'), |
|
218 | - 'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'), |
|
219 | - 'name' => $l->t('Apps'), |
|
220 | - ]); |
|
221 | - } |
|
210 | + if ($this->userSession->isLoggedIn()) { |
|
211 | + if ($this->isAdmin()) { |
|
212 | + // App management |
|
213 | + $this->add([ |
|
214 | + 'type' => 'settings', |
|
215 | + 'id' => 'core_apps', |
|
216 | + 'order' => 4, |
|
217 | + 'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'), |
|
218 | + 'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'), |
|
219 | + 'name' => $l->t('Apps'), |
|
220 | + ]); |
|
221 | + } |
|
222 | 222 | |
223 | - // Personal and (if applicable) admin settings |
|
224 | - $this->add([ |
|
225 | - 'type' => 'settings', |
|
226 | - 'id' => 'settings', |
|
227 | - 'order' => 2, |
|
228 | - 'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'), |
|
229 | - 'name' => $l->t('Settings'), |
|
230 | - 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
|
231 | - ]); |
|
223 | + // Personal and (if applicable) admin settings |
|
224 | + $this->add([ |
|
225 | + 'type' => 'settings', |
|
226 | + 'id' => 'settings', |
|
227 | + 'order' => 2, |
|
228 | + 'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'), |
|
229 | + 'name' => $l->t('Settings'), |
|
230 | + 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
|
231 | + ]); |
|
232 | 232 | |
233 | - $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator); |
|
234 | - if ($logoutUrl !== '') { |
|
235 | - // Logout |
|
236 | - $this->add([ |
|
237 | - 'type' => 'settings', |
|
238 | - 'id' => 'logout', |
|
239 | - 'order' => 99999, |
|
240 | - 'href' => $logoutUrl, |
|
241 | - 'name' => $l->t('Log out'), |
|
242 | - 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'), |
|
243 | - ]); |
|
244 | - } |
|
233 | + $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator); |
|
234 | + if ($logoutUrl !== '') { |
|
235 | + // Logout |
|
236 | + $this->add([ |
|
237 | + 'type' => 'settings', |
|
238 | + 'id' => 'logout', |
|
239 | + 'order' => 99999, |
|
240 | + 'href' => $logoutUrl, |
|
241 | + 'name' => $l->t('Log out'), |
|
242 | + 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'), |
|
243 | + ]); |
|
244 | + } |
|
245 | 245 | |
246 | - if ($this->isSubadmin()) { |
|
247 | - // User management |
|
248 | - $this->add([ |
|
249 | - 'type' => 'settings', |
|
250 | - 'id' => 'core_users', |
|
251 | - 'order' => 5, |
|
252 | - 'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'), |
|
253 | - 'name' => $l->t('Users'), |
|
254 | - 'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'), |
|
255 | - ]); |
|
256 | - } |
|
257 | - } |
|
246 | + if ($this->isSubadmin()) { |
|
247 | + // User management |
|
248 | + $this->add([ |
|
249 | + 'type' => 'settings', |
|
250 | + 'id' => 'core_users', |
|
251 | + 'order' => 5, |
|
252 | + 'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'), |
|
253 | + 'name' => $l->t('Users'), |
|
254 | + 'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'), |
|
255 | + ]); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - if ($this->appManager === 'null') { |
|
260 | - return; |
|
261 | - } |
|
259 | + if ($this->appManager === 'null') { |
|
260 | + return; |
|
261 | + } |
|
262 | 262 | |
263 | - if ($this->userSession->isLoggedIn()) { |
|
264 | - $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser()); |
|
265 | - } else { |
|
266 | - $apps = $this->appManager->getInstalledApps(); |
|
267 | - } |
|
263 | + if ($this->userSession->isLoggedIn()) { |
|
264 | + $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser()); |
|
265 | + } else { |
|
266 | + $apps = $this->appManager->getInstalledApps(); |
|
267 | + } |
|
268 | 268 | |
269 | - foreach ($apps as $app) { |
|
270 | - if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) { |
|
271 | - continue; |
|
272 | - } |
|
269 | + foreach ($apps as $app) { |
|
270 | + if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) { |
|
271 | + continue; |
|
272 | + } |
|
273 | 273 | |
274 | - // load plugins and collections from info.xml |
|
275 | - $info = $this->appManager->getAppInfo($app); |
|
276 | - if (!isset($info['navigations']['navigation'])) { |
|
277 | - continue; |
|
278 | - } |
|
279 | - foreach ($info['navigations']['navigation'] as $key => $nav) { |
|
280 | - if (!isset($nav['name'])) { |
|
281 | - continue; |
|
282 | - } |
|
283 | - if (!isset($nav['route'])) { |
|
284 | - continue; |
|
285 | - } |
|
286 | - $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
|
287 | - if ($role === 'admin' && !$this->isAdmin()) { |
|
288 | - continue; |
|
289 | - } |
|
290 | - $l = $this->l10nFac->get($app); |
|
291 | - $id = $nav['id'] ?? $app . ($key === 0 ? '' : $key); |
|
292 | - $order = isset($nav['order']) ? $nav['order'] : 100; |
|
293 | - $type = isset($nav['type']) ? $nav['type'] : 'link'; |
|
294 | - $route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : ''; |
|
295 | - $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
|
296 | - foreach ([$icon, "$app.svg"] as $i) { |
|
297 | - try { |
|
298 | - $icon = $this->urlGenerator->imagePath($app, $i); |
|
299 | - break; |
|
300 | - } catch (\RuntimeException $ex) { |
|
301 | - // no icon? - ignore it then |
|
302 | - } |
|
303 | - } |
|
304 | - if ($icon === null) { |
|
305 | - $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); |
|
306 | - } |
|
274 | + // load plugins and collections from info.xml |
|
275 | + $info = $this->appManager->getAppInfo($app); |
|
276 | + if (!isset($info['navigations']['navigation'])) { |
|
277 | + continue; |
|
278 | + } |
|
279 | + foreach ($info['navigations']['navigation'] as $key => $nav) { |
|
280 | + if (!isset($nav['name'])) { |
|
281 | + continue; |
|
282 | + } |
|
283 | + if (!isset($nav['route'])) { |
|
284 | + continue; |
|
285 | + } |
|
286 | + $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
|
287 | + if ($role === 'admin' && !$this->isAdmin()) { |
|
288 | + continue; |
|
289 | + } |
|
290 | + $l = $this->l10nFac->get($app); |
|
291 | + $id = $nav['id'] ?? $app . ($key === 0 ? '' : $key); |
|
292 | + $order = isset($nav['order']) ? $nav['order'] : 100; |
|
293 | + $type = isset($nav['type']) ? $nav['type'] : 'link'; |
|
294 | + $route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : ''; |
|
295 | + $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
|
296 | + foreach ([$icon, "$app.svg"] as $i) { |
|
297 | + try { |
|
298 | + $icon = $this->urlGenerator->imagePath($app, $i); |
|
299 | + break; |
|
300 | + } catch (\RuntimeException $ex) { |
|
301 | + // no icon? - ignore it then |
|
302 | + } |
|
303 | + } |
|
304 | + if ($icon === null) { |
|
305 | + $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); |
|
306 | + } |
|
307 | 307 | |
308 | - $this->add([ |
|
309 | - 'id' => $id, |
|
310 | - 'order' => $order, |
|
311 | - 'href' => $route, |
|
312 | - 'icon' => $icon, |
|
313 | - 'type' => $type, |
|
314 | - 'name' => $l->t($nav['name']), |
|
315 | - ]); |
|
316 | - } |
|
317 | - } |
|
318 | - } |
|
308 | + $this->add([ |
|
309 | + 'id' => $id, |
|
310 | + 'order' => $order, |
|
311 | + 'href' => $route, |
|
312 | + 'icon' => $icon, |
|
313 | + 'type' => $type, |
|
314 | + 'name' => $l->t($nav['name']), |
|
315 | + ]); |
|
316 | + } |
|
317 | + } |
|
318 | + } |
|
319 | 319 | |
320 | - private function isAdmin() { |
|
321 | - $user = $this->userSession->getUser(); |
|
322 | - if ($user !== null) { |
|
323 | - return $this->groupManager->isAdmin($user->getUID()); |
|
324 | - } |
|
325 | - return false; |
|
326 | - } |
|
320 | + private function isAdmin() { |
|
321 | + $user = $this->userSession->getUser(); |
|
322 | + if ($user !== null) { |
|
323 | + return $this->groupManager->isAdmin($user->getUID()); |
|
324 | + } |
|
325 | + return false; |
|
326 | + } |
|
327 | 327 | |
328 | - private function isSubadmin() { |
|
329 | - $user = $this->userSession->getUser(); |
|
330 | - if ($user !== null) { |
|
331 | - return $this->groupManager->getSubAdmin()->isSubAdmin($user); |
|
332 | - } |
|
333 | - return false; |
|
334 | - } |
|
328 | + private function isSubadmin() { |
|
329 | + $user = $this->userSession->getUser(); |
|
330 | + if ($user !== null) { |
|
331 | + return $this->groupManager->getSubAdmin()->isSubAdmin($user); |
|
332 | + } |
|
333 | + return false; |
|
334 | + } |
|
335 | 335 | } |