Skip to content

Commit

Permalink
fix(dashboard): Don't show read one-to-one when the last system messa…
Browse files Browse the repository at this point in the history
…ge is newer

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Apr 12, 2024
1 parent d739a3c commit 4aa0438
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
49 changes: 35 additions & 14 deletions lib/Dashboard/TalkWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,6 +63,7 @@ public function __construct(
protected AvatarService $avatarService,
protected ParticipantService $participantService,
protected MessageParser $messageParser,
protected ChatManager $chatManager,
protected ITimeFactory $timeFactory,
) {
}
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions tests/integration/features/integration/dashboard.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 4aa0438

Please sign in to comment.