Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(dashboard): implement widget item api v2 #10250

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 59 additions & 5 deletions lib/Dashboard/TalkWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* @license GNU AGPL version 3 or any later version
*
Expand Down Expand Up @@ -40,16 +41,17 @@
use OCP\Dashboard\IConditionalWidget;
use OCP\Dashboard\IIconWidget;
use OCP\Dashboard\IOptionWidget;
use OCP\Dashboard\IReloadableWidget;
use OCP\Dashboard\Model\WidgetButton;
use OCP\Dashboard\Model\WidgetItem;
use OCP\Dashboard\Model\WidgetItems;
use OCP\Dashboard\Model\WidgetOptions;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Util;

class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidget, IConditionalWidget {
class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidget, IConditionalWidget, IReloadableWidget {

public function __construct(
protected IUserSession $userSession,
Expand Down Expand Up @@ -112,7 +114,7 @@ public function getWidgetButtons(string $userId): array {
$buttons[] = new WidgetButton(
WidgetButton::TYPE_MORE,
$this->url->linkToRouteAbsolute('spreed.Page.index'),
$this->l10n->t('More unread mentions')
$this->l10n->t('More conversations')
);
return $buttons;
}
Expand All @@ -135,8 +137,6 @@ public function getUrl(): ?string {
* @inheritDoc
*/
public function load(): void {
Util::addStyle('spreed', 'icons');
Util::addScript('spreed', 'talk-dashboard');
}

public function getItems(string $userId, ?string $since = null, int $limit = 7): array {
Expand Down Expand Up @@ -170,6 +170,53 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
return $result;
}

/**
* @inheritDoc
*/
public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems {
$allRooms = $this->manager->getRoomsForUser($userId, [], true);

$rooms = [];
$mentions = [];
foreach ($allRooms as $room) {
if ($room->getObjectType() === BreakoutRoom::PARENT_OBJECT_TYPE) {
continue;
}
$rooms[] = $room;

$participant = $this->participantService->getParticipant($room, $userId);
$attendee = $participant->getAttendee();
if ($room->getCallFlag() !== Participant::FLAG_DISCONNECTED
|| $attendee->getLastMentionMessage() > $attendee->getLastReadMessage()
|| (
($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER)
&& $room->getLastMessage()
&& $room->getLastMessage()->getId() > $attendee->getLastReadMessage()
)) {
$mentions[] = $room;
}
}

$roomsToReturn = $rooms;
if (!empty($mentions)) {
$roomsToReturn = $mentions;
}

uasort($roomsToReturn, [$this, 'sortRooms']);
$roomsToReturn = array_slice($roomsToReturn, 0, $limit);

$result = [];
foreach ($roomsToReturn as $room) {
$result[] = $this->prepareRoom($room, $userId);
}

return new WidgetItems(
$result,
empty($result) ? $this->l10n->t('Say hi to your friends and colleagues!') : '',
empty($mentions) ? $this->l10n->t('No unread mentions') : '',
);
}

protected function prepareRoom(Room $room, string $userId): WidgetItem {
$participant = $this->participantService->getParticipant($room, $userId);
$subtitle = '';
Expand Down Expand Up @@ -219,4 +266,11 @@ protected function sortRooms(Room $roomA, Room $roomB): int {

return $roomA->getLastActivity() >= $roomB->getLastActivity() ? -1 : 1;
}

/**
* @inheritDoc
*/
public function getReloadInterval(): int {
return 30;
}
}
56 changes: 0 additions & 56 deletions src/dashboard.js

This file was deleted.

Loading
Loading