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.
This commit is contained in:
parent
d1aef17f9a
commit
6793bec4c6
11 changed files with 64 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -82,16 +82,19 @@ module AccountInteractions
|
|||
has_many :domain_blocks, class_name: 'AccountDomainBlock', dependent: :destroy
|
||||
end
|
||||
|
||||
def follow!(other_account, reblogs: nil)
|
||||
def follow!(other_account, reblogs: nil, uri: nil)
|
||||
reblogs = true if reblogs.nil?
|
||||
rel = active_relationships.create_with(show_reblogs: reblogs).find_or_create_by!(target_account: other_account)
|
||||
rel.update!(show_reblogs: reblogs)
|
||||
|
||||
rel = active_relationships.create_with(show_reblogs: reblogs, uri: uri)
|
||||
.find_or_create_by!(target_account: other_account)
|
||||
|
||||
rel.update!(show_reblogs: reblogs)
|
||||
rel
|
||||
end
|
||||
|
||||
def block!(other_account)
|
||||
block_relationships.find_or_create_by!(target_account: other_account)
|
||||
def block!(other_account, uri: nil)
|
||||
block_relationships.create_with(uri: uri)
|
||||
.find_or_create_by!(target_account: other_account)
|
||||
end
|
||||
|
||||
def mute!(other_account, notifications: nil)
|
||||
|
|
|
@ -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 Follow < ApplicationRecord
|
||||
|
@ -26,4 +27,16 @@ class Follow < ApplicationRecord
|
|||
validates :account_id, uniqueness: { scope: :target_account_id }
|
||||
|
||||
scope :recent, -> { reorder(id: :desc) }
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue