Chatwoot/app/drops/conversation_drop.rb
Pranav Raj S 2f63ebb8a6
fix: Add fixes for sentry errors (#3522)
- Add fixes for sentry errors
2021-12-09 11:50:28 +05:30

30 lines
696 B
Ruby

class ConversationDrop < BaseDrop
include MessageFormatHelper
def display_id
@obj.try(:display_id)
end
def contact_name
@obj.try(:contact).name.capitalize || 'Customer'
end
def recent_messages
@obj.try(:recent_messages).map do |message|
{
'sender' => message_sender_name(message.sender),
'content' => render_message_content(transform_user_mention_content(message.content)),
'attachments' => message.attachments.map(&:file_url)
}
end
end
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
end