mirror of
https://github.com/yingziwu/mastodon.git
synced 2026-02-04 03:25:14 +00:00
Reload notifications when accepted notifications are merged (streaming only) (#31419)
This commit is contained in:
parent
d4f135bc6d
commit
53c183f899
11 changed files with 192 additions and 24 deletions
|
|
@ -120,4 +120,34 @@ RSpec.describe 'Requests' do
|
|||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/notifications/requests/merged' do
|
||||
subject do
|
||||
get '/api/v1/notifications/requests/merged', headers: headers
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write write:notifications'
|
||||
|
||||
context 'when the user has no accepted request pending merge' do
|
||||
it 'returns http success and returns merged: true' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq({ merged: true })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the user has an accepted request pending merge' do
|
||||
before do
|
||||
redis.set("notification_unfilter_jobs:#{user.account_id}", 1)
|
||||
end
|
||||
|
||||
it 'returns http success and returns merged: false' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq({ merged: false })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,10 +8,11 @@ RSpec.describe AcceptNotificationRequestService do
|
|||
let(:notification_request) { Fabricate(:notification_request) }
|
||||
|
||||
describe '#call' do
|
||||
it 'destroys the notification request, creates a permission, and queues a worker' do
|
||||
it 'destroys the notification request, creates a permission, increases the jobs count and queues a worker' do
|
||||
expect { subject.call(notification_request) }
|
||||
.to change { NotificationRequest.exists?(notification_request.id) }.to(false)
|
||||
.and change { NotificationPermission.exists?(account_id: notification_request.account_id, from_account_id: notification_request.from_account_id) }.to(true)
|
||||
.and change { redis.get("notification_unfilter_jobs:#{notification_request.account_id}").to_i }.by(1)
|
||||
|
||||
expect(UnfilterNotificationsWorker).to have_enqueued_sidekiq_job(notification_request.account_id, notification_request.from_account_id)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,13 +13,56 @@ describe UnfilterNotificationsWorker do
|
|||
Fabricate(:notification, filtered: true, from_account: sender, account: recipient, type: :mention, activity: mention)
|
||||
follow_request = sender.request_follow!(recipient)
|
||||
Fabricate(:notification, filtered: true, from_account: sender, account: recipient, type: :follow_request, activity: follow_request)
|
||||
allow(redis).to receive(:publish)
|
||||
allow(redis).to receive(:exists?).and_return(false)
|
||||
end
|
||||
|
||||
shared_examples 'shared behavior' do
|
||||
it 'unfilters notifications and adds private messages to conversations' do
|
||||
expect { subject }
|
||||
.to change { recipient.notifications.where(from_account_id: sender.id).pluck(:filtered) }.from([true, true]).to([false, false])
|
||||
.and change { recipient.conversations.exists?(last_status_id: sender.statuses.first.id) }.to(true)
|
||||
context 'when this is the last pending merge job and the user is subscribed to streaming' do
|
||||
before do
|
||||
redis.set("notification_unfilter_jobs:#{recipient.id}", 1)
|
||||
allow(redis).to receive(:exists?).with("subscribed:timeline:#{recipient.id}").and_return(true)
|
||||
end
|
||||
|
||||
it 'unfilters notifications, adds private messages to conversations, and pushes to redis' do
|
||||
expect { subject }
|
||||
.to change { recipient.notifications.where(from_account_id: sender.id).pluck(:filtered) }.from([true, true]).to([false, false])
|
||||
.and change { recipient.conversations.exists?(last_status_id: sender.statuses.first.id) }.to(true)
|
||||
.and change { redis.get("notification_unfilter_jobs:#{recipient.id}").to_i }.by(-1)
|
||||
|
||||
expect(redis).to have_received(:publish).with("timeline:#{recipient.id}:notifications", '{"event":"notifications_merged","payload":"1"}')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when this is not last pending merge job and the user is subscribed to streaming' do
|
||||
before do
|
||||
redis.set("notification_unfilter_jobs:#{recipient.id}", 2)
|
||||
allow(redis).to receive(:exists?).with("subscribed:timeline:#{recipient.id}").and_return(true)
|
||||
end
|
||||
|
||||
it 'unfilters notifications, adds private messages to conversations, and does not push to redis' do
|
||||
expect { subject }
|
||||
.to change { recipient.notifications.where(from_account_id: sender.id).pluck(:filtered) }.from([true, true]).to([false, false])
|
||||
.and change { recipient.conversations.exists?(last_status_id: sender.statuses.first.id) }.to(true)
|
||||
.and change { redis.get("notification_unfilter_jobs:#{recipient.id}").to_i }.by(-1)
|
||||
|
||||
expect(redis).to_not have_received(:publish).with("timeline:#{recipient.id}:notifications", '{"event":"notifications_merged","payload":"1"}')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when this is the last pending merge job and the user is not subscribed to streaming' do
|
||||
before do
|
||||
redis.set("notification_unfilter_jobs:#{recipient.id}", 1)
|
||||
end
|
||||
|
||||
it 'unfilters notifications, adds private messages to conversations, and does not push to redis' do
|
||||
expect { subject }
|
||||
.to change { recipient.notifications.where(from_account_id: sender.id).pluck(:filtered) }.from([true, true]).to([false, false])
|
||||
.and change { recipient.conversations.exists?(last_status_id: sender.statuses.first.id) }.to(true)
|
||||
.and change { redis.get("notification_unfilter_jobs:#{recipient.id}").to_i }.by(-1)
|
||||
|
||||
expect(redis).to_not have_received(:publish).with("timeline:#{recipient.id}:notifications", '{"event":"notifications_merged","payload":"1"}')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue