l10n = $l10n; $this->dateTimeFormatter = $dateTimeFormatter; $this->urlGenerator = $urlGenerator; $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-dark'; } /** * @inheritDoc */ public function getIconUrl(): string { return $this->urlGenerator->getAbsoluteURL( $this->urlGenerator->imagePath(Application::APP_ID, 'app-dark.svg') ); } /** * @inheritDoc */ public function getUrl(): ?string { return null; } /** * @inheritDoc */ public function load(): void { } private function getWidgetData(string $userId, ?string $since = null, int $limit = 7): array { // Fetch status updates and filter current user $recentStatusUpdates = array_slice( array_filter( $this->service->findAllRecentStatusChanges($limit + 1, 0), static function (UserStatus $status) use ($userId, $since): bool { return $status->getUserId() !== $userId && ($since === null || $status->getStatusTimestamp() > (int)$since); } ), 0, $limit ); return 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() === IUserStatus::INVISIBLE ? IUserStatus::OFFLINE : $status->getStatus(), 'icon' => $status->getCustomIcon(), 'message' => $status->getCustomMessage(), 'timestamp' => $status->getStatusMessageTimestamp(), ]; }, $recentStatusUpdates); } /** * @inheritDoc */ public function getItems(string $userId, ?string $since = null, int $limit = 7): array { $widgetItemsData = $this->getWidgetData($userId, $since, $limit); return array_map(function (array $widgetData) { $formattedDate = $this->dateTimeFormatter->formatTimeSpan($widgetData['timestamp']); return new WidgetItem( $widgetData['displayName'], $widgetData['icon'] . ($widgetData['icon'] ? ' ' : '') . $widgetData['message'] . ', ' . $formattedDate, // https://nextcloud.local/index.php/u/julien $this->urlGenerator->getAbsoluteURL( $this->urlGenerator->linkToRoute('core.ProfilePage.index', ['targetUserId' => $widgetData['userId']]) ), $this->urlGenerator->getAbsoluteURL( $this->urlGenerator->linkToRoute('core.avatar.getAvatar', ['userId' => $widgetData['userId'], 'size' => 44]) ), (string)$widgetData['timestamp'] ); }, $widgetItemsData); } /** * @inheritDoc */ public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems { $items = $this->getItems($userId, $since, $limit); return new WidgetItems( $items, count($items) === 0 ? $this->l10n->t('No recent status changes') : '', ); } public function getWidgetOptions(): WidgetOptions { return new WidgetOptions(true); } }