FIX: stuck notification for mentions within threads (#30546)

For mentions within threads, the mentioned user can experience a stuck notification. This is due to thread memberships only being created for users who interact with a thread. Without the membership we cannot track if the message containing the mention was read by the user.

The solution to this explored in this PR is:

- auto add memberships for mentioned users (only direct mentions for performance reasons).
- update channel/thread unread queries to check notification read status AND thread membership last read message id when counting mentions.

Previously the mention count would remain until the user notification (containing the mention) was read. However this only happens if the user clicks the notification or clicks dismiss all notifications. When a user navigated to the thread without clicking the notification, the green/urgent badge on chat would remain even after a hard page refresh.
This commit is contained in:
David Battersby
2025-01-06 17:26:37 +04:00
committed by GitHub
parent 27c557bc89
commit 67d568f709
7 changed files with 34 additions and 10 deletions

View File

@ -787,6 +787,22 @@ describe Chat::Message do
expect(message.user_mentions.pluck(:target_id)).to match_array(already_mentioned)
expect(message.user_mentions.pluck(:id)).to include(*existing_mention_ids) # the mentions weren't recreated
end
it "creates thread memberships for mentioned users when replying to a thread" do
thread = Fabricate(:chat_thread)
thread_message =
Fabricate(
:chat_message,
chat_channel: thread.channel,
thread: thread,
message: "cc @#{user3.username} and @#{user4.username}",
)
thread_message.cook
thread_message.upsert_mentions
expect(thread.user_chat_thread_memberships.pluck(:user_id)).to include(user3.id, user4.id)
end
end
context "with group mentions" do