FIX: delayed chat summary email (#31255)

Updates the chat summary email to account for:

- unread mentions in category channels (same as before)
- unread direct messages (now excluding threads)
- unread watched thread replies (for both channels and DM channels)

We have also reduced the window from 1 week down to 1 day for all 3
criteria. The DM unreads query is now properly selecting the first
unread message within the window (rather than the first message
regardless of read status).
This commit is contained in:
David Battersby
2025-02-24 14:25:52 +04:00
committed by GitHub
parent 18c8a8ffca
commit 342ab6f082
7 changed files with 228 additions and 36 deletions

View File

@ -579,4 +579,66 @@ describe UserNotifications do
end
end
end
describe "in a direct message channel with threads" do
fab!(:message) do
Fabricate(:chat_message, chat_channel: direct_message, user: other, created_at: 2.days.ago)
end
fab!(:thread) { Fabricate(:chat_thread, channel: direct_message, original_message: message) }
fab!(:reply) { Fabricate(:chat_message, chat_channel: direct_message, thread:, user: other) }
let(:watching) { Chat::NotificationLevels.all[:watching] }
it "does not send a chat summary email for thread replies" do
no_chat_summary_email
end
describe "when the user is watching the thread" do
before do
Fabricate(:user_chat_thread_membership, user: user, thread:, notification_level: watching)
end
it "sends a chat summary email" do
chat_summary_email
end
end
describe "when the user has 2 watched threads" do
fab!(:message_2) do
Fabricate(
:chat_message,
chat_channel: direct_message_2,
user: another,
created_at: 2.days.ago,
)
end
fab!(:thread_2) do
Fabricate(:chat_thread, channel: direct_message_2, original_message: message_2)
end
fab!(:thread_2_reply) do
Fabricate(:chat_message, chat_channel: direct_message_2, thread: thread_2, user: another)
end
before do
Fabricate(:user_chat_thread_membership, user: user, thread:, notification_level: watching)
Fabricate(
:user_chat_thread_membership,
user: user,
thread: thread_2,
notification_level: watching,
)
end
it "sends a chat summary email" do
chat_summary_with_subject(:watched_threads, channel: direct_message.title(user), count: 1)
end
end
describe "when another user is watching a thread" do
before { thread.membership_for(other).update!(notification_level: watching) }
it "does not send current user a chat summary email" do
no_chat_summary_email
end
end
end
end