mirror of
https://github.com/mastodon/mastodon.git
synced 2026-03-21 18:05:23 -05:00
29 lines
833 B
Ruby
29 lines
833 B
Ruby
# frozen_string_literal: true
|
|
|
|
class UpdateCollectionService
|
|
UPDATEABLE_PARAMS = %w(name description language sensitive discoverable tag_id).freeze
|
|
|
|
def call(collection, params)
|
|
@collection = collection
|
|
@collection.update!(params)
|
|
|
|
distribute_update_activity if Mastodon::Feature.collections_federation_enabled?
|
|
end
|
|
|
|
private
|
|
|
|
def distribute_update_activity
|
|
return unless relevant_attributes_changed?
|
|
|
|
ActivityPub::AccountRawDistributionWorker.perform_async(activity_json, @collection.account.id)
|
|
end
|
|
|
|
def activity_json
|
|
ActiveModelSerializers::SerializableResource.new(@collection, serializer: ActivityPub::UpdateFeaturedCollectionSerializer, adapter: ActivityPub::Adapter).to_json
|
|
end
|
|
|
|
def relevant_attributes_changed?
|
|
(@collection.saved_changes.keys & UPDATEABLE_PARAMS).any?
|
|
end
|
|
end
|