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

@ -325,5 +325,43 @@ describe Chat::Mailer do
user.user_option.update!(allow_private_messages: false)
expect_not_enqueued
end
it "queues a chat summary email when message is the original thread message" do
Fabricate(:chat_thread, channel: direct_message, original_message: Chat::Message.last)
expect_enqueued
end
end
describe "in direct message channel with threads" do
fab!(:dm_channel) { Fabricate(:direct_message_channel, users: [user, other]) }
fab!(:message) do
Fabricate(:chat_message, chat_channel: dm_channel, user: other, created_at: 2.weeks.ago)
end
fab!(:thread) do
Fabricate(:chat_thread, channel: dm_channel, original_message: message, with_replies: 1)
end
it "does not queue a chat summary email for thread replies" do
expect_not_enqueued
end
it "queues a chat summary email when user is watching the thread" do
Fabricate(
:user_chat_thread_membership,
user: user,
thread: thread,
notification_level: Chat::NotificationLevels.all[:watching],
)
expect_enqueued
end
it "does not queue a chat summary for threads watched by other users" do
thread.membership_for(other).update!(
notification_level: Chat::NotificationLevels.all[:watching],
)
expect_not_enqueued
end
end
end

View File

@ -265,6 +265,7 @@ Fabricator(:chat_thread, class_name: "Chat::Thread") do
transients[:with_replies],
:chat_message,
thread: thread,
chat_channel_id: thread.channel_id,
use_service: transients[:use_service],
)
.each { |message| thread.add(message.user) }

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