feat: Display sent status of emails in email channel (#3125)
This commit is contained in:
@@ -2,14 +2,14 @@ class ConversationReplyMailer < ApplicationMailer
|
||||
default from: ENV.fetch('MAILER_SENDER_EMAIL', 'Chatwoot <accounts@chatwoot.com>')
|
||||
layout :choose_layout
|
||||
|
||||
def reply_with_summary(conversation, message_queued_time)
|
||||
def reply_with_summary(conversation, last_queued_id)
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
init_conversation_attributes(conversation)
|
||||
return if conversation_already_viewed?
|
||||
|
||||
recap_messages = @conversation.messages.chat.where('created_at < ?', message_queued_time).last(10)
|
||||
new_messages = @conversation.messages.chat.where('created_at >= ?', message_queued_time)
|
||||
recap_messages = @conversation.messages.chat.where('id < ?', last_queued_id).last(10)
|
||||
new_messages = @conversation.messages.chat.where('id >= ?', last_queued_id)
|
||||
@messages = recap_messages + new_messages
|
||||
@messages = @messages.select(&:email_reply_summarizable?)
|
||||
|
||||
@@ -25,13 +25,13 @@ class ConversationReplyMailer < ApplicationMailer
|
||||
})
|
||||
end
|
||||
|
||||
def reply_without_summary(conversation, message_queued_time)
|
||||
def reply_without_summary(conversation, last_queued_id)
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
init_conversation_attributes(conversation)
|
||||
return if conversation_already_viewed?
|
||||
|
||||
@messages = @conversation.messages.chat.where(message_type: [:outgoing, :template]).where('created_at >= ?', message_queued_time)
|
||||
@messages = @conversation.messages.chat.where(message_type: [:outgoing, :template]).where('id >= ?', last_queued_id)
|
||||
@messages = @messages.reject { |m| m.template? && !m.input_csat? }
|
||||
return false if @messages.count.zero?
|
||||
|
||||
@@ -41,12 +41,30 @@ class ConversationReplyMailer < ApplicationMailer
|
||||
reply_to: reply_email,
|
||||
subject: mail_subject,
|
||||
message_id: custom_message_id,
|
||||
in_reply_to: in_reply_to_email,
|
||||
cc: cc_bcc_emails[0],
|
||||
bcc: cc_bcc_emails[1]
|
||||
in_reply_to: in_reply_to_email
|
||||
})
|
||||
end
|
||||
|
||||
def email_reply(message)
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
init_conversation_attributes(message.conversation)
|
||||
@message = message
|
||||
|
||||
reply_mail_object = mail({
|
||||
to: @contact&.email,
|
||||
from: from_email_with_name,
|
||||
reply_to: reply_email,
|
||||
subject: mail_subject,
|
||||
message_id: custom_message_id,
|
||||
in_reply_to: in_reply_to_email,
|
||||
cc: cc_bcc_emails[0],
|
||||
bcc: cc_bcc_emails[1]
|
||||
})
|
||||
|
||||
message.update(source_id: reply_mail_object.message_id)
|
||||
end
|
||||
|
||||
def conversation_transcript(conversation, to_email)
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
@@ -104,7 +122,7 @@ class ConversationReplyMailer < ApplicationMailer
|
||||
|
||||
def reply_email
|
||||
if should_use_conversation_email_address?
|
||||
"#{assignee_name} <reply+#{@conversation.uuid}@#{@account.inbound_email_domain}>"
|
||||
"#{assignee_name} from #{@inbox.name} <reply+#{@conversation.uuid}@#{@account.inbound_email_domain}>"
|
||||
else
|
||||
@inbox.email_address || @agent&.email
|
||||
end
|
||||
@@ -129,7 +147,9 @@ class ConversationReplyMailer < ApplicationMailer
|
||||
end
|
||||
|
||||
def custom_message_id
|
||||
"<conversation/#{@conversation.uuid}/messages/#{@messages&.last&.id}@#{@account.inbound_email_domain}>"
|
||||
last_message = @message || @messages&.last
|
||||
|
||||
"<conversation/#{@conversation.uuid}/messages/#{last_message&.id}@#{@account.inbound_email_domain}>"
|
||||
end
|
||||
|
||||
def in_reply_to_email
|
||||
@@ -161,7 +181,7 @@ class ConversationReplyMailer < ApplicationMailer
|
||||
end
|
||||
|
||||
def choose_layout
|
||||
return false if action_name == 'reply_without_summary'
|
||||
return false if action_name == 'reply_without_summary' || action_name == 'email_reply'
|
||||
|
||||
'mailer/base'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user