about summary refs log tree commit diff
path: root/app/models/block.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/block.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/block.rb')
-rw-r--r--app/models/block.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/app/models/block.rb b/app/models/block.rb
index df4a6bbac..bf3e07600 100644
--- a/app/models/block.rb
+++ b/app/models/block.rb
@@ -8,6 +8,7 @@
 #  updated_at        :datetime         not null
 #  account_id        :bigint(8)        not null
 #  target_account_id :bigint(8)        not null
+#  uri               :string
 #
 
 class Block < ApplicationRecord
@@ -19,7 +20,12 @@ class Block < ApplicationRecord
 
   validates :account_id, uniqueness: { scope: :target_account_id }
 
+  def local?
+    false # Force uri_for to use uri attribute
+  end
+
   after_commit :remove_blocking_cache
+  before_validation :set_uri, only: :create
 
   private
 
@@ -27,4 +33,8 @@ class Block < ApplicationRecord
     Rails.cache.delete("exclude_account_ids_for:#{account_id}")
     Rails.cache.delete("exclude_account_ids_for:#{target_account_id}")
   end
+
+  def set_uri
+    self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil?
+  end
 end