2020-08-06 09:51:06 +00:00
|
|
|
class ConversationDrop < BaseDrop
|
2021-11-17 12:35:53 +00:00
|
|
|
include MessageFormatHelper
|
|
|
|
|
2020-08-06 09:51:06 +00:00
|
|
|
def display_id
|
|
|
|
@obj.try(:display_id)
|
|
|
|
end
|
2021-11-17 12:35:53 +00:00
|
|
|
|
2021-11-27 10:08:27 +00:00
|
|
|
def contact_name
|
2022-07-22 10:07:24 +00:00
|
|
|
@obj.try(:contact).name.try(:capitalize) || 'Customer'
|
2021-11-27 10:08:27 +00:00
|
|
|
end
|
|
|
|
|
2021-11-17 12:35:53 +00:00
|
|
|
def recent_messages
|
|
|
|
@obj.try(:recent_messages).map do |message|
|
|
|
|
{
|
2021-11-27 10:08:27 +00:00
|
|
|
'sender' => message_sender_name(message.sender),
|
2021-12-09 06:20:28 +00:00
|
|
|
'content' => render_message_content(transform_user_mention_content(message.content)),
|
2021-11-17 12:35:53 +00:00
|
|
|
'attachments' => message.attachments.map(&:file_url)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2021-11-27 10:08:27 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def message_sender_name(sender)
|
|
|
|
return 'Bot' if sender.blank?
|
|
|
|
return contact_name if sender.instance_of?(Contact)
|
|
|
|
|
|
|
|
sender&.available_name || sender&.name
|
|
|
|
end
|
2020-08-06 09:51:06 +00:00
|
|
|
end
|