diff --git a/plugins/chat/config/locales/server.en.yml b/plugins/chat/config/locales/server.en.yml index 90bce726dc8..66971e7d5a3 100644 --- a/plugins/chat/config/locales/server.en.yml +++ b/plugins/chat/config/locales/server.en.yml @@ -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}." diff --git a/plugins/chat/lib/extensions/user_notifications_extension.rb b/plugins/chat/lib/extensions/user_notifications_extension.rb index 6dd71b609cd..e86d88f7d90 100644 --- a/plugins/chat/lib/extensions/user_notifications_extension.rb +++ b/plugins/chat/lib/extensions/user_notifications_extension.rb @@ -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 diff --git a/plugins/chat/spec/mailers/user_notifications_spec.rb b/plugins/chat/spec/mailers/user_notifications_spec.rb index d872efdab55..11d35065d52 100644 --- a/plugins/chat/spec/mailers/user_notifications_spec.rb +++ b/plugins/chat/spec/mailers/user_notifications_spec.rb @@ -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, {})