mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-21 21:57:19 +00:00
[WiP] Support generating numeric ActivityPub IDs
This commit is contained in:
parent
71d15a6aea
commit
32471a0395
|
@ -38,11 +38,23 @@ class ActivityPub::TagManager
|
||||||
|
|
||||||
case target.object_type
|
case target.object_type
|
||||||
when :person
|
when :person
|
||||||
target.instance_actor? ? instance_actor_url : account_url(target)
|
if target.instance_actor?
|
||||||
|
instance_actor_url
|
||||||
|
elsif target.numeric_ap_id?
|
||||||
|
numeric_account_url(target.id)
|
||||||
|
else
|
||||||
|
account_url(target)
|
||||||
|
end
|
||||||
when :note, :comment, :activity
|
when :note, :comment, :activity
|
||||||
return activity_account_status_url(target.account, target) if target.reblog?
|
if target.account.numeric_ap_id?
|
||||||
|
return activity_numeric_account_status_url(target.account, target) if target.reblog?
|
||||||
|
|
||||||
account_status_url(target.account, target)
|
numeric_account_status_url(target.account.id, target)
|
||||||
|
else
|
||||||
|
return activity_account_status_url(target.account, target) if target.reblog?
|
||||||
|
|
||||||
|
account_status_url(target.account, target)
|
||||||
|
end
|
||||||
when :emoji
|
when :emoji
|
||||||
emoji_url(target)
|
emoji_url(target)
|
||||||
when :flag
|
when :flag
|
||||||
|
@ -58,6 +70,10 @@ class ActivityPub::TagManager
|
||||||
account_url(username: username)
|
account_url(username: username)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def uri_for_account_id(id)
|
||||||
|
numeric_account_url(id: id)
|
||||||
|
end
|
||||||
|
|
||||||
def generate_uri_for(_target)
|
def generate_uri_for(_target)
|
||||||
URI.join(root_url, 'payloads', SecureRandom.uuid)
|
URI.join(root_url, 'payloads', SecureRandom.uuid)
|
||||||
end
|
end
|
||||||
|
@ -65,49 +81,67 @@ class ActivityPub::TagManager
|
||||||
def activity_uri_for(target)
|
def activity_uri_for(target)
|
||||||
raise ArgumentError, 'target must be a local activity' unless %i(note comment activity).include?(target.object_type) && target.local?
|
raise ArgumentError, 'target must be a local activity' unless %i(note comment activity).include?(target.object_type) && target.local?
|
||||||
|
|
||||||
activity_account_status_url(target.account, target)
|
target.account.numeric_ap_id? ? activity_numeric_account_status_url(target.account.id, target) : activity_account_status_url(target.account, target)
|
||||||
end
|
end
|
||||||
|
|
||||||
def replies_uri_for(target, page_params = nil)
|
def replies_uri_for(target, page_params = nil)
|
||||||
raise ArgumentError, 'target must be a local activity' unless %i(note comment activity).include?(target.object_type) && target.local?
|
raise ArgumentError, 'target must be a local activity' unless %i(note comment activity).include?(target.object_type) && target.local?
|
||||||
|
|
||||||
account_status_replies_url(target.account, target, page_params)
|
target.account.numeric_ap_id? ? numeric_account_status_replies_url(target.account.id, target, page_params) : account_status_replies_url(target.account, target, page_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def likes_uri_for(target)
|
def likes_uri_for(target)
|
||||||
raise ArgumentError, 'target must be a local activity' unless %i(note comment activity).include?(target.object_type) && target.local?
|
raise ArgumentError, 'target must be a local activity' unless %i(note comment activity).include?(target.object_type) && target.local?
|
||||||
|
|
||||||
account_status_likes_url(target.account, target)
|
target.account.numeric_ap_id? ? numeric_account_status_likes_url(target.account.id, target) : account_status_likes_url(target.account, target)
|
||||||
end
|
end
|
||||||
|
|
||||||
def shares_uri_for(target)
|
def shares_uri_for(target)
|
||||||
raise ArgumentError, 'target must be a local activity' unless %i(note comment activity).include?(target.object_type) && target.local?
|
raise ArgumentError, 'target must be a local activity' unless %i(note comment activity).include?(target.object_type) && target.local?
|
||||||
|
|
||||||
account_status_shares_url(target.account, target)
|
target.account.numeric_ap_id? ? numeric_account_status_shares_url(target.account.id, target) : account_status_shares_url(target.account, target)
|
||||||
|
end
|
||||||
|
|
||||||
|
def following_uri_for(target, ...)
|
||||||
|
raise ArgumentError, 'target must be a local account' unless target.local?
|
||||||
|
|
||||||
|
target.numeric_ap_id? ? numeric_account_following_index_url(target.id, ...) : account_following_index_url(target, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
def followers_uri_for(target, ...)
|
def followers_uri_for(target, ...)
|
||||||
return target.followers_url.presence unless target.local?
|
return target.followers_url.presence unless target.local?
|
||||||
|
|
||||||
account_followers_url(target, ...)
|
target.numeric_ap_id? ? numeric_account_followers_url(target.id, ...) : account_followers_url(target, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
def collection_uri_for(target, ...)
|
def collection_uri_for(target, ...)
|
||||||
raise NotImplementedError unless target.local?
|
raise ArgumentError, 'target must be a local account' unless target.local?
|
||||||
|
|
||||||
account_collection_url(target, ...)
|
target.numeric_ap_id? ? numeric_account_collection_url(target.id, ...) : account_collection_url(target, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
def inbox_uri_for(target)
|
def inbox_uri_for(target)
|
||||||
raise NotImplementedError unless target.local?
|
raise ArgumentError, 'target must be a local account' unless target.local?
|
||||||
|
|
||||||
target.instance_actor? ? instance_actor_inbox_url : account_inbox_url(target)
|
if target.instance_actor?
|
||||||
|
instance_actor_inbox_url
|
||||||
|
elsif target.numeric_ap_id?
|
||||||
|
numeric_account_inbox_url(target.id)
|
||||||
|
else
|
||||||
|
account_inbox_url(target)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def outbox_uri_for(target, ...)
|
def outbox_uri_for(target, ...)
|
||||||
raise NotImplementedError unless target.local?
|
raise ArgumentError, 'target must be a local account' unless target.local?
|
||||||
|
|
||||||
target.instance_actor? ? instance_actor_outbox_url(...) : account_outbox_url(target, ...)
|
if target.instance_actor?
|
||||||
|
instance_actor_outbox_url(...)
|
||||||
|
elsif target.numeric_ap_id?
|
||||||
|
numeric_account_outbox_url(target.id, ...)
|
||||||
|
else
|
||||||
|
account_outbox_url(target, ...)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Primary audience of a status
|
# Primary audience of a status
|
||||||
|
|
|
@ -182,6 +182,11 @@ class Account < ApplicationRecord
|
||||||
|
|
||||||
update_index('accounts', :self)
|
update_index('accounts', :self)
|
||||||
|
|
||||||
|
def numeric_ap_id?
|
||||||
|
# TODO: this is a placeholder for now
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
def local?
|
def local?
|
||||||
domain.nil?
|
domain.nil?
|
||||||
end
|
end
|
||||||
|
|
|
@ -280,8 +280,10 @@ module Account::Interactions
|
||||||
def local_followers_hash
|
def local_followers_hash
|
||||||
Rails.cache.fetch("followers_hash:#{id}:local") do
|
Rails.cache.fetch("followers_hash:#{id}:local") do
|
||||||
digest = "\x00" * 32
|
digest = "\x00" * 32
|
||||||
followers.where(domain: nil).pluck_each(:username) do |username|
|
# TODO
|
||||||
Xorcist.xor!(digest, Digest::SHA256.digest(ActivityPub::TagManager.instance.uri_for_username(username)))
|
followers.where(domain: nil).pluck_each('false as numeric_ap_id', :id, :username) do |numeric_ap_id, id, username|
|
||||||
|
uri = numeric_ap_id ? ActivityPub::TagManager.instance.uri_for_account_id(id) : ActivityPub::TagManager.instance.uri_for_username(username)
|
||||||
|
Xorcist.xor!(digest, Digest::SHA256.digest(uri))
|
||||||
end
|
end
|
||||||
digest.unpack1('H*')
|
digest.unpack1('H*')
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue