2020-12-03 04:22:51 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class REST::ChatConversationAccountSerializer < ActiveModel::Serializer
|
2020-12-16 00:31:30 +00:00
|
|
|
attributes :id, :is_hidden, :is_approved, :unread_count,
|
|
|
|
:is_unread, :chat_conversation_id, :created_at,
|
2020-12-16 07:39:07 +00:00
|
|
|
:is_muted, :chat_message_expiration_policy
|
2020-12-03 04:22:51 +00:00
|
|
|
|
|
|
|
has_many :participant_accounts, key: :other_accounts, serializer: REST::AccountSerializer
|
|
|
|
has_one :last_chat_message, serializer: REST::ChatMessageSerializer, unless: :last_chat_message_id?
|
|
|
|
|
|
|
|
def id
|
|
|
|
object.id.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def chat_conversation_id
|
|
|
|
object.chat_conversation_id.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def last_chat_message_id?
|
|
|
|
object.last_chat_message_id.nil?
|
|
|
|
end
|
|
|
|
|
2020-12-03 22:13:11 +00:00
|
|
|
def is_unread
|
|
|
|
object.unread_count > 0
|
|
|
|
end
|
|
|
|
|
2020-12-19 06:33:33 +00:00
|
|
|
def chat_message_expiration_policy
|
|
|
|
case object.chat_message_expiration_policy
|
|
|
|
when ChatConversationAccount::EXPIRATION_POLICY_MAP[:five_minutes]
|
|
|
|
return 'five_minutes'
|
|
|
|
when ChatConversationAccount::EXPIRATION_POLICY_MAP[:one_hour]
|
|
|
|
return 'one_hour'
|
|
|
|
when ChatConversationAccount::EXPIRATION_POLICY_MAP[:six_hours]
|
|
|
|
return 'six_hours'
|
|
|
|
when ChatConversationAccount::EXPIRATION_POLICY_MAP[:one_day]
|
|
|
|
return 'one_day'
|
|
|
|
when ChatConversationAccount::EXPIRATION_POLICY_MAP[:three_days]
|
|
|
|
return 'three_days'
|
|
|
|
when ChatConversationAccount::EXPIRATION_POLICY_MAP[:one_week]
|
|
|
|
return 'one_week'
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
end
|