aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_status/lib/Controller
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-06-16 11:14:00 +0200
committerJoas Schilling <coding@schilljs.com>2021-06-16 11:32:32 +0200
commit38d2f978a6d720b7bbeab70fe7841d13e206a740 (patch)
treecad567fb9de665d5d8e01de1187085b08753f629 /apps/user_status/lib/Controller
parent0a9a5f006a94645d409748bf56b818c87e496e75 (diff)
downloadnextcloud-server-38d2f978a6d720b7bbeab70fe7841d13e206a740.tar.gz
nextcloud-server-38d2f978a6d720b7bbeab70fe7841d13e206a740.zip
Save a request everytime we send the heartbeat
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/user_status/lib/Controller')
-rw-r--r--apps/user_status/lib/Controller/HeartbeatController.php40
1 files changed, 29 insertions, 11 deletions
diff --git a/apps/user_status/lib/Controller/HeartbeatController.php b/apps/user_status/lib/Controller/HeartbeatController.php
index c0fc515518c..223ff4a0f45 100644
--- a/apps/user_status/lib/Controller/HeartbeatController.php
+++ b/apps/user_status/lib/Controller/HeartbeatController.php
@@ -25,7 +25,10 @@ declare(strict_types=1);
*/
namespace OCA\UserStatus\Controller;
+use OCA\UserStatus\Db\UserStatus;
+use OCA\UserStatus\Service\StatusService;
use OCP\AppFramework\Controller;
+use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -46,24 +49,20 @@ class HeartbeatController extends Controller {
/** @var ITimeFactory */
private $timeFactory;
- /**
- * HeartbeatController constructor.
- *
- * @param string $appName
- * @param IRequest $request
- * @param IEventDispatcher $eventDispatcher
- * @param IUserSession $userSession
- * @param ITimeFactory $timeFactory
- */
+ /** @var StatusService */
+ private $service;
+
public function __construct(string $appName,
IRequest $request,
IEventDispatcher $eventDispatcher,
IUserSession $userSession,
- ITimeFactory $timeFactory) {
+ ITimeFactory $timeFactory,
+ StatusService $service) {
parent::__construct($appName, $request);
$this->eventDispatcher = $eventDispatcher;
$this->userSession = $userSession;
$this->timeFactory = $timeFactory;
+ $this->service = $service;
}
/**
@@ -90,6 +89,25 @@ class HeartbeatController extends Controller {
)
);
- return new JSONResponse([], Http::STATUS_NO_CONTENT);
+ try {
+ $userStatus = $this->service->findByUserId($user->getUID());
+ } catch (DoesNotExistException $ex) {
+ return new JSONResponse([], Http::STATUS_NO_CONTENT);
+ }
+
+ return new JSONResponse($this->formatStatus($userStatus));
+ }
+
+ private function formatStatus(UserStatus $status): array {
+ return [
+ 'userId' => $status->getUserId(),
+ 'message' => $status->getCustomMessage(),
+ 'messageId' => $status->getMessageId(),
+ 'messageIsPredefined' => $status->getMessageId() !== null,
+ 'icon' => $status->getCustomIcon(),
+ 'clearAt' => $status->getClearAt(),
+ 'status' => $status->getStatus(),
+ 'statusIsUserDefined' => $status->getIsUserDefined(),
+ ];
}
}