Files
leadchat/app/presenters/conversations/event_data_presenter.rb
Shivam Mishra 6196a6d99a fix: last_activity_at is nil when conv is created (#9934)
The payload does not include last_activity_at when the conversation is created. Because of this the frontend is not able to sort the conversations when appending this. Another problem is that the last_activity_at is not always present, it is added only when a message is created, and it updates it. So this can be nil when the conversation is created, so we fallback to created_at only at the presentation layer
2024-08-12 15:08:06 +05:30

50 lines
1.3 KiB
Ruby

class Conversations::EventDataPresenter < SimpleDelegator
def push_data
{
additional_attributes: additional_attributes,
can_reply: can_reply?,
channel: inbox.try(:channel_type),
contact_inbox: contact_inbox,
id: display_id,
inbox_id: inbox_id,
messages: push_messages,
labels: label_list,
meta: push_meta,
status: status,
custom_attributes: custom_attributes,
snoozed_until: snoozed_until,
unread_count: unread_incoming_messages.count,
first_reply_created_at: first_reply_created_at,
priority: priority,
waiting_since: waiting_since.to_i,
**push_timestamps
}
end
private
def push_messages
[messages.chat.last&.push_event_data].compact
end
def push_meta
{
sender: contact.push_event_data,
assignee: assignee&.push_event_data,
team: team&.push_event_data,
hmac_verified: contact_inbox&.hmac_verified
}
end
def push_timestamps
{
agent_last_seen_at: agent_last_seen_at.to_i,
contact_last_seen_at: contact_last_seen_at.to_i,
last_activity_at: last_activity_at.to_i,
timestamp: last_activity_at.to_i,
created_at: created_at.to_i
}
end
end
Conversations::EventDataPresenter.prepend_mod_with('Conversations::EventDataPresenter')