feat: Clear all previous notifications if a new notification is added to a conversation (#8490)

This commit is contained in:
Muhsin Keloth
2023-12-06 14:03:43 +05:30
committed by GitHub
parent 76711d95ff
commit db33b7d1dc
6 changed files with 57 additions and 6 deletions

View File

@@ -0,0 +1,16 @@
class Notification::RemoveDuplicateNotificationJob < ApplicationJob
queue_as :default
def perform(notification)
return unless notification.is_a?(Notification)
user_id = notification.user_id
primary_actor_id = notification.primary_actor_id
# Find older notifications with the same user and primary_actor_id, excluding the new one
duplicate_notifications = Notification.where(user_id: user_id, primary_actor_id: primary_actor_id)
.where.not(id: notification.id)
duplicate_notifications.each(&:destroy)
end
end