feat: Add notification_deleted action cable event (#8431)
This commit is contained in:
@@ -7,6 +7,12 @@ class ActionCableListener < BaseListener
|
|||||||
broadcast(account, tokens, NOTIFICATION_CREATED, { notification: notification.push_event_data, unread_count: unread_count, count: count })
|
broadcast(account, tokens, NOTIFICATION_CREATED, { notification: notification.push_event_data, unread_count: unread_count, count: count })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notification_deleted(event)
|
||||||
|
notification, account, unread_count, count = extract_notification_and_account(event)
|
||||||
|
tokens = [event.data[:notification].user.pubsub_token]
|
||||||
|
broadcast(account, tokens, NOTIFICATION_DELETED, notification: notification, unread_count: unread_count, count: count)
|
||||||
|
end
|
||||||
|
|
||||||
def account_cache_invalidated(event)
|
def account_cache_invalidated(event)
|
||||||
account = event.data[:account]
|
account = event.data[:account]
|
||||||
tokens = user_tokens(account, account.agents)
|
tokens = user_tokens(account, account.agents)
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class Notification < ApplicationRecord
|
|||||||
enum notification_type: NOTIFICATION_TYPES
|
enum notification_type: NOTIFICATION_TYPES
|
||||||
|
|
||||||
after_create_commit :process_notification_delivery, :dispatch_create_event
|
after_create_commit :process_notification_delivery, :dispatch_create_event
|
||||||
|
after_destroy_commit :dispatch_destroy_event
|
||||||
|
|
||||||
# TODO: Get rid of default scope
|
# TODO: Get rid of default scope
|
||||||
# https://stackoverflow.com/a/1834250/939299
|
# https://stackoverflow.com/a/1834250/939299
|
||||||
@@ -135,4 +136,8 @@ class Notification < ApplicationRecord
|
|||||||
def dispatch_create_event
|
def dispatch_create_event
|
||||||
Rails.configuration.dispatcher.dispatch(NOTIFICATION_CREATED, Time.zone.now, notification: self)
|
Rails.configuration.dispatcher.dispatch(NOTIFICATION_CREATED, Time.zone.now, notification: self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dispatch_destroy_event
|
||||||
|
Rails.configuration.dispatcher.dispatch(NOTIFICATION_DELETED, Time.zone.now, notification: self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ module Events::Types
|
|||||||
|
|
||||||
# notification events
|
# notification events
|
||||||
NOTIFICATION_CREATED = 'notification.created'
|
NOTIFICATION_CREATED = 'notification.created'
|
||||||
|
NOTIFICATION_DELETED = 'notification.deleted'
|
||||||
|
|
||||||
# agent events
|
# agent events
|
||||||
AGENT_ADDED = 'agent.added'
|
AGENT_ADDED = 'agent.added'
|
||||||
|
|||||||
@@ -131,6 +131,27 @@ describe ActionCableListener do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#notification_deleted' do
|
||||||
|
let(:event_name) { :'notification.deleted' }
|
||||||
|
let!(:notification) { create(:notification, account: account, user: agent) }
|
||||||
|
let!(:event) { Events::Base.new(event_name, Time.zone.now, notification: notification) }
|
||||||
|
|
||||||
|
it 'sends message to account admins, inbox agents' do
|
||||||
|
expect(ActionCableBroadcastJob).to receive(:perform_later).with(
|
||||||
|
[agent.pubsub_token],
|
||||||
|
'notification.deleted',
|
||||||
|
{
|
||||||
|
account_id: notification.account_id,
|
||||||
|
notification: notification,
|
||||||
|
unread_count: 1,
|
||||||
|
count: 1
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
listener.notification_deleted(event)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#conversation_updated' do
|
describe '#conversation_updated' do
|
||||||
let(:event_name) { :'conversation.updated' }
|
let(:event_name) { :'conversation.updated' }
|
||||||
let!(:event) { Events::Base.new(event_name, Time.zone.now, conversation: conversation, user: agent, is_private: false) }
|
let!(:event) { Events::Base.new(event_name, Time.zone.now, conversation: conversation, user: agent, is_private: false) }
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ Hey @John, @Alisha Peter can you check this ticket?"
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when primary actory is deleted' do
|
context 'when primary actor is deleted' do
|
||||||
let!(:conversation) { create(:conversation) }
|
let!(:conversation) { create(:conversation) }
|
||||||
|
|
||||||
it 'clears notifications' do
|
it 'clears notifications' do
|
||||||
|
|||||||
Reference in New Issue
Block a user