about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/api/v1/domain_blocks_controller.rb1
-rw-r--r--app/services/activitypub/process_account_service.rb9
-rw-r--r--app/services/after_block_domain_from_account_service.rb7
-rw-r--r--app/services/after_unblock_domain_from_account_service.rb18
-rw-r--r--app/services/update_account_domain_blocks_service.rb19
-rw-r--r--app/workers/after_account_domain_unblock_worker.rb11
-rw-r--r--app/workers/update_account_domain_blocks_worker.rb11
7 files changed, 75 insertions, 1 deletions
diff --git a/app/controllers/api/v1/domain_blocks_controller.rb b/app/controllers/api/v1/domain_blocks_controller.rb
index af9e7a20f..21c9d3aae 100644
--- a/app/controllers/api/v1/domain_blocks_controller.rb
+++ b/app/controllers/api/v1/domain_blocks_controller.rb
@@ -23,6 +23,7 @@ class Api::V1::DomainBlocksController < Api::BaseController
 
   def destroy
     current_account.unblock_domain!(domain_block_params[:domain])
+    AfterAccountDomainUnblockWorker.perform_async(current_account.id, domain_block_params[:domain])
     render_empty
   end
 
diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb
index 8064fcb00..414dbfda7 100644
--- a/app/services/activitypub/process_account_service.rb
+++ b/app/services/activitypub/process_account_service.rb
@@ -20,8 +20,10 @@ class ActivityPub::ProcessAccountService < BaseService
         @account        = Account.find_remote(@username, @domain)
         @old_public_key = @account&.public_key
 
-        create_account if @account.nil?
+        is_new_account = @account.nil?
+        create_account if is_new_account
         update_account
+        update_account_domain_blocks if is_new_account
         process_tags
         process_attachments
       else
@@ -105,6 +107,11 @@ class ActivityPub::ProcessAccountService < BaseService
     VerifyAccountLinksWorker.perform_async(@account.id)
   end
 
+  def update_account_domain_blocks
+    return if @account.domain.nil? || @account.local?
+    UpdateAccountDomainBlocksWorker.perform_async(@account.id)
+  end
+
   def actor_type
     if @json['type'].is_a?(Array)
       @json['type'].find { |type| ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(type) }
diff --git a/app/services/after_block_domain_from_account_service.rb b/app/services/after_block_domain_from_account_service.rb
index f12f18319..762a8baea 100644
--- a/app/services/after_block_domain_from_account_service.rb
+++ b/app/services/after_block_domain_from_account_service.rb
@@ -10,6 +10,7 @@ class AfterBlockDomainFromAccountService < BaseService
 
     reject_existing_followers!
     reject_pending_follow_requests!
+    block_accounts!
   end
 
   private
@@ -26,6 +27,12 @@ class AfterBlockDomainFromAccountService < BaseService
     end
   end
 
+  def block_accounts!
+    Account.where(domain: @domain).find_each do |blocked_account|
+      BlockService.new.call(@account, blocked_account)
+    end
+  end
+
   def reject_follow!(follow)
     follow.destroy
 
diff --git a/app/services/after_unblock_domain_from_account_service.rb b/app/services/after_unblock_domain_from_account_service.rb
new file mode 100644
index 000000000..a2d10bcf0
--- /dev/null
+++ b/app/services/after_unblock_domain_from_account_service.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AfterUnblockDomainFromAccountService < BaseService
+  def call(account, domain)
+    @account = account
+    @domain  = domain
+
+    unblock_accounts!
+  end
+
+  private
+
+  def unblock_accounts!
+    @account.blocking.where(domain: @domain).find_each do |blocked_account|
+      UnblockService.new.call(@account, blocked_account)
+    end
+  end
+end
diff --git a/app/services/update_account_domain_blocks_service.rb b/app/services/update_account_domain_blocks_service.rb
new file mode 100644
index 000000000..d14cdbdda
--- /dev/null
+++ b/app/services/update_account_domain_blocks_service.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class UpdateAccountDomainBlocksService < BaseService
+  def call(account)
+    @account = account
+    @domain  = account.domain
+
+    block_where_domain_blocked!
+  end
+
+  private
+
+  def block_where_domain_blocked!
+    account_ids = AccountDomainBlock.distinct.where(domain: @domain).pluck(:account_id)
+    Account.where(id: account_ids).find_each do |blocked_by|
+      BlockService.new.call(blocked_by, @account)
+    end
+  end
+end
diff --git a/app/workers/after_account_domain_unblock_worker.rb b/app/workers/after_account_domain_unblock_worker.rb
new file mode 100644
index 000000000..6268f0819
--- /dev/null
+++ b/app/workers/after_account_domain_unblock_worker.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class AfterAccountDomainUnblockWorker
+  include Sidekiq::Worker
+
+  def perform(account_id, domain)
+    AfterUnblockDomainFromAccountService.new.call(Account.find(account_id), domain)
+  rescue ActiveRecord::RecordNotFound
+    true
+  end
+end
diff --git a/app/workers/update_account_domain_blocks_worker.rb b/app/workers/update_account_domain_blocks_worker.rb
new file mode 100644
index 000000000..14d4e8516
--- /dev/null
+++ b/app/workers/update_account_domain_blocks_worker.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class UpdateAccountDomainBlocksWorker
+  include Sidekiq::Worker
+
+  def perform(account_id)
+    UpdateAccountDomainBlocksService.new.call(Account.find(account_id))
+  rescue ActiveRecord::RecordNotFound
+    true
+  end
+end