Skip to content

Commit

Permalink
Merge pull request #13214 from nextcloud/fix/unread-count-for-chat-wi…
Browse files Browse the repository at this point in the history
…th-shared-objects

fix(Chat): consider shared objects when marking unread
  • Loading branch information
nickvergessen authored Sep 10, 2024
2 parents bc22d4d + a6af2c8 commit ae83af9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Chat/ChatManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/features/chat-4/unread-messages.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

0 comments on commit ae83af9

Please sign in to comment.