about summary refs log tree commit diff
path: root/app/models/follow_request.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-05-04 21:14:34 +0200
committerGitHub <noreply@github.com>2018-05-04 21:14:34 +0200
commit6793bec4c67e695100cb4d8551f0bda0b7e87b12 (patch)
tree696e35d972dd537bc9b2551cc11eb95a0b6414d2 /app/models/follow_request.rb
parentd1aef17f9ad0074458ad0b390ac73db228928f07 (diff)
Store URIs of follows, follow requests and blocks for ActivityPub (#7160)
Same URI passed between follow request and follow, since they are
the same thing in ActivityPub. Local URIs are generated during
creation using UUIDs and are passed to serializers.
Diffstat (limited to 'app/models/follow_request.rb')
-rw-r--r--app/models/follow_request.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/app/models/follow_request.rb b/app/models/follow_request.rb
index d559a8f62..9c4875564 100644
--- a/app/models/follow_request.rb
+++ b/app/models/follow_request.rb
@@ -9,6 +9,7 @@
 #  account_id        :bigint(8)        not null
 #  target_account_id :bigint(8)        not null
 #  show_reblogs      :boolean          default(TRUE), not null
+#  uri               :string
 #
 
 class FollowRequest < ApplicationRecord
@@ -23,11 +24,22 @@ class FollowRequest < ApplicationRecord
   validates :account_id, uniqueness: { scope: :target_account_id }
 
   def authorize!
-    account.follow!(target_account, reblogs: show_reblogs)
+    account.follow!(target_account, reblogs: show_reblogs, uri: uri)
     MergeWorker.perform_async(target_account.id, account.id)
-
     destroy!
   end
 
   alias reject! destroy!
+
+  def local?
+    false # Force uri_for to use uri attribute
+  end
+
+  before_validation :set_uri, only: :create
+
+  private
+
+  def set_uri
+    self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil?
+  end
 end