FEATURE: Show unread in sidebar for unread channel threads (#22342)

This commit makes it so that when the user has unread threads
for a channel we show a blue dot in the sidebar (or channel index
for mobile/drawer).

This blue dot is slightly different from the channel unread messages:

1. It will only show if the new thread messages were created since
   the user last viewed the channel
2. It will be cleared when the user views the channel, but the threads
   are still considered unread because we want the user to click into
   the thread list to view them

This necessitates a change to the current user serializer to also
include the unread thread overview, which is all unread threads
across all channels and their last reply date + time.
This commit is contained in:
Martin Brennan
2023-07-17 13:00:49 +10:00
committed by GitHub
parent edc837eaf5
commit 07c3782e51
31 changed files with 459 additions and 132 deletions

View File

@ -9,6 +9,7 @@ RSpec.describe Chat::TrackingStateReportQuery do
include_missing_memberships: include_missing_memberships,
include_threads: include_threads,
include_read: include_read,
include_last_reply_details: include_last_reply_details,
)
end
@ -20,6 +21,7 @@ RSpec.describe Chat::TrackingStateReportQuery do
let(:include_missing_memberships) { false }
let(:include_threads) { false }
let(:include_read) { true }
let(:include_last_reply_details) { false }
context "when channel_ids empty" do
it "returns empty object for channel_tracking" do
expect(query.channel_tracking).to eq({})
@ -129,6 +131,56 @@ RSpec.describe Chat::TrackingStateReportQuery do
)
end
context "when include_last_reply_details is true" do
let(:include_last_reply_details) { true }
before do
thread_1.add(current_user)
thread_2.add(current_user)
Fabricate(:chat_message, chat_channel: channel_1, thread: thread_1)
Fabricate(:chat_message, chat_channel: channel_2, thread: thread_2)
end
it "gets the last_reply_created_at for each thread based on the last_message" do
expect(query.thread_tracking).to eq(
{
thread_1.id => {
unread_count: 1,
mention_count: 0,
channel_id: channel_1.id,
last_reply_created_at: thread_1.reload.last_message.created_at,
},
thread_2.id => {
unread_count: 1,
mention_count: 0,
channel_id: channel_2.id,
last_reply_created_at: thread_2.reload.last_message.created_at,
},
},
)
end
it "does not get the last_reply_created_at for threads where the last_message is deleted" do
thread_1.reload.last_message.trash!
expect(query.thread_tracking).to eq(
{
thread_1.id => {
unread_count: 0,
mention_count: 0,
channel_id: channel_1.id,
last_reply_created_at: nil,
},
thread_2.id => {
unread_count: 1,
mention_count: 0,
channel_id: channel_2.id,
last_reply_created_at: thread_2.reload.last_message.created_at,
},
},
)
end
end
context "when thread_ids and channel_ids is empty" do
let(:thread_ids) { [] }
let(:channel_ids) { [] }