feat: Update notifications and unread count in real time (#4261)
This commit is contained in:
@@ -72,6 +72,7 @@ class Account < ApplicationRecord
|
||||
has_many :sms_channels, dependent: :destroy_async, class_name: '::Channel::Sms'
|
||||
has_many :working_hours, dependent: :destroy_async
|
||||
has_many :automation_rules, dependent: :destroy
|
||||
has_many :notifications, dependent: :destroy
|
||||
|
||||
has_flags ACCOUNT_SETTINGS_FLAGS.merge(column: 'settings_flags').merge(DEFAULT_QUERY_SETTING)
|
||||
|
||||
|
||||
@@ -52,15 +52,24 @@ class Notification < ApplicationRecord
|
||||
notification_type: notification_type,
|
||||
primary_actor_type: primary_actor_type,
|
||||
primary_actor_id: primary_actor_id,
|
||||
primary_actor: primary_actor.push_event_data,
|
||||
primary_actor: primary_actor_data,
|
||||
read_at: read_at,
|
||||
secondary_actor: secondary_actor&.push_event_data,
|
||||
user: user&.push_event_data,
|
||||
created_at: created_at,
|
||||
account_id: account_id
|
||||
created_at: created_at.to_i,
|
||||
account_id: account_id,
|
||||
push_message_title: push_message_title
|
||||
}
|
||||
end
|
||||
|
||||
def primary_actor_data
|
||||
if %w[assigned_conversation_new_message conversation_mention].include? notification_type
|
||||
primary_actor.conversation.push_event_data
|
||||
else
|
||||
primary_actor.push_event_data
|
||||
end
|
||||
end
|
||||
|
||||
def fcm_push_data
|
||||
{
|
||||
id: id,
|
||||
|
||||
@@ -187,4 +187,11 @@ class User < ApplicationRecord
|
||||
def will_save_change_to_email?
|
||||
mutations_from_database.changed?('email')
|
||||
end
|
||||
|
||||
def notifications_meta
|
||||
{
|
||||
unread_count: notifications.where(read_at: nil).count,
|
||||
count: notifications.count
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user