FIX: only show relevent chat channel mentions in summary email (#27631)

Chat summary email should only contain mentions that are relevant to the current user.
This commit is contained in:
David Battersby 2024-06-27 15:53:40 +04:00 committed by GitHub
parent 4a6b79dead
commit 580bad3c02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 0 deletions

View File

@ -33,6 +33,7 @@ module Chat
AND chat_messages.created_at > now() - interval '1 week'
AND (uccm.last_read_message_id IS NULL OR uccm.last_read_message_id < chat_messages.id)
AND (uccm.last_unread_mention_when_emailed_id IS NULL OR uccm.last_unread_mention_when_emailed_id < chat_messages.id)
AND (chat_mentions.target_id = #{user.id} OR chat_mentions.type = 'Chat::AllMention')
AND NOT notifications.read
GROUP BY uccm.id
)

View File

@ -464,5 +464,45 @@ describe UserNotifications do
)
end
end
describe "when another user is mentioned in the channel and user receives a 1:1" do
before do
create_message(direct_message, "Hello, how are you?")
create_message(followed_channel, "Hey @#{another.username}", Chat::UserMention)
end
it "does not show the channel mention in the subject" do
chat_summary_with_subject(:chat_dm_1, name: direct_message.title(user), count: 1)
end
it "does not show the channel mention in the body" do
html = chat_summary_email.html_part.body.to_s
expect(html).to include(direct_message.title(user))
expect(html).not_to include(followed_channel.title(user))
end
end
describe "when mentioning @all in the channel and user receives a 1:1" do
before do
create_message(direct_message, "Hello, how are you?")
create_message(followed_channel, "Hey @all", Chat::AllMention)
end
it "shows both the channel mention and 1:1 in the subject" do
chat_summary_with_subject(
:chat_channel_and_dm,
channel: followed_channel.name,
name: direct_message.title(user),
)
end
it "shows both the channel mention and 1:1 in the body" do
html = chat_summary_email.html_part.body.to_s
expect(html).to include(direct_message.title(user))
expect(html).to include(followed_channel.title(user))
end
end
end
end