summaryrefslogtreecommitdiffstats
path: root/apps/user_status/lib/Dashboard
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2020-08-18 10:54:46 +0200
committerGeorg Ehrke <developer@georgehrke.com>2020-08-20 15:43:34 +0200
commitbd6a6cf3bff74dc5690fe032a4203165227f01d2 (patch)
treee66324bec9e142b859d171b051060850295bad5d /apps/user_status/lib/Dashboard
parent03603db486debbb31dfa05486f3b10338a28b50c (diff)
downloadnextcloud-server-bd6a6cf3bff74dc5690fe032a4203165227f01d2.tar.gz
nextcloud-server-bd6a6cf3bff74dc5690fe032a4203165227f01d2.zip
Add Status Dashboard
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/user_status/lib/Dashboard')
-rw-r--r--apps/user_status/lib/Dashboard/UserStatusWidget.php156
1 files changed, 156 insertions, 0 deletions
diff --git a/apps/user_status/lib/Dashboard/UserStatusWidget.php b/apps/user_status/lib/Dashboard/UserStatusWidget.php
new file mode 100644
index 00000000000..809aa000005
--- /dev/null
+++ b/apps/user_status/lib/Dashboard/UserStatusWidget.php
@@ -0,0 +1,156 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2020, Georg Ehrke
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+namespace OCA\UserStatus\Dashboard;
+
+use OCA\UserStatus\AppInfo\Application;
+use OCA\UserStatus\Db\UserStatus;
+use OCA\UserStatus\Service\StatusService;
+use OCP\Dashboard\IWidget;
+use OCP\IInitialStateService;
+use OCP\IL10N;
+use OCP\IUserManager;
+use OCP\IUserSession;
+
+/**
+ * Class UserStatusWidget
+ *
+ * @package OCA\UserStatus
+ */
+class UserStatusWidget implements IWidget {
+
+ /** @var IL10N */
+ private $l10n;
+
+ /** @var IInitialStateService */
+ private $initialStateService;
+
+ /** @var IUserManager */
+ private $userManager;
+
+ /** @var IUserSession */
+ private $userSession;
+
+ /** @var StatusService */
+ private $service;
+
+ /**
+ * UserStatusWidget constructor
+ *
+ * @param IL10N $l10n
+ * @param IInitialStateService $initialStateService
+ * @param IUserManager $userManager
+ * @param IUserSession $userSession
+ * @param StatusService $service
+ */
+ public function __construct(IL10N $l10n,
+ IInitialStateService $initialStateService,
+ IUserManager $userManager,
+ IUserSession $userSession,
+ StatusService $service) {
+ $this->l10n = $l10n;
+ $this->initialStateService = $initialStateService;
+ $this->userManager = $userManager;
+ $this->userSession = $userSession;
+ $this->service = $service;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getId(): string {
+ return Application::APP_ID;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getTitle(): string {
+ return $this->l10n->t('Recent statuses');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getOrder(): int {
+ return 5;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getIconClass(): string {
+ return 'icon-user-status';
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getUrl(): ?string {
+ return null;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function load(): void {
+ \OCP\Util::addScript(Application::APP_ID, 'dashboard');
+
+ $currentUser = $this->userSession->getUser();
+ if ($currentUser === null) {
+ $this->initialStateService->provideInitialState(Application::APP_ID, 'dashboard_data', []);
+ return;
+ }
+ $currentUserId = $currentUser->getUID();
+
+ // Fetch status updates and filter current user
+ $recentStatusUpdates = array_slice(
+ array_filter(
+ $this->service->findAllRecentStatusChanges(8, 0),
+ static function (UserStatus $status) use ($currentUserId): bool {
+ return $status->getUserId() !== $currentUserId;
+ }
+ ),
+ 0,
+ 7
+ );
+
+ $this->initialStateService->provideInitialState(Application::APP_ID, 'dashboard_data', array_map(function (UserStatus $status): array {
+ $user = $this->userManager->get($status->getUserId());
+ $displayName = $status->getUserId();
+ if ($user !== null) {
+ $displayName = $user->getDisplayName();
+ }
+
+ return [
+ 'userId' => $status->getUserId(),
+ 'displayName' => $displayName,
+ 'status' => $status->getStatus() === 'invisible' ? 'offline' : $status->getStatus(),
+ 'icon' => $status->getCustomIcon(),
+ 'message' => $status->getCustomMessage(),
+ 'timestamp' => $status->getStatusTimestamp(),
+ ];
+ }, $recentStatusUpdates));
+ }
+}