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
|
|
|
|
@obj.try(:contact).name.capitalize || 'Customer'
|
|
|
|
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-11-17 12:35:53 +00:00
|
|
|
'content' => transform_user_mention_content(message.content),
|
|
|
|
'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
|