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

fix(dashboard): Don't show read one-to-one when the last system messa… #12072

Merged
merged 1 commit into from
Apr 12, 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
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
Loading