feat: Clear all previous notifications if a new notification is added to a conversation (#8490)
This commit is contained in:
16
app/jobs/notification/remove_duplicate_notification_job.rb
Normal file
16
app/jobs/notification/remove_duplicate_notification_job.rb
Normal 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
|
||||
Reference in New Issue
Block a user