Add support for importing lists (#25203)
This commit is contained in:
@ -7,7 +7,7 @@ class BulkImportRowService
|
||||
@type = row.bulk_import.type.to_sym
|
||||
|
||||
case @type
|
||||
when :following, :blocking, :muting
|
||||
when :following, :blocking, :muting, :lists
|
||||
target_acct = @data['acct']
|
||||
target_domain = domain(target_acct)
|
||||
@target_account = stoplight_wrap_request(target_domain) { ResolveAccountService.new.call(target_acct, { check_delivery_availability: true }) }
|
||||
@ -33,6 +33,12 @@ class BulkImportRowService
|
||||
return false unless StatusPolicy.new(@account, @target_status).show?
|
||||
|
||||
@account.bookmarks.find_or_create_by!(status: @target_status)
|
||||
when :lists
|
||||
list = @account.owned_lists.find_or_create_by!(title: @data['list_name'])
|
||||
|
||||
FollowService.new.call(@account, @target_account) unless @account.id == @target_account.id
|
||||
|
||||
list.accounts << @target_account
|
||||
end
|
||||
|
||||
true
|
||||
|
@ -16,6 +16,8 @@ class BulkImportService < BaseService
|
||||
import_domain_blocks!
|
||||
when :bookmarks
|
||||
import_bookmarks!
|
||||
when :lists
|
||||
import_lists!
|
||||
end
|
||||
|
||||
@import.update!(state: :finished, finished_at: Time.now.utc) if @import.processed_items == @import.total_items
|
||||
@ -157,4 +159,24 @@ class BulkImportService < BaseService
|
||||
[row.id]
|
||||
end
|
||||
end
|
||||
|
||||
def import_lists!
|
||||
rows = @import.rows.to_a
|
||||
|
||||
if @import.overwrite?
|
||||
included_lists = rows.map { |row| row.data['list_name'] }.uniq
|
||||
|
||||
@account.owned_lists.where.not(title: included_lists).destroy_all
|
||||
|
||||
# As list membership changes do not retroactively change timeline
|
||||
# contents, simplify things by just clearing everything
|
||||
@account.owned_lists.find_each do |list|
|
||||
list.list_accounts.destroy_all
|
||||
end
|
||||
end
|
||||
|
||||
Import::RowWorker.push_bulk(rows) do |row|
|
||||
[row.id]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user