diff --git a/app/mailers/conversation_reply_mailer.rb b/app/mailers/conversation_reply_mailer.rb index ccea7184a..eed4a4c43 100644 --- a/app/mailers/conversation_reply_mailer.rb +++ b/app/mailers/conversation_reply_mailer.rb @@ -34,7 +34,8 @@ class ConversationReplyMailer < ApplicationMailer @contact = @conversation.contact @agent = @conversation.assignee - @messages = @conversation.messages.outgoing.where('created_at >= ?', message_queued_time) + @messages = @conversation.messages.chat.outgoing.where('created_at >= ?', message_queued_time) + return false if @messages.count.zero? mail({ to: @contact&.email, diff --git a/app/models/concerns/featurable.rb b/app/models/concerns/featurable.rb index 7c8a44264..5112d170e 100644 --- a/app/models/concerns/featurable.rb +++ b/app/models/concerns/featurable.rb @@ -55,6 +55,6 @@ module Featurable return true if config.blank? features_to_enabled = config.value.select { |f| f[:enabled] }.map { |f| f[:name] } - enable_features(features_to_enabled) + enable_features(*features_to_enabled) end end diff --git a/app/models/message.rb b/app/models/message.rb index e5f148f4b..f1388b59d 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -146,7 +146,7 @@ class Message < ApplicationRecord end def notify_via_mail - if Redis::Alfred.get(conversation_mail_key).nil? && conversation.contact.email? && outgoing? + if Redis::Alfred.get(conversation_mail_key).nil? && conversation.contact.email? && outgoing? && !private # set a redis key for the conversation so that we don't need to send email for every # new message that comes in and we dont enque the delayed sidekiq job for every message Redis::Alfred.setex(conversation_mail_key, Time.zone.now) diff --git a/spec/mailers/conversation_reply_mailer_spec.rb b/spec/mailers/conversation_reply_mailer_spec.rb index dbe254258..915232231 100644 --- a/spec/mailers/conversation_reply_mailer_spec.rb +++ b/spec/mailers/conversation_reply_mailer_spec.rb @@ -34,10 +34,16 @@ RSpec.describe ConversationReplyMailer, type: :mailer do end context 'without summary' do - let(:conversation) { create(:conversation, assignee: agent) } - let(:message_1) { create(:message, conversation: conversation) } - let(:message_2) { build(:message, conversation: conversation, message_type: 'outgoing', content: 'Outgoing Message') } - let(:private_message) { create(:message, content: 'This is a private message', conversation: conversation) } + let(:conversation) { create(:conversation, assignee: agent, account: account).reload } + let(:message_1) { create(:message, conversation: conversation, account: account, content: 'Outgoing Message 1').reload } + let(:message_2) { build(:message, conversation: conversation, account: account, message_type: 'outgoing', content: 'Outgoing Message 2') } + let(:private_message) do + create(:message, + content: 'This is a private message', + conversation: conversation, + account: account, + message_type: 'outgoing').reload + end let(:mail) { described_class.reply_without_summary(message_1.conversation, Time.zone.now - 1.minute).deliver_now } before do @@ -52,7 +58,6 @@ RSpec.describe ConversationReplyMailer, type: :mailer do # make the message private private_message.private = true private_message.save - expect(mail.body.decoded).not_to include(private_message.content) end