DEV: Make summary subject logic more explicit (#19167)

This commit is contained in:
Roman Rizzi 2022-11-23 14:29:41 -03:00 committed by GitHub
parent 1dadf4381f
commit 023333a8e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View File

@ -178,7 +178,7 @@ en:
chat_channel:
one: "[%{email_prefix}] New message in %{message_title}"
other: "[%{email_prefix}] New messages in %{message_title} and %{others}"
other_direct_message: "from %{message_title}"
other_direct_message: "from %{dm_title}"
others: "%{count} others"
unsubscribe: "This chat summary is sent from %{site_link} when you are away. Change your %{email_preferences_link}, or %{unsubscribe_link} to unsubscribe."
unsubscribe_no_link: "This chat summary is sent from %{site_link} when you are away. Change your %{email_preferences_link}."

View File

@ -66,6 +66,8 @@ module Chat::UserNotificationsExtension
dm_users = grouped_channels.last.flat_map { |c| grouped_messages[c].map(&:user) }.uniq
total_count_for_subject = non_dm_channels.size + dm_users.size
# Prioritize messages from regular channels.
first_message_from = non_dm_channels.pop
if first_message_from
first_message_title = first_message_from.title(user)
@ -107,6 +109,7 @@ module Chat::UserNotificationsExtension
return if total_count <= 1
return I18n.t(with_subject_prefix("others"), count: total_count - 1) if total_count > 2
# The summary contains exactly two messages.
if other_non_dm_channels.empty?
second_message_from = other_dm_users.first
second_message_title = second_message_from.username
@ -115,8 +118,9 @@ module Chat::UserNotificationsExtension
second_message_title = second_message_from.title(user)
end
return second_message_title if first_message_from.class == second_message_from.class
second_message_is_from_channel = first_message_from.class == second_message_from.class
return second_message_title if second_message_is_from_channel
I18n.t(with_subject_prefix("other_direct_message"), message_title: second_message_title)
I18n.t(with_subject_prefix("other_direct_message"), dm_title: second_message_title)
end
end

View File

@ -223,7 +223,7 @@ describe UserNotifications do
expected_other_text =
I18n.t(
"user_notifications.chat_summary.subject.other_direct_message",
message_title: sender.username,
dm_title: sender.username,
)
email = described_class.chat_summary(user, {})