diff options
author | Thibaut Girka <thib@sitedethib.com> | 2019-04-04 14:53:52 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2019-04-04 14:53:52 +0200 |
commit | 1682ac571763f473da54074b0608cd9ccb4b9ae5 (patch) | |
tree | 2cb3f134660b2d7d460772966f7eb595395611f7 /app/services | |
parent | 3f5acc1ab3bc9c5a6c5805901a393ccd3457b909 (diff) | |
parent | 26bd9fa508ac155f996c2c0d9753a27d46158749 (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: - app/controllers/following_accounts_controller.rb Conflicts were due to glitch-soc's theming system. - app/javascript/packs/public.js Some code has been change upstream, but it has been moved to app/javascript/core/settings.js in glitch-soc. Applied the changes there.
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/import_service.rb | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/app/services/import_service.rb b/app/services/import_service.rb index 3f558626e..c1c88e0dd 100644 --- a/app/services/import_service.rb +++ b/app/services/import_service.rb @@ -8,7 +8,6 @@ class ImportService < BaseService def call(import) @import = import @account = @import.account - @data = CSV.new(import_data).reject(&:blank?) case @import.type when 'following' @@ -25,19 +24,23 @@ class ImportService < BaseService private def import_follows! + parse_import_data!(['Account address']) import_relationships!('follow', 'unfollow', @account.following, follow_limit) end def import_blocks! + parse_import_data!(['Account address']) import_relationships!('block', 'unblock', @account.blocking, ROWS_PROCESSING_LIMIT) end def import_mutes! + parse_import_data!(['Account address']) import_relationships!('mute', 'unmute', @account.muting, ROWS_PROCESSING_LIMIT) end def import_domain_blocks! - items = @data.take(ROWS_PROCESSING_LIMIT).map { |row| row.first.strip } + parse_import_data!(['#domain']) + items = @data.take(ROWS_PROCESSING_LIMIT).map { |row| row['#domain'].strip } if @import.overwrite? presence_hash = items.each_with_object({}) { |id, mapping| mapping[id] = true } @@ -61,25 +64,33 @@ class ImportService < BaseService end def import_relationships!(action, undo_action, overwrite_scope, limit) - items = @data.take(limit).map { |row| row.first.strip } + items = @data.take(limit).map { |row| [row['Account address']&.strip, row['Hide notifications']&.strip] }.reject { |(id, _)| id.blank? } if @import.overwrite? - presence_hash = items.each_with_object({}) { |id, mapping| mapping[id] = true } + presence_hash = items.each_with_object({}) { |(id, extra), mapping| mapping[id] = [true, extra] } overwrite_scope.find_each do |target_account| if presence_hash[target_account.acct] items.delete(target_account.acct) + extra = presence_hash[target_account.acct][1] + Import::RelationshipWorker.perform_async(@account.id, target_account.acct, action, ActiveModel::Type::Boolean.new.cast(extra)) else Import::RelationshipWorker.perform_async(@account.id, target_account.acct, undo_action) end end end - Import::RelationshipWorker.push_bulk(items) do |acct| - [@account.id, acct, action] + Import::RelationshipWorker.push_bulk(items) do |acct, extra| + [@account.id, acct, action, ActiveModel::Type::Boolean.new.cast(extra)] end end + def parse_import_data!(default_headers) + data = CSV.parse(import_data, headers: true) + data = CSV.parse(import_data, headers: default_headers) unless data.headers&.first&.strip&.include?(' ') + @data = data.reject(&:blank?) + end + def import_data Paperclip.io_adapters.for(@import.data).read end |