mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-14 00:08:46 +00:00
25 lines
542 B
Ruby
25 lines
542 B
Ruby
# frozen_string_literal: true
|
|
|
|
class CreateCollectionService
|
|
def call(params, account)
|
|
account_ids = params.delete(:account_ids)
|
|
@collection = Collection.new(params.merge({ account:, local: true }))
|
|
build_items(account_ids)
|
|
|
|
@collection.save!
|
|
@collection
|
|
end
|
|
|
|
private
|
|
|
|
def build_items(account_ids)
|
|
return if account_ids.blank?
|
|
|
|
account_ids.each do |account_id|
|
|
account = Account.find(account_id)
|
|
# TODO: validate preferences
|
|
@collection.collection_items.build(account:)
|
|
end
|
|
end
|
|
end
|