feat: Add message content to mention email template (#2838)

This commit is contained in:
Tejaswini Chile 2021-08-18 15:28:45 +05:30 committed by GitHub
parent 20b96c7c60
commit eb80324eaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 8 deletions

12
app/drops/message_drop.rb Normal file
View file

@ -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

View file

@ -24,6 +24,7 @@ class AgentNotifications::ConversationNotificationsMailer < ApplicationMailer
@agent = agent @agent = agent
@conversation = message.conversation @conversation = message.conversation
@message = message
subject = "#{@agent.available_name}, You have been mentioned in conversation [ID - #{@conversation.display_id}]" 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) @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 send_mail_with_liquid(to: @agent.email, subject: subject) and return
@ -47,7 +48,8 @@ class AgentNotifications::ConversationNotificationsMailer < ApplicationMailer
super.merge({ super.merge({
user: @agent, user: @agent,
conversation: @conversation, conversation: @conversation,
inbox: @conversation.inbox inbox: @conversation.inbox,
message: @message
}) })
end end
end end

View file

@ -3,7 +3,7 @@ class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true self.abstract_class = true
# the models that exposed in email templates through liquid # 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 # ModelDrop class should exist in app/drops
def to_drop def to_drop

View file

@ -1,8 +1,18 @@
<p>Hi {{user.available_name}}</p> <style type="text/css">
.quoted-text--content {
box-sizing:border-box;
padding:8px 16px;
margin:0 0 20px;
font-size:14px;
border-left:5px solid #eeeeee
}
</style>
<p>Hi {{user.available_name}}, </p>
<p>Time to save the world. You have been mentioned in a conversation</p> <p>You've been mentioned in a conversation. <b>{{message.sender_display_name}}</b> wrote:</p>
<blockquote class='quoted-text--content'>
{{message.text_content}}
</blockquote>
<p> <p><a href="{{ action_url }}">View Message</a></p>
Click <a href="{{ action_url }}">here</a> to get cracking.
</p>

View file

@ -39,7 +39,8 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer, type: :maile
end end
describe 'conversation_mention' do 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 } let(:mail) { described_class.with(account: account).conversation_mention(message, agent).deliver_now }
it 'renders the subject' do it 'renders the subject' do
@ -49,6 +50,10 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer, type: :maile
it 'renders the receiver email' do it 'renders the receiver email' do
expect(mail.to).to eq([agent.email]) expect(mail.to).to eq([agent.email])
end end
it 'renders the senders name' do
expect(mail.body.encoded).to match("You've been mentioned in a conversation. <b>#{another_agent.display_name}</b> wrote:")
end
end end
describe 'assigned_conversation_new_message' do describe 'assigned_conversation_new_message' do