A platform for community discussion. Free, open, simple.
FIX: Deliver chat summaries when allowed groups include "everyone" (#18955)
Roman Rizzi698c3ced1539
diff --git a/plugins/chat/lib/chat_mailer.rb b/plugins/chat/lib/chat_mailer.rbindex 4cfdde2e346..8c914b497d8 100644--- a/plugins/chat/lib/chat_mailer.rb+++ b/plugins/chat/lib/chat_mailer.rb@@ -32,13 +32,17 @@ class Chat::ChatMailerwhen_away_frequency = UserOption.chat_email_frequencies[:when_away]allowed_group_ids = Chat.allowed_group_ids- User- .select("users.id", "ARRAY_AGG(ARRAY[uccm.id, c_msg.id]) AS memberships_with_unread_messages")+ users = User.joins(:user_option).where(user_options: { chat_enabled: true, chat_email_frequency: when_away_frequency }).where("users.last_seen_at < ?", 15.minutes.ago)- .joins(:groups)- .where(groups: { id: allowed_group_ids })++ if !allowed_group_ids.include?(Group::AUTO_GROUPS[:everyone])+ users = users.joins(:groups).where(groups: { id: allowed_group_ids })+ end++ users+ .select("users.id", "ARRAY_AGG(ARRAY[uccm.id, c_msg.id]) AS memberships_with_unread_messages").joins("INNER JOIN user_chat_channel_memberships uccm ON uccm.user_id = users.id").joins("INNER JOIN chat_channels cc ON cc.id = uccm.chat_channel_id").joins("INNER JOIN chat_messages c_msg ON c_msg.chat_channel_id = uccm.chat_channel_id")diff --git a/plugins/chat/spec/components/chat_mailer_spec.rb b/plugins/chat/spec/components/chat_mailer_spec.rbindex 3b74d34ddfb..20229526a89 100644--- a/plugins/chat/spec/components/chat_mailer_spec.rb+++ b/plugins/chat/spec/components/chat_mailer_spec.rb@@ -197,6 +197,14 @@ describe Chat::ChatMailer doassert_summary_skippedend+ it "queues a job when the chat_allowed_groups is set to everyone" do+ SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:everyone]++ described_class.send_unread_mentions_summary++ assert_only_queued_once+ end+describe "update the user membership after we send the email" dobefore { Jobs.run_immediately! }