mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 19:17:48 +00:00 
			
		
		
		
	Feat: Include previous messages in mention/assign notifications email (#3385)
This commit is contained in:
		| @@ -1,5 +1,17 @@ | ||||
| class ConversationDrop < BaseDrop | ||||
|   include MessageFormatHelper | ||||
|  | ||||
|   def display_id | ||||
|     @obj.try(:display_id) | ||||
|   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 | ||||
|   | ||||
| @@ -147,6 +147,10 @@ class Conversation < ApplicationRecord | ||||
|     inbox.inbox_type == 'Twitter' && additional_attributes['type'] == 'tweet' | ||||
|   end | ||||
|  | ||||
|   def recent_messages | ||||
|     messages.chat.last(5) | ||||
|   end | ||||
|  | ||||
|   private | ||||
|  | ||||
|   def execute_after_update_commit_callbacks | ||||
|   | ||||
| @@ -2,6 +2,30 @@ | ||||
|  | ||||
| <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> | ||||
| Click <a href="{{action_url}}">here</a> to get cracking. | ||||
| </p> | ||||
|   | ||||
| @@ -5,4 +5,28 @@ | ||||
|   {{message.text_content}} | ||||
| </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> | ||||
|   | ||||
| @@ -340,6 +340,30 @@ RSpec.describe Conversation, type: :model do | ||||
|     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 | ||||
|     subject(:unread_incoming_messages) { conversation.unread_incoming_messages } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Shivam Chahar
					Shivam Chahar