diff --git a/app/controllers/api/v1/notifications/requests_controller.rb b/app/controllers/api/v1/notifications/requests_controller.rb index 3c90f13ce24..6642725393c 100644 --- a/app/controllers/api/v1/notifications/requests_controller.rb +++ b/app/controllers/api/v1/notifications/requests_controller.rb @@ -45,6 +45,7 @@ class Api::V1::Notifications::RequestsController < Api::BaseController end def dismiss_bulk + FilteredNotificationCleanupWorker.perform_async(current_account.id, @requests.map(&:from_account_id)) @requests.each(&:destroy!) render_empty end diff --git a/app/workers/filtered_notification_cleanup_worker.rb b/app/workers/filtered_notification_cleanup_worker.rb index 87ff6a9eb5e..d4107bbfdab 100644 --- a/app/workers/filtered_notification_cleanup_worker.rb +++ b/app/workers/filtered_notification_cleanup_worker.rb @@ -3,7 +3,7 @@ class FilteredNotificationCleanupWorker include Sidekiq::Worker - def perform(account_id, from_account_id) - Notification.where(account_id: account_id, from_account_id: from_account_id, filtered: true).in_batches(order: :desc).delete_all + def perform(account_id, from_account_ids) + Notification.where(account_id: account_id, from_account_id: from_account_ids, filtered: true).in_batches(order: :desc).delete_all end end diff --git a/spec/requests/api/v1/notifications/requests_spec.rb b/spec/requests/api/v1/notifications/requests_spec.rb index bee9d3a3da9..596f910fe95 100644 --- a/spec/requests/api/v1/notifications/requests_spec.rb +++ b/spec/requests/api/v1/notifications/requests_spec.rb @@ -122,7 +122,9 @@ RSpec.describe 'Requests' do it_behaves_like 'forbidden for wrong scope', 'read read:notifications' it 'returns http success and destroys the notification request', :aggregate_failures do - expect { subject }.to change(NotificationRequest, :count).by(-1) + expect { subject } + .to change(NotificationRequest, :count).by(-1) + .and enqueue_sidekiq_job(FilteredNotificationCleanupWorker).with(user.account_id, be_a(Array)) expect(response).to have_http_status(200) expect(response.content_type) diff --git a/spec/workers/filtered_notification_cleanup_worker_spec.rb b/spec/workers/filtered_notification_cleanup_worker_spec.rb index 5ecd4291af9..4e839c26827 100644 --- a/spec/workers/filtered_notification_cleanup_worker_spec.rb +++ b/spec/workers/filtered_notification_cleanup_worker_spec.rb @@ -20,5 +20,20 @@ RSpec.describe FilteredNotificationCleanupWorker do .to change { recipient.notifications.where(from_account: sender).count }.from(2).to(0) .and(not_change { recipient.notifications.where(from_account: bystander).count }) end + + context 'when given an array of IDs as parameter' do + let(:other_sender) { Fabricate(:account) } + + before do + Fabricate(:notification, account: recipient, activity: Fabricate(:favourite, account: other_sender), filtered: true) + end + + it 'deletes all filtered notifications to the account' do + expect { described_class.new.perform(recipient.id, [sender.id, other_sender.id]) } + .to change { recipient.notifications.where(from_account: sender).count }.from(2).to(0) + .and change { recipient.notifications.where(from_account: other_sender).count }.from(1).to(0) + .and(not_change { recipient.notifications.where(from_account: bystander).count }) + end + end end end