about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'app/services')
-rw-r--r--app/services/block_domain_service.rb13
-rw-r--r--app/services/follow_remote_account_service.rb1
-rw-r--r--app/services/process_interaction_service.rb2
3 files changed, 16 insertions, 0 deletions
diff --git a/app/services/block_domain_service.rb b/app/services/block_domain_service.rb
new file mode 100644
index 000000000..075460605
--- /dev/null
+++ b/app/services/block_domain_service.rb
@@ -0,0 +1,13 @@
+class BlockDomainService < BaseService
+  def call(domain)
+    block = DomainBlock.find_or_create_by!(domain: domain)
+
+    Account.where(domain: domain).find_each do |account|
+      if account.subscribed?
+        account.subscription('').unsubscribe
+      end
+
+      account.destroy!
+    end
+  end
+end
diff --git a/app/services/follow_remote_account_service.rb b/app/services/follow_remote_account_service.rb
index 3b305504c..43a598635 100644
--- a/app/services/follow_remote_account_service.rb
+++ b/app/services/follow_remote_account_service.rb
@@ -8,6 +8,7 @@ class FollowRemoteAccountService < BaseService
     username, domain = uri.split('@')
 
     return Account.find_local(username) if TagManager.instance.local_domain?(domain)
+    return nil if DomainBlock.blocked?(domain)
 
     account = Account.find_remote(username, domain)
 
diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb
index 0768579ef..75051c5df 100644
--- a/app/services/process_interaction_service.rb
+++ b/app/services/process_interaction_service.rb
@@ -13,6 +13,8 @@ class ProcessInteractionService < BaseService
     domain   = Addressable::URI.parse(url).host
     account  = Account.find_by(username: username, domain: domain)
 
+    return if DomainBlock.blocked?(domain)
+
     if account.nil?
       account = follow_remote_account_service.call("#{username}@#{domain}")
     end