From eb80324eaafc9451fd4b2a24cbdefb3ac5c065d8 Mon Sep 17 00:00:00 2001 From: Tejaswini Chile Date: Wed, 18 Aug 2021 15:28:45 +0530 Subject: [PATCH] feat: Add message content to mention email template (#2838) --- app/drops/message_drop.rb | 12 +++++++++++ .../conversation_notifications_mailer.rb | 4 +++- app/models/application_record.rb | 2 +- .../conversation_mention.liquid | 20 ++++++++++++++----- .../conversation_notifications_mailer_spec.rb | 7 ++++++- 5 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 app/drops/message_drop.rb diff --git a/app/drops/message_drop.rb b/app/drops/message_drop.rb new file mode 100644 index 000000000..dac2eeff0 --- /dev/null +++ b/app/drops/message_drop.rb @@ -0,0 +1,12 @@ +class MessageDrop < BaseDrop + include MessageFormatHelper + + def sender_display_name + @obj.sender.try(:display_name) + end + + def text_content + content = @obj.try(:content) + transform_user_mention_content content + end +end diff --git a/app/mailers/agent_notifications/conversation_notifications_mailer.rb b/app/mailers/agent_notifications/conversation_notifications_mailer.rb index 877c68ab5..c0f1f8630 100644 --- a/app/mailers/agent_notifications/conversation_notifications_mailer.rb +++ b/app/mailers/agent_notifications/conversation_notifications_mailer.rb @@ -24,6 +24,7 @@ class AgentNotifications::ConversationNotificationsMailer < ApplicationMailer @agent = agent @conversation = message.conversation + @message = message subject = "#{@agent.available_name}, You have been mentioned in conversation [ID - #{@conversation.display_id}]" @action_url = app_account_conversation_url(account_id: @conversation.account_id, id: @conversation.display_id) send_mail_with_liquid(to: @agent.email, subject: subject) and return @@ -47,7 +48,8 @@ class AgentNotifications::ConversationNotificationsMailer < ApplicationMailer super.merge({ user: @agent, conversation: @conversation, - inbox: @conversation.inbox + inbox: @conversation.inbox, + message: @message }) end end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 69f6efc5d..37b839992 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -3,7 +3,7 @@ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true # the models that exposed in email templates through liquid - DROPPABLES = %w[Account Channel Conversation Inbox User].freeze + DROPPABLES = %w[Account Channel Conversation Inbox User Message].freeze # ModelDrop class should exist in app/drops def to_drop diff --git a/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_mention.liquid b/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_mention.liquid index 7bddf270d..9e385d5d6 100644 --- a/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_mention.liquid +++ b/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_mention.liquid @@ -1,8 +1,18 @@ -

Hi {{user.available_name}}

+ +

Hi {{user.available_name}},

-

Time to save the world. You have been mentioned in a conversation

+

You've been mentioned in a conversation. {{message.sender_display_name}} wrote:

+
+ {{message.text_content}} +
-

-Click here to get cracking. -

+

View Message

diff --git a/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb b/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb index 54dd9dae3..4263b6796 100644 --- a/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb +++ b/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb @@ -39,7 +39,8 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer, type: :maile end describe 'conversation_mention' do - let(:message) { create(:message, conversation: conversation, account: account) } + let(:another_agent) { create(:user, email: 'agent2@example.com', account: account) } + let(:message) { create(:message, conversation: conversation, account: account, sender: another_agent) } let(:mail) { described_class.with(account: account).conversation_mention(message, agent).deliver_now } it 'renders the subject' do @@ -49,6 +50,10 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer, type: :maile it 'renders the receiver email' do expect(mail.to).to eq([agent.email]) end + + it 'renders the senders name' do + expect(mail.body.encoded).to match("You've been mentioned in a conversation. #{another_agent.display_name} wrote:") + end end describe 'assigned_conversation_new_message' do