]> cat aescling's git repositories - mastodon.git/commitdiff
Allow Accept/Reject with a non-embedded object (#12199)
authorpuckipedia <puck@puckipedia.com>
Thu, 24 Oct 2019 20:45:43 +0000 (20:45 +0000)
committerEugen Rochko <eugen@zeonfederated.com>
Thu, 24 Oct 2019 20:45:43 +0000 (22:45 +0200)
Some ActivityPub servers refuse to embed remote objects into their own
output. This is because they are not the authoritative source for these
objects, and as such embedding them is always a waste of space. The
follow request and follow models contain a URI, so this can be used to
match them.

app/lib/activitypub/activity.rb
app/lib/activitypub/activity/accept.rb
app/lib/activitypub/activity/reject.rb

index a4a9baaee40e568c239b752835b80b0f720cbcb1..5cd48a6aec8bc6a068a07e51e1184dbff3d20c31 100644 (file)
@@ -153,6 +153,14 @@ class ActivityPub::Activity
     fetch_remote_original_status
   end
 
+  def follow_request_from_object
+    @follow_request ||= FollowRequest.find_by(target_account: @account, uri: object_uri) unless object_uri.nil?
+  end
+
+  def follow_from_object
+    @follow ||= Follow.find_by(target_account: @account, uri: object_uri) unless object_uri.nil?
+  end
+
   def fetch_remote_original_status
     if object_uri.start_with?('http')
       return if ActivityPub::TagManager.instance.local_uri?(object_uri)
index 348ee0d1cb3ef27ea9ccc559c18fc2ac8dadb3a7..7010ff43e8e4f8a4d4b97e19d48c209e0d49c93e 100644 (file)
@@ -2,17 +2,18 @@
 
 class ActivityPub::Activity::Accept < ActivityPub::Activity
   def perform
+    return accept_follow_for_relay if relay_follow?
+    return follow_request_from_object.authorize! unless follow_request_from_object.nil?
+
     case @object['type']
     when 'Follow'
-      accept_follow
+      accept_embedded_follow
     end
   end
 
   private
 
-  def accept_follow
-    return accept_follow_for_relay if relay_follow?
-
+  def accept_embedded_follow
     target_account = account_from_uri(target_uri)
 
     return if target_account.nil? || !target_account.local?
index dba21fb9a7d896c23a7a385f935b72f34fb31b40..8d771ed81753b311d77403128bd71d1594f1f55d 100644 (file)
@@ -2,17 +2,19 @@
 
 class ActivityPub::Activity::Reject < ActivityPub::Activity
   def perform
+    return reject_follow_for_relay if relay_follow?
+    return follow_request_from_object.reject! unless follow_request_from_object.nil?
+    return UnfollowService.new.call(follow_from_object.target_account, @account) unless follow_from_object.nil?
+
     case @object['type']
     when 'Follow'
-      reject_follow
+      reject_embedded_follow
     end
   end
 
   private
 
-  def reject_follow
-    return reject_follow_for_relay if relay_follow?
-
+  def reject_embedded_follow
     target_account = account_from_uri(target_uri)
 
     return if target_account.nil? || !target_account.local?