about summary refs log tree commit diff
path: root/app/lib/activitypub
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2020-01-15 14:24:55 -0600
committermultiple creatures <dev@multiple-creature.party>2020-01-15 14:24:55 -0600
commitb4b8eaf61cfb0bd6df8fe1cf0d00e55be13dd1f5 (patch)
tree02f2933e69ae2172281908d0c08836ab0a47df15 /app/lib/activitypub
parentf40c1ae07ed96e4629389867593ae5fbc6f226ae (diff)
anti-harassment: add option to toggle whether to allow follows/packmate requests from accounts you've never interacted with before; default to off
Diffstat (limited to 'app/lib/activitypub')
-rw-r--r--app/lib/activitypub/activity/follow.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/app/lib/activitypub/activity/follow.rb b/app/lib/activitypub/activity/follow.rb
index 66df92601..1c19c7006 100644
--- a/app/lib/activitypub/activity/follow.rb
+++ b/app/lib/activitypub/activity/follow.rb
@@ -14,6 +14,11 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
       return
     end
 
+    if !target_account.user.allow_unknown_follows? && !(target_account.following?(@account) || ever_mentioned_by?(target_account))
+      reject_follow_request!(target_account)
+      return
+    end
+
     # Fast-forward repeat follow requests
     if @account.following?(target_account)
       AuthorizeFollowService.new.call(@account, target_account, skip_follow_request: true, follow_request_uri: @json['id'])
@@ -33,5 +38,11 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
   def reject_follow_request!(target_account)
     json = Oj.dump(serialize_payload(FollowRequest.new(account: @account, target_account: target_account, uri: @json['id']), ActivityPub::RejectFollowSerializer))
     ActivityPub::DeliveryWorker.perform_async(json, target_account.id, @account.inbox_url)
+  endA
+
+  private
+
+  def ever_mentioned_by?(target_account)
+    Status.joins(:mentions).merge(target_account.mentions).where(account_id: @account.id).exists?
   end
 end