Feat: Include previous messages in mention/assign notifications email (#3385)

This commit is contained in:
Shivam Chahar 2021-11-17 18:05:53 +05:30 committed by GitHub
parent 9ea42ebff2
commit fec4a29081
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 0 deletions

View file

@ -1,5 +1,17 @@
class ConversationDrop < BaseDrop class ConversationDrop < BaseDrop
include MessageFormatHelper
def display_id def display_id
@obj.try(:display_id) @obj.try(:display_id)
end end
def recent_messages
@obj.try(:recent_messages).map do |message|
{
'sender' => message.sender&.available_name || message.sender&.name,
'content' => transform_user_mention_content(message.content),
'attachments' => message.attachments.map(&:file_url)
}
end
end
end end

View file

@ -147,6 +147,10 @@ class Conversation < ApplicationRecord
inbox.inbox_type == 'Twitter' && additional_attributes['type'] == 'tweet' inbox.inbox_type == 'Twitter' && additional_attributes['type'] == 'tweet'
end end
def recent_messages
messages.chat.last(5)
end
private private
def execute_after_update_commit_callbacks def execute_after_update_commit_callbacks

View file

@ -2,6 +2,30 @@
<p>Time to save the world. A new conversation has been assigned to you</p> <p>Time to save the world. A new conversation has been assigned to you</p>
{% for chat_message in conversation.recent_messages %}
<div>
{% if chat_message.sender == user.available_name %}
<h4 style="margin: 0;">You</h4>
{% else %}
<h4 style="margin: 0;">{{chat_message.sender}}</h4>
{% endif %}
</div>
<div>
<p style="padding: 10px 20px; margin: 5px 0 20px 0; background: #F2F3F7; border-radius: 10px; display: inline-block; font-family: "Helvetica Neue",Tahoma,Arial,sans-serif; text-align: start; unicode-bidi: plaintext;">
{% if chat_message.content %}
{{chat_message.content}}
{% endif %}
{% if chat_message.attachments %}
{% for attachment in chat_message.attachments %}
Attachment [<a href="{{ attachment }}" _target="blank">Click here to view</a>]
{% endfor %}
{% endif %}
</p>
</div>
{% endfor %}
<p> <p>
Click <a href="{{action_url}}">here</a> to get cracking. Click <a href="{{action_url}}">here</a> to get cracking.
</p> </p>

View file

@ -5,4 +5,28 @@
{{message.text_content}} {{message.text_content}}
</blockquote> </blockquote>
{% for chat_message in conversation.recent_messages %}
<div>
{% if chat_message.sender == user.available_name %}
<h4 style="margin: 0;">You</h4>
{% else %}
<h4 style="margin: 0;">{{chat_message.sender}}</h4>
{% endif %}
</div>
<div>
<p style="padding: 10px 20px; margin: 5px 0 20px 0; background: #F2F3F7; border-radius: 10px; display: inline-block; font-family: "Helvetica Neue",Tahoma,Arial,sans-serif; text-align: start; unicode-bidi: plaintext;">
{% if chat_message.content %}
{{chat_message.content}}
{% endif %}
{% if chat_message.attachments %}
{% for attachment in chat_message.attachments %}
Attachment [<a href="{{ attachment }}" _target="blank">Click here to view</a>]
{% endfor %}
{% endif %}
</p>
</div>
{% endfor %}
<p><a href="{{ action_url }}">View Message</a></p> <p><a href="{{ action_url }}">View Message</a></p>

View file

@ -340,6 +340,30 @@ RSpec.describe Conversation, type: :model do
end end
end end
describe 'recent_messages' do
subject(:recent_messages) { conversation.recent_messages }
let(:conversation) { create(:conversation, agent_last_seen_at: 1.hour.ago) }
let(:message_params) do
{
conversation: conversation,
account: conversation.account,
inbox: conversation.inbox,
sender: conversation.assignee
}
end
let!(:messages) do
create_list(:message, 10, **message_params) do |message, i|
message.created_at = i.minute.ago
end
end
it 'returns upto 5 recent messages' do
expect(recent_messages.length).to be < 6
expect(recent_messages).to eq messages.last(5)
end
end
describe 'unread_incoming_messages' do describe 'unread_incoming_messages' do
subject(:unread_incoming_messages) { conversation.unread_incoming_messages } subject(:unread_incoming_messages) { conversation.unread_incoming_messages }