From a6af2c83df430d82b7a57b84f874c8f429565f27 Mon Sep 17 00:00:00 2001 From: Sanskar Soni Date: Sun, 8 Sep 2024 07:54:59 +0530 Subject: [PATCH] fix(Chat): consider shared objects when marking unread Signed-off-by: Sanskar Soni --- lib/Chat/ChatManager.php | 2 +- lib/Controller/ChatController.php | 4 ++-- .../features/chat-4/unread-messages.feature | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php index 9843720dd65..d59075c6e17 100644 --- a/lib/Chat/ChatManager.php +++ b/lib/Chat/ChatManager.php @@ -705,7 +705,7 @@ public function getUnreadCount(Room $chat, int $lastReadMessage): int { $key = $chat->getId() . '-' . $lastReadMessage; $unreadCount = $this->unreadCountCache->get($key); if ($unreadCount === null) { - $unreadCount = $this->commentsManager->getNumberOfCommentsWithVerbsForObjectSinceComment('chat', (string)$chat->getId(), $lastReadMessage, [self::VERB_MESSAGE, 'object_shared']); + $unreadCount = $this->commentsManager->getNumberOfCommentsWithVerbsForObjectSinceComment('chat', (string)$chat->getId(), $lastReadMessage, [self::VERB_MESSAGE, self::VERB_OBJECT_SHARED]); $this->unreadCountCache->set($key, $unreadCount, 1800); } return $unreadCount; diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index 2aa44cdccac..25489c9b648 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -1123,8 +1123,8 @@ public function markUnread(): DataResponse { $previousMessage = $this->chatManager->getPreviousMessageWithVerb( $this->room, (int)$message->getId(), - [ChatManager::VERB_MESSAGE], - $message->getVerb() === ChatManager::VERB_MESSAGE + [ChatManager::VERB_MESSAGE, ChatManager::VERB_OBJECT_SHARED], + $message->getVerb() === ChatManager::VERB_MESSAGE || $message->getVerb() === ChatManager::VERB_OBJECT_SHARED ); $unreadId = (int)$previousMessage->getId(); } catch (NotFoundException $e) { diff --git a/tests/integration/features/chat-4/unread-messages.feature b/tests/integration/features/chat-4/unread-messages.feature index ca91b95e474..ff068e93c08 100644 --- a/tests/integration/features/chat-4/unread-messages.feature +++ b/tests/integration/features/chat-4/unread-messages.feature @@ -202,3 +202,21 @@ Feature: chat-2/unread-messages Then user "participant2" is participant of room "group room" (v4) | unreadMessages | | 1 | + + Scenario: marking conversation as unread marks last message as unread considering shared file + Given user "participant1" creates room "group room" (v4) + | roomType | 2 | + | roomName | room | + And user "participant1" sends message "Message 1" to room "group room" with 201 + And user "participant1" sends message "Message 2" to room "group room" with 201 + And user "participant1" shares "welcome.txt" with room "group room" + When user "participant1" marks room "group room" as unread with 200 + Then user "participant1" is participant of room "group room" (v4) + | unreadMessages | + | 1 | + When user "participant1" sends message "Message 3" to room "group room" with 201 + And user "participant1" marks room "group room" as unread with 200 + Then user "participant1" is participant of room "group room" (v4) + | unreadMessages | + | 1 | +