2020-12-03 04:22:51 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: chat_conversation_accounts
|
|
|
|
#
|
2020-12-03 22:13:11 +00:00
|
|
|
# id :bigint(8) not null, primary key
|
|
|
|
# account_id :bigint(8)
|
|
|
|
# chat_conversation_id :bigint(8)
|
|
|
|
# participant_account_ids :bigint(8) default([]), not null, is an Array
|
|
|
|
# last_chat_message_id :bigint(8)
|
|
|
|
# is_hidden :boolean default(FALSE), not null
|
|
|
|
# is_approved :boolean default(FALSE), not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2021-01-05 16:35:23 +00:00
|
|
|
# unread_count :bigint(8) default(0), not null
|
2020-12-03 22:13:11 +00:00
|
|
|
# chat_message_expiration_policy :string
|
2020-12-16 07:39:07 +00:00
|
|
|
# is_muted :boolean default(FALSE), not null
|
2020-12-03 04:22:51 +00:00
|
|
|
#
|
|
|
|
|
2020-12-16 00:31:30 +00:00
|
|
|
# : todo : max per account
|
2020-12-03 04:22:51 +00:00
|
|
|
class ChatConversationAccount < ApplicationRecord
|
|
|
|
include Paginable
|
2020-12-16 00:31:30 +00:00
|
|
|
|
|
|
|
EXPIRATION_POLICY_MAP = {
|
|
|
|
none: nil,
|
|
|
|
five_minutes: '1',
|
2020-12-19 06:33:33 +00:00
|
|
|
one_hour: '2',
|
2020-12-16 00:31:30 +00:00
|
|
|
six_hours: '3',
|
|
|
|
one_day: '4',
|
|
|
|
three_days: '5',
|
|
|
|
one_week: '6',
|
|
|
|
}.freeze
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
belongs_to :account
|
|
|
|
belongs_to :chat_conversation
|
|
|
|
belongs_to :last_chat_message, class_name: 'ChatMessage', optional: true
|
|
|
|
|
2020-12-22 19:19:38 +00:00
|
|
|
default_scope { recent }
|
|
|
|
|
|
|
|
scope :recent, -> { reorder(updated_at: :desc) }
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
def participant_accounts
|
|
|
|
if participant_account_ids.empty?
|
|
|
|
[account]
|
|
|
|
else
|
|
|
|
participants = Account.where(id: participant_account_ids)
|
|
|
|
participants.empty? ? [account] : participants
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-20 17:27:24 +00:00
|
|
|
private
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
end
|