2020-03-05 20:17:37 +00:00
|
|
|
json.meta do
|
|
|
|
json.sender do
|
2022-10-06 00:24:34 +00:00
|
|
|
json.partial! 'api/v1/models/contact', formats: [:json], resource: conversation.contact
|
2020-03-05 20:17:37 +00:00
|
|
|
end
|
2020-07-04 14:16:17 +00:00
|
|
|
json.channel conversation.inbox.try(:channel_type)
|
2020-12-08 17:19:47 +00:00
|
|
|
if conversation.assignee&.account
|
2020-07-27 16:49:26 +00:00
|
|
|
json.assignee do
|
2022-10-06 00:24:34 +00:00
|
|
|
json.partial! 'api/v1/models/agent', formats: [:json], resource: conversation.assignee
|
2020-07-27 16:49:26 +00:00
|
|
|
end
|
|
|
|
end
|
2021-03-15 13:07:03 +00:00
|
|
|
if conversation.team.present?
|
|
|
|
json.team do
|
2022-10-06 00:24:34 +00:00
|
|
|
json.partial! 'api/v1/models/team', formats: [:json], resource: conversation.team
|
2021-03-15 13:07:03 +00:00
|
|
|
end
|
|
|
|
end
|
2021-11-22 18:02:17 +00:00
|
|
|
json.hmac_verified conversation.contact_inbox&.hmac_verified
|
2020-03-05 20:17:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
json.id conversation.display_id
|
2021-01-31 07:35:07 +00:00
|
|
|
if conversation.messages.count.zero?
|
|
|
|
json.messages []
|
|
|
|
elsif conversation.unread_incoming_messages.count.zero?
|
2020-09-19 07:16:34 +00:00
|
|
|
json.messages [conversation.messages.includes([{ attachments: [{ file_attachment: [:blob] }] }]).last.try(:push_event_data)]
|
2020-03-05 20:17:37 +00:00
|
|
|
else
|
2020-12-10 18:00:38 +00:00
|
|
|
json.messages conversation.unread_messages.includes([:user, { attachments: [{ file_attachment: [:blob] }] }]).last(10).map(&:push_event_data)
|
2020-03-05 20:17:37 +00:00
|
|
|
end
|
|
|
|
|
2021-09-29 14:03:51 +00:00
|
|
|
json.account_id conversation.account_id
|
|
|
|
json.additional_attributes conversation.additional_attributes
|
2020-03-05 20:17:37 +00:00
|
|
|
json.agent_last_seen_at conversation.agent_last_seen_at.to_i
|
2021-09-23 15:29:10 +00:00
|
|
|
json.assignee_last_seen_at conversation.assignee_last_seen_at.to_i
|
2021-09-29 14:03:51 +00:00
|
|
|
json.can_reply conversation.can_reply?
|
|
|
|
json.contact_last_seen_at conversation.contact_last_seen_at.to_i
|
2021-09-22 05:16:48 +00:00
|
|
|
json.custom_attributes conversation.custom_attributes
|
2021-09-29 14:03:51 +00:00
|
|
|
json.inbox_id conversation.inbox_id
|
2020-06-25 15:34:03 +00:00
|
|
|
json.labels conversation.label_list
|
2021-09-29 14:03:51 +00:00
|
|
|
json.muted conversation.muted?
|
|
|
|
json.snoozed_until conversation.snoozed_until
|
|
|
|
json.status conversation.status
|
|
|
|
json.timestamp conversation.last_activity_at.to_i
|
2022-11-29 16:18:00 +00:00
|
|
|
json.first_reply_created_at conversation.first_reply_created_at.to_i
|
2021-09-29 14:03:51 +00:00
|
|
|
json.unread_count conversation.unread_incoming_messages.count
|
2022-11-16 23:43:55 +00:00
|
|
|
json.last_non_activity_message conversation.messages.non_activity_messages.first.try(:push_event_data)
|