FIX: Do not count thread messages for channel unreads (#21126)

We currently don't have a nice UI to show unread messages for the thread,
and it will take some time to create one. For now, this commit makes it so
new messages inside a thread do not count towards a chat channel's unread
counts, and new messages sent in a thread do not update a user's `last_read_message_id`
for a channel.

In addition, this PR refactors the `Chat::ChannelFetcher` to use the `Chat::ChannelUnreadsQuery`
query class for consistency, and made said class able to return zeroed-out records
for channels the user is not a member of.

Finally, a small bug is fixed here where if a user's `last_read_message_id` for
a channel was a thread's OM ID, then the thread OM would not show in the
main channel stream for them until another reply to the channel was posted.
This commit is contained in:
Martin Brennan
2023-04-19 08:53:51 +10:00
committed by GitHub
parent 0cd8659b06
commit a8cf8e57b4
11 changed files with 256 additions and 82 deletions

View File

@ -85,5 +85,17 @@ describe "Channel thread message echoing", type: :system, js: true do
channel_page.message_by_id_selector(thread.replies.last.id),
)
end
it "does show the thread original_message if it is the last message in the channel" do
new_thread = Fabricate(:chat_thread, channel: channel)
current_user
.user_chat_channel_memberships
.find_by(chat_channel: channel)
.update!(last_read_message_id: new_thread.original_message_id)
chat_page.visit_channel(channel)
expect(channel_page).to have_css(
channel_page.message_by_id_selector(new_thread.original_message_id),
)
end
end
end

View File

@ -143,6 +143,22 @@ describe "Single thread in side panel", type: :system, js: true do
expect(open_thread).to have_message(thread.id, text: "this is a test message")
end
end
it "does not mark the channel unread if another user sends a message in the thread" do
other_user = Fabricate(:user)
chat_system_user_bootstrap(user: other_user, channel: channel)
Chat::MessageCreator.create(
chat_channel: channel,
user: other_user,
content: "Hello world!",
thread_id: thread.id,
)
sign_in(current_user)
chat_page.visit_channel(channel)
expect(page).not_to have_css(
".sidebar-section-link.channel-#{channel.id} .sidebar-section-link-suffix.unread",
)
end
end
context "when using mobile" do