From be91b322a43ae75c5ad011728611c72874a93a00 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Fri, 14 Aug 2020 00:47:24 +0530 Subject: [PATCH] chore: Enable additional attributes in liquid (#1144) enable additional liquid variables in mailers Co-authored-by: Pranav Raj Sreepuram --- app/drops/user_drop.rb | 3 +++ app/mailers/application_mailer.rb | 5 ++++- app/mailers/conversation_reply_mailer.rb | 17 +++++++++-------- app/views/layouts/mailer/base.liquid | 4 ++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/drops/user_drop.rb b/app/drops/user_drop.rb index e2876a58a..f10eee131 100644 --- a/app/drops/user_drop.rb +++ b/app/drops/user_drop.rb @@ -1,2 +1,5 @@ class UserDrop < BaseDrop + def available_name + @obj.try(:available_name) + end end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index c5ce00349..72954f441 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -35,7 +35,10 @@ class ApplicationMailer < ActionMailer::Base # Merge additional objects into this in your mailer # liquid template handler converts these objects into drop objects { - account: Current.account + account: Current.account, + user: @agent, + conversation: @conversation, + inbox: @conversation&.inbox } end diff --git a/app/mailers/conversation_reply_mailer.rb b/app/mailers/conversation_reply_mailer.rb index c60fb4363..5129cb1ed 100644 --- a/app/mailers/conversation_reply_mailer.rb +++ b/app/mailers/conversation_reply_mailer.rb @@ -5,10 +5,7 @@ class ConversationReplyMailer < ApplicationMailer def reply_with_summary(conversation, message_queued_time) return unless smtp_config_set_or_development? - @conversation = conversation - @account = @conversation.account - @contact = @conversation.contact - @agent = @conversation.assignee + init_conversation_attributes(conversation) recap_messages = @conversation.messages.chat.where('created_at < ?', message_queued_time).last(10) 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) return unless smtp_config_set_or_development? - @conversation = conversation - @account = @conversation.account - @contact = @conversation.contact - @agent = @conversation.assignee + init_conversation_attributes(conversation) @messages = @conversation.messages.chat.outgoing.where('created_at >= ?', message_queued_time) return false if @messages.count.zero? @@ -49,6 +43,13 @@ class ConversationReplyMailer < ApplicationMailer private + def init_conversation_attributes(conversation) + @conversation = conversation + @account = @conversation.account + @contact = @conversation.contact + @agent = @conversation.assignee + end + def assignee_name @assignee_name ||= @agent&.available_name || 'Notifications' end diff --git a/app/views/layouts/mailer/base.liquid b/app/views/layouts/mailer/base.liquid index 6eea14f4e..e836cdbb6 100644 --- a/app/views/layouts/mailer/base.liquid +++ b/app/views/layouts/mailer/base.liquid @@ -89,7 +89,7 @@