feat: update jbuilder and query

UNSTABLE
This commit is contained in:
Shivam Mishra
2023-06-02 18:56:44 +05:30
parent f63a301b17
commit c5360ec0a6
3 changed files with 53 additions and 17 deletions
+36
View File
@@ -36,13 +36,49 @@
# index_conversation_with_labels_on_last_activity_at (last_activity_at)
#
class ConversationWithLabel < ApplicationRecord
self.primary_key = :id
belongs_to :account
belongs_to :inbox
belongs_to :assignee, class_name: 'User', optional: true
belongs_to :contact
belongs_to :contact_inbox
belongs_to :team, optional: true
belongs_to :campaign, optional: true
has_many :mentions
has_many :messages
has_one :csat_survey_response
has_many :conversation_participants
has_many :notifications, as: :primary_actor
has_many :attachments, through: :messages
scope :assigned_to, ->(agent) { where(assignee_id: agent.id) }
scope :unassigned, -> { where(assignee_id: nil) }
scope :assigned, -> { where.not(assignee_id: nil) }
scope :latest, -> { order(last_activity_at: :desc) }
def self.refresh
# https://github.com/scenic-views/scenic#what-about-materialized-views
# needs atleast one unuque index for concurrent refresh
Scenic.database.refresh_materialized_view(table_name, concurrently: true, cascade: false)
end
def label_list
labels_array
end
def muted?
Redis::Alfred.get(mute_key).present?
end
def readonly?
true
end
private
def mute_key
format(Redis::RedisKeys::CONVERSATION_MUTE_KEY, id: id)
end
end