mirror of
https://github.com/mastodon/mastodon.git
synced 2025-02-06 06:55:04 +00:00
Change dismissing a notification to clear existing filtered notifications for that account (#31329)
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.1) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.1) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.1) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.1, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.1) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.1) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.1) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.1, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
This commit is contained in:
parent
6f285bb2a6
commit
670e4655d1
|
@ -29,7 +29,7 @@ class Api::V1::Notifications::RequestsController < Api::BaseController
|
|||
end
|
||||
|
||||
def dismiss
|
||||
@request.destroy!
|
||||
DismissNotificationRequestService.new.call(@request)
|
||||
render_empty
|
||||
end
|
||||
|
||||
|
|
8
app/services/dismiss_notification_request_service.rb
Normal file
8
app/services/dismiss_notification_request_service.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DismissNotificationRequestService < BaseService
|
||||
def call(request)
|
||||
FilteredNotificationCleanupWorker.perform_async(request.account_id, request.from_account_id)
|
||||
request.destroy!
|
||||
end
|
||||
end
|
9
app/workers/filtered_notification_cleanup_worker.rb
Normal file
9
app/workers/filtered_notification_cleanup_worker.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
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).reorder(nil).in_batches(order: :desc).delete_all
|
||||
end
|
||||
end
|
19
spec/services/dismiss_notification_request_service_spec.rb
Normal file
19
spec/services/dismiss_notification_request_service_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DismissNotificationRequestService do
|
||||
describe '#call' do
|
||||
let(:sender) { Fabricate(:account) }
|
||||
let(:receiver) { Fabricate(:account) }
|
||||
let(:request) { Fabricate(:notification_request, account: receiver, from_account: sender) }
|
||||
|
||||
it 'destroys the request and queues a worker', :aggregate_failures do
|
||||
expect { described_class.new.call(request) }
|
||||
.to change(request, :destroyed?).to(true)
|
||||
|
||||
expect(FilteredNotificationCleanupWorker)
|
||||
.to have_enqueued_sidekiq_job(receiver.id, sender.id)
|
||||
end
|
||||
end
|
||||
end
|
24
spec/workers/filtered_notification_cleanup_worker_spec.rb
Normal file
24
spec/workers/filtered_notification_cleanup_worker_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe FilteredNotificationCleanupWorker do
|
||||
describe '#perform' do
|
||||
let(:sender) { Fabricate(:account) }
|
||||
let(:recipient) { Fabricate(:account) }
|
||||
let(:bystander) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
Fabricate(:notification, account: recipient, activity: Fabricate(:favourite, account: sender), filtered: true)
|
||||
Fabricate(:notification, account: recipient, activity: Fabricate(:favourite, account: bystander), filtered: true)
|
||||
Fabricate(:notification, account: recipient, activity: Fabricate(:follow, account: sender), filtered: true)
|
||||
Fabricate(:notification, account: recipient, activity: Fabricate(:favourite, account: bystander), filtered: true)
|
||||
end
|
||||
|
||||
it 'deletes all filtered notifications to the account' do
|
||||
expect { described_class.new.perform(recipient.id, sender.id) }
|
||||
.to change { recipient.notifications.where(from_account: sender).count }.from(2).to(0)
|
||||
.and(not_change { recipient.notifications.where(from_account: bystander).count })
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user