Fix no notification being created when account is added to collection on creation (#38611)
This commit is contained in:
parent
28b04ec24e
commit
ba9eabccbf
@ -47,6 +47,10 @@ class CollectionItem < ApplicationRecord
|
|||||||
update!(state: :revoked)
|
update!(state: :revoked)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_local_account?
|
||||||
|
account&.local?
|
||||||
|
end
|
||||||
|
|
||||||
def local_item_with_remote_account?
|
def local_item_with_remote_account?
|
||||||
local? && account&.remote?
|
local? && account&.remote?
|
||||||
end
|
end
|
||||||
|
|||||||
@ -9,6 +9,7 @@ class CreateCollectionService
|
|||||||
|
|
||||||
@collection.save!
|
@collection.save!
|
||||||
|
|
||||||
|
notify_local_users
|
||||||
distribute_add_activity
|
distribute_add_activity
|
||||||
distribute_feature_request_activities
|
distribute_feature_request_activities
|
||||||
|
|
||||||
@ -39,6 +40,12 @@ class CreateCollectionService
|
|||||||
end
|
end
|
||||||
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
|
def activity_json
|
||||||
ActiveModelSerializers::SerializableResource.new(@collection, serializer: ActivityPub::AddFeaturedCollectionSerializer, adapter: ActivityPub::Adapter).to_json
|
ActiveModelSerializers::SerializableResource.new(@collection, serializer: ActivityPub::AddFeaturedCollectionSerializer, adapter: ActivityPub::Adapter).to_json
|
||||||
end
|
end
|
||||||
|
|||||||
@ -62,6 +62,16 @@ RSpec.describe CreateCollectionService do
|
|||||||
end
|
end
|
||||||
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
|
context 'when some accounts are remote' do
|
||||||
let(:accounts) { Fabricate.times(2, :remote_account, feature_approval_policy: (0b10 << 16)) }
|
let(:accounts) { Fabricate.times(2, :remote_account, feature_approval_policy: (0b10 << 16)) }
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user