mirror of
https://github.com/mastodon/mastodon.git
synced 2025-01-08 19:35:11 +01:00
Remove deprecated single-argument variation of UnfilterNotificationsWorker
This commit is contained in:
parent
839a4e27a9
commit
e4d9e643ba
@ -4,25 +4,14 @@ class UnfilterNotificationsWorker
|
|||||||
include Sidekiq::Worker
|
include Sidekiq::Worker
|
||||||
include Redisable
|
include Redisable
|
||||||
|
|
||||||
# Earlier versions of the feature passed a `notification_request` ID
|
def perform(account_id, from_account_id)
|
||||||
# If `to_account_id` is passed, the first argument is an account ID
|
@from_account = Account.find_by(id: from_account_id)
|
||||||
# TODO for after 4.3.0: drop the single-argument case
|
@recipient = Account.find_by(id: account_id)
|
||||||
def perform(notification_request_or_account_id, from_account_id = nil)
|
|
||||||
if from_account_id.present?
|
|
||||||
@notification_request = nil
|
|
||||||
@from_account = Account.find_by(id: from_account_id)
|
|
||||||
@recipient = Account.find_by(id: notification_request_or_account_id)
|
|
||||||
else
|
|
||||||
@notification_request = NotificationRequest.find_by(id: notification_request_or_account_id)
|
|
||||||
@from_account = @notification_request&.from_account
|
|
||||||
@recipient = @notification_request&.account
|
|
||||||
end
|
|
||||||
|
|
||||||
return if @from_account.nil? || @recipient.nil?
|
return if @from_account.nil? || @recipient.nil?
|
||||||
|
|
||||||
push_to_conversations!
|
push_to_conversations!
|
||||||
unfilter_notifications!
|
unfilter_notifications!
|
||||||
remove_request!
|
|
||||||
decrement_worker_count!
|
decrement_worker_count!
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -36,10 +25,6 @@ class UnfilterNotificationsWorker
|
|||||||
filtered_notifications.in_batches.update_all(filtered: false)
|
filtered_notifications.in_batches.update_all(filtered: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_request!
|
|
||||||
@notification_request&.destroy!
|
|
||||||
end
|
|
||||||
|
|
||||||
def filtered_notifications
|
def filtered_notifications
|
||||||
Notification.where(account: @recipient, from_account: @from_account, filtered: true)
|
Notification.where(account: @recipient, from_account: @from_account, filtered: true)
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,7 @@ require 'rails_helper'
|
|||||||
RSpec.describe UnfilterNotificationsWorker do
|
RSpec.describe UnfilterNotificationsWorker do
|
||||||
let(:recipient) { Fabricate(:account) }
|
let(:recipient) { Fabricate(:account) }
|
||||||
let(:sender) { Fabricate(:account) }
|
let(:sender) { Fabricate(:account) }
|
||||||
|
let(:worker) { described_class.new }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
# Populate multiple kinds of filtered notifications
|
# Populate multiple kinds of filtered notifications
|
||||||
@ -67,23 +68,22 @@ RSpec.describe UnfilterNotificationsWorker do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#perform' do
|
describe '#perform' do
|
||||||
context 'with single argument (prerelease behavior)' do
|
context 'with recipient and sender' do
|
||||||
subject { described_class.new.perform(notification_request.id) }
|
subject { worker.perform(recipient.id, sender.id) }
|
||||||
|
|
||||||
let(:notification_request) { Fabricate(:notification_request, from_account: sender, account: recipient) }
|
|
||||||
|
|
||||||
it_behaves_like 'shared behavior'
|
it_behaves_like 'shared behavior'
|
||||||
|
|
||||||
it 'destroys the notification request' do
|
|
||||||
expect { subject }
|
|
||||||
.to change { NotificationRequest.exists?(notification_request.id) }.to(false)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with two arguments' do
|
context 'with missing records' do
|
||||||
subject { described_class.new.perform(recipient.id, sender.id) }
|
it 'runs without error for missing sender' do
|
||||||
|
expect { worker.perform(recipient.id, nil) }
|
||||||
|
.to_not raise_error
|
||||||
|
end
|
||||||
|
|
||||||
it_behaves_like 'shared behavior'
|
it 'runs without error for missing recipient' do
|
||||||
|
expect { worker.perform(nil, sender.id) }
|
||||||
|
.to_not raise_error
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user