From 4aa043852ca8d43785b9aa77fc95d31ce6afb058 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2024 10:48:27 +0200 Subject: [PATCH] fix(dashboard): Don't show read one-to-one when the last system message is newer Signed-off-by: Joas Schilling --- lib/Dashboard/TalkWidget.php | 49 +++++++++++++------ .../features/integration/dashboard.feature | 5 ++ 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/lib/Dashboard/TalkWidget.php b/lib/Dashboard/TalkWidget.php index 34f820d213b..a5feb0b6c73 100644 --- a/lib/Dashboard/TalkWidget.php +++ b/lib/Dashboard/TalkWidget.php @@ -26,6 +26,7 @@ namespace OCA\Talk\Dashboard; +use OCA\Talk\Chat\ChatManager; use OCA\Talk\Chat\MessageParser; use OCA\Talk\Config; use OCA\Talk\Manager; @@ -62,6 +63,7 @@ public function __construct( protected AvatarService $avatarService, protected ParticipantService $participantService, protected MessageParser $messageParser, + protected ChatManager $chatManager, protected ITimeFactory $timeFactory, ) { } @@ -147,15 +149,21 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7): return false; } + if ($room->getCallFlag() !== Participant::FLAG_DISCONNECTED) { + return true; + } + $participant = $this->participantService->getParticipant($room, $userId); $attendee = $participant->getAttendee(); - return $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() - ); + + if ($attendee->getLastMentionMessage() > $attendee->getLastReadMessage()) { + return true; + } + + return ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) + && $room->getLastMessage() + && $room->getLastMessage()->getId() > $attendee->getLastReadMessage() + && $this->chatManager->getUnreadCount($room, $attendee->getLastReadMessage()) > 0; }); uasort($rooms, [$this, 'sortRooms']); @@ -186,14 +194,27 @@ public function getItemsV2(string $userId, ?string $since = null, int $limit = 7 $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() - )) { + if ($room->getCallFlag() !== Participant::FLAG_DISCONNECTED) { + // Call in progress $mentions[] = $room; + continue; + } + + if ($attendee->getLastMentionMessage() > $attendee->getLastReadMessage()) { + // Really mentioned + $mentions[] = $room; + continue; + } + + if (($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) + && $room->getLastMessage()?->getId() > $attendee->getLastReadMessage()) { + // If there are "unread" messages in one-to-one or former one-to-one + // we check if they are actual messages or system messages not + // considered by the read-marker + if ($this->chatManager->getUnreadCount($room, $attendee->getLastReadMessage()) > 0) { + // Unread message in one-to-one are considered "mentions" + $mentions[] = $room; + } } } diff --git a/tests/integration/features/integration/dashboard.feature b/tests/integration/features/integration/dashboard.feature index 233ba534acd..018427dda0c 100644 --- a/tests/integration/features/integration/dashboard.feature +++ b/tests/integration/features/integration/dashboard.feature @@ -2,6 +2,7 @@ Feature: integration/dashboard Background: Given user "participant1" exists Given user "participant2" exists + Given user "participant3" exists Scenario: User gets the available dashboard widgets When user "participant1" sees the following entry when loading the list of dashboard widgets (v1) @@ -16,6 +17,10 @@ Feature: integration/dashboard Given user "participant2" creates room "one-to-one room" (v4) | roomType | 1 | | invite | participant1 | + Given user "participant1" creates room "former one-to-one room" (v4) + | roomType | 1 | + | invite | participant3 | + And user "participant3" is deleted And user "participant2" sends message "Hello" to room "one-to-one room" with 201 And wait for 1 second Given user "participant2" creates room "group room" (v4)