Fix no notification being created when account is added to collection on creation (#38611)

This commit is contained in:
Eugen Rochko 2026-04-08 18:01:37 +02:00 committed by GitHub
parent 28b04ec24e
commit ba9eabccbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 0 deletions

View File

@ -47,6 +47,10 @@ class CollectionItem < ApplicationRecord
update!(state: :revoked)
end
def with_local_account?
account&.local?
end
def local_item_with_remote_account?
local? && account&.remote?
end

View File

@ -9,6 +9,7 @@ class CreateCollectionService
@collection.save!
notify_local_users
distribute_add_activity
distribute_feature_request_activities
@ -39,6 +40,12 @@ class CreateCollectionService
end
end
def notify_local_users
@collection.collection_items.select(&:with_local_account?).each do |collection_item|
LocalNotificationWorker.perform_async(@account.id, collection_item.id, collection_item.class.name, 'added_to_collection')
end
end
def activity_json
ActiveModelSerializers::SerializableResource.new(@collection, serializer: ActivityPub::AddFeaturedCollectionSerializer, adapter: ActivityPub::Adapter).to_json
end

View File

@ -62,6 +62,16 @@ RSpec.describe CreateCollectionService do
end
end
context 'when some accounts are local' do
it 'schedules notifications' do
subject.call(params, author)
expect(LocalNotificationWorker)
.to have_enqueued_sidekiq_job
.with(author.id, anything, 'CollectionItem', 'added_to_collection')
end
end
context 'when some accounts are remote' do
let(:accounts) { Fabricate.times(2, :remote_account, feature_approval_policy: (0b10 << 16)) }