闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
706 B

  1. # frozen_string_literal: true
  2. require 'csv'
  3. class ImportWorker
  4. include Sidekiq::Worker
  5. sidekiq_options queue: 'pull', retry: false
  6. attr_reader :import
  7. def perform(import_id)
  8. @import = Import.find(import_id)
  9. Import::RelationshipWorker.push_bulk(import_rows) do |row|
  10. [@import.account_id, row.first, relationship_type]
  11. end
  12. @import.destroy
  13. end
  14. private
  15. def import_contents
  16. Paperclip.io_adapters.for(@import.data).read
  17. end
  18. def relationship_type
  19. case @import.type
  20. when 'following'
  21. 'follow'
  22. when 'blocking'
  23. 'block'
  24. when 'muting'
  25. 'mute'
  26. end
  27. end
  28. def import_rows
  29. CSV.new(import_contents).reject(&:blank?)
  30. end
  31. end