diff --git a/app/mailers/conversation_reply_mailer.rb b/app/mailers/conversation_reply_mailer.rb index 4b41d81db..0b0b75669 100644 --- a/app/mailers/conversation_reply_mailer.rb +++ b/app/mailers/conversation_reply_mailer.rb @@ -9,8 +9,8 @@ class ConversationReplyMailer < ApplicationMailer @contact = @conversation.contact @agent = @conversation.assignee - recap_messages = @conversation.messages.where('created_at < ?', message_queued_time).order(created_at: :asc).last(10) - new_messages = @conversation.messages.where('created_at >= ?', message_queued_time) + recap_messages = @conversation.messages.chat.where('created_at < ?', message_queued_time).last(10) + new_messages = @conversation.messages.chat.where('created_at >= ?', message_queued_time) @messages = recap_messages + new_messages @messages = @messages.select(&:reportable?) diff --git a/app/models/message.rb b/app/models/message.rb index 99572a751..47ea8c425 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -59,7 +59,7 @@ class Message < ApplicationRecord # .succ is a hack to avoid https://makandracards.com/makandra/1057-why-two-ruby-time-objects-are-not-equal-although-they-appear-to-be scope :unread_since, ->(datetime) { where('EXTRACT(EPOCH FROM created_at) > (?)', datetime.to_i.succ) } - scope :chat, -> { where.not(message_type: :activity).where.not(private: true) } + scope :chat, -> { where.not(message_type: :activity).where(private: false) } default_scope { order(created_at: :asc) } belongs_to :account diff --git a/spec/mailers/conversation_reply_mailer_spec.rb b/spec/mailers/conversation_reply_mailer_spec.rb index f6d61a577..cb49dbe22 100644 --- a/spec/mailers/conversation_reply_mailer_spec.rb +++ b/spec/mailers/conversation_reply_mailer_spec.rb @@ -12,15 +12,31 @@ RSpec.describe ConversationReplyMailer, type: :mailer do allow(class_instance).to receive(:smtp_config_set_or_development?).and_return(true) end - context 'when custom domain and email is not enabled' do + context 'with all mails' do let(:conversation) { create(:conversation, assignee: agent) } let(:message) { create(:message, conversation: conversation) } + let(:private_message) { create(:message, content: 'This is a private message', conversation: conversation) } let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now } it 'renders the subject' do expect(mail.subject).to eq("[##{message.conversation.display_id}] #{message.content.truncate(30)}") end + it 'not have private notes' do + # make the message private + private_message.private = true + private_message.save + + expect(mail.body.decoded).not_to include(private_message.content) + expect(mail.body.decoded).to include(message.content) + end + end + + context 'when custom domain and email is not enabled' do + let(:conversation) { create(:conversation, assignee: agent) } + let(:message) { create(:message, conversation: conversation) } + let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now } + it 'renders the receiver email' do expect(mail.to).to eq([message&.conversation&.contact&.email]) end