From ba9eabccbfeb4be9168ef6a5c17670deabab6ffd Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 8 Apr 2026 18:01:37 +0200 Subject: [PATCH] Fix no notification being created when account is added to collection on creation (#38611) --- app/models/collection_item.rb | 4 ++++ app/services/create_collection_service.rb | 7 +++++++ spec/services/create_collection_service_spec.rb | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/app/models/collection_item.rb b/app/models/collection_item.rb index f7067fb2fc..8877f3f8da 100644 --- a/app/models/collection_item.rb +++ b/app/models/collection_item.rb @@ -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 diff --git a/app/services/create_collection_service.rb b/app/services/create_collection_service.rb index e38bddebba..1b94e41f44 100644 --- a/app/services/create_collection_service.rb +++ b/app/services/create_collection_service.rb @@ -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 diff --git a/spec/services/create_collection_service_spec.rb b/spec/services/create_collection_service_spec.rb index ded9d4d567..1cca49764f 100644 --- a/spec/services/create_collection_service_spec.rb +++ b/spec/services/create_collection_service_spec.rb @@ -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)) }