chore: Enable additional attributes in liquid (#1144)

enable additional liquid variables in mailers

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose 2020-08-14 00:47:24 +05:30 committed by GitHub
parent 0117997fb1
commit be91b322a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 11 deletions

View file

@ -1,2 +1,5 @@
class UserDrop < BaseDrop class UserDrop < BaseDrop
def available_name
@obj.try(:available_name)
end
end end

View file

@ -35,7 +35,10 @@ class ApplicationMailer < ActionMailer::Base
# Merge additional objects into this in your mailer # Merge additional objects into this in your mailer
# liquid template handler converts these objects into drop objects # liquid template handler converts these objects into drop objects
{ {
account: Current.account account: Current.account,
user: @agent,
conversation: @conversation,
inbox: @conversation&.inbox
} }
end end

View file

@ -5,10 +5,7 @@ class ConversationReplyMailer < ApplicationMailer
def reply_with_summary(conversation, message_queued_time) def reply_with_summary(conversation, message_queued_time)
return unless smtp_config_set_or_development? return unless smtp_config_set_or_development?
@conversation = conversation init_conversation_attributes(conversation)
@account = @conversation.account
@contact = @conversation.contact
@agent = @conversation.assignee
recap_messages = @conversation.messages.chat.where('created_at < ?', message_queued_time).last(10) recap_messages = @conversation.messages.chat.where('created_at < ?', message_queued_time).last(10)
new_messages = @conversation.messages.chat.where('created_at >= ?', message_queued_time) new_messages = @conversation.messages.chat.where('created_at >= ?', message_queued_time)
@ -29,10 +26,7 @@ class ConversationReplyMailer < ApplicationMailer
def reply_without_summary(conversation, message_queued_time) def reply_without_summary(conversation, message_queued_time)
return unless smtp_config_set_or_development? return unless smtp_config_set_or_development?
@conversation = conversation init_conversation_attributes(conversation)
@account = @conversation.account
@contact = @conversation.contact
@agent = @conversation.assignee
@messages = @conversation.messages.chat.outgoing.where('created_at >= ?', message_queued_time) @messages = @conversation.messages.chat.outgoing.where('created_at >= ?', message_queued_time)
return false if @messages.count.zero? return false if @messages.count.zero?
@ -49,6 +43,13 @@ class ConversationReplyMailer < ApplicationMailer
private private
def init_conversation_attributes(conversation)
@conversation = conversation
@account = @conversation.account
@contact = @conversation.contact
@agent = @conversation.assignee
end
def assignee_name def assignee_name
@assignee_name ||= @agent&.available_name || 'Notifications' @assignee_name ||= @agent&.available_name || 'Notifications'
end end

View file

@ -89,7 +89,7 @@
<div class="footer" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; clear: both; color: #999; margin: 0; padding: 20px;"> <div class="footer" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; clear: both; color: #999; margin: 0; padding: 20px;">
<table width="100%" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> <table width="100%" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
{% if global_config['BRAND_NAME'] %} {% if global_config['BRAND_NAME'] != '' %}
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top"> <td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
Powered by Powered by