From 63b3686746186e811ae1ba6911bc5938afb69ab1 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Fri, 12 Jan 2024 06:24:03 +0530 Subject: [PATCH] chore: Add a check to verify if the user exists before broadcasting the `notification_deleted` event. (#8678) When a user is deleted, all associated notifications are also deleted from the database. As a result, the user record becomes empty. handling this case in code to prevent sentry errors. --- app/listeners/action_cable_listener.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/listeners/action_cable_listener.rb b/app/listeners/action_cable_listener.rb index b74c46909..3d6b4a48c 100644 --- a/app/listeners/action_cable_listener.rb +++ b/app/listeners/action_cable_listener.rb @@ -8,6 +8,8 @@ class ActionCableListener < BaseListener end def notification_deleted(event) + return if event.data[:notification].user.blank? + notification, account, unread_count, count = extract_notification_and_account(event) tokens = [event.data[:notification].user.pubsub_token] broadcast(account, tokens, NOTIFICATION_DELETED, { notification: notification.push_event_data, unread_count: unread_count, count: count })