mirror of
https://github.com/mastodon/mastodon.git
synced 2025-10-05 16:42:47 +00:00
Add support for numeric-based URIs for local accounts (#32724)
Some checks failed
Bundler Audit / security (push) Waiting to run
Check i18n / check-i18n (push) Waiting to run
Chromatic / Run Chromatic (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.2) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
CSS Linting / lint (push) Has been cancelled
Some checks failed
Bundler Audit / security (push) Waiting to run
Check i18n / check-i18n (push) Waiting to run
Chromatic / Run Chromatic (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.2) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
CSS Linting / lint (push) Has been cancelled
This commit is contained in:
parent
4d7c208da3
commit
150f0fcba5
|
@ -71,6 +71,10 @@ class AccountsController < ApplicationController
|
||||||
params[:username]
|
params[:username]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def account_id_param
|
||||||
|
params[:id]
|
||||||
|
end
|
||||||
|
|
||||||
def skip_temporary_suspension_response?
|
def skip_temporary_suspension_response?
|
||||||
request.format == :json
|
request.format == :json
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,7 +28,7 @@ class ActivityPub::LikesController < ActivityPub::BaseController
|
||||||
|
|
||||||
def likes_collection_presenter
|
def likes_collection_presenter
|
||||||
ActivityPub::CollectionPresenter.new(
|
ActivityPub::CollectionPresenter.new(
|
||||||
id: account_status_likes_url(@account, @status),
|
id: ActivityPub::TagManager.instance.likes_uri_for(@status),
|
||||||
type: :unordered,
|
type: :unordered,
|
||||||
size: @status.favourites_count
|
size: @status.favourites_count
|
||||||
)
|
)
|
||||||
|
|
|
@ -73,6 +73,8 @@ class ActivityPub::OutboxesController < ActivityPub::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_account
|
def set_account
|
||||||
@account = params[:account_username].present? ? Account.find_local!(username_param) : Account.representative
|
return super if params[:account_username].present? || params[:account_id].present?
|
||||||
|
|
||||||
|
@account = Account.representative
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,7 +37,7 @@ class ActivityPub::RepliesController < ActivityPub::BaseController
|
||||||
|
|
||||||
def replies_collection_presenter
|
def replies_collection_presenter
|
||||||
page = ActivityPub::CollectionPresenter.new(
|
page = ActivityPub::CollectionPresenter.new(
|
||||||
id: account_status_replies_url(@account, @status, page_params),
|
id: ActivityPub::TagManager.instance.replies_uri_for(@status, page_params),
|
||||||
type: :unordered,
|
type: :unordered,
|
||||||
part_of: account_status_replies_url(@account, @status),
|
part_of: account_status_replies_url(@account, @status),
|
||||||
next: next_page,
|
next: next_page,
|
||||||
|
@ -47,7 +47,7 @@ class ActivityPub::RepliesController < ActivityPub::BaseController
|
||||||
return page if page_requested?
|
return page if page_requested?
|
||||||
|
|
||||||
ActivityPub::CollectionPresenter.new(
|
ActivityPub::CollectionPresenter.new(
|
||||||
id: account_status_replies_url(@account, @status),
|
id: ActivityPub::TagManager.instance.replies_uri_for(@status),
|
||||||
type: :unordered,
|
type: :unordered,
|
||||||
first: page
|
first: page
|
||||||
)
|
)
|
||||||
|
@ -66,8 +66,7 @@ class ActivityPub::RepliesController < ActivityPub::BaseController
|
||||||
# Only consider remote accounts
|
# Only consider remote accounts
|
||||||
return nil if @replies.size < DESCENDANTS_LIMIT
|
return nil if @replies.size < DESCENDANTS_LIMIT
|
||||||
|
|
||||||
account_status_replies_url(
|
ActivityPub::TagManager.instance.replies_uri_for(
|
||||||
@account,
|
|
||||||
@status,
|
@status,
|
||||||
page: true,
|
page: true,
|
||||||
min_id: @replies&.last&.id,
|
min_id: @replies&.last&.id,
|
||||||
|
@ -77,8 +76,7 @@ class ActivityPub::RepliesController < ActivityPub::BaseController
|
||||||
# For now, we're serving only self-replies, but next page might be other accounts
|
# For now, we're serving only self-replies, but next page might be other accounts
|
||||||
next_only_other_accounts = @replies&.last&.account_id != @account.id || @replies.size < DESCENDANTS_LIMIT
|
next_only_other_accounts = @replies&.last&.account_id != @account.id || @replies.size < DESCENDANTS_LIMIT
|
||||||
|
|
||||||
account_status_replies_url(
|
ActivityPub::TagManager.instance.replies_uri_for(
|
||||||
@account,
|
|
||||||
@status,
|
@status,
|
||||||
page: true,
|
page: true,
|
||||||
min_id: next_only_other_accounts ? nil : @replies&.last&.id,
|
min_id: next_only_other_accounts ? nil : @replies&.last&.id,
|
||||||
|
|
|
@ -28,7 +28,7 @@ class ActivityPub::SharesController < ActivityPub::BaseController
|
||||||
|
|
||||||
def shares_collection_presenter
|
def shares_collection_presenter
|
||||||
ActivityPub::CollectionPresenter.new(
|
ActivityPub::CollectionPresenter.new(
|
||||||
id: account_status_shares_url(@account, @status),
|
id: ActivityPub::TagManager.instance.shares_uri_for(@status),
|
||||||
type: :unordered,
|
type: :unordered,
|
||||||
size: @status.reblogs_count
|
size: @status.reblogs_count
|
||||||
)
|
)
|
||||||
|
|
|
@ -18,7 +18,11 @@ module AccountOwnedConcern
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_account
|
def set_account
|
||||||
@account = Account.find_local!(username_param)
|
@account = username_param.present? ? Account.find_local!(username_param) : Account.local.find(account_id_param)
|
||||||
|
end
|
||||||
|
|
||||||
|
def account_id_param
|
||||||
|
params[:account_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
def username_param
|
def username_param
|
||||||
|
|
|
@ -60,17 +60,17 @@ class FollowerAccountsController < ApplicationController
|
||||||
def collection_presenter
|
def collection_presenter
|
||||||
if page_requested?
|
if page_requested?
|
||||||
ActivityPub::CollectionPresenter.new(
|
ActivityPub::CollectionPresenter.new(
|
||||||
id: account_followers_url(@account, page: params.fetch(:page, 1)),
|
id: page_url(params.fetch(:page, 1)),
|
||||||
type: :ordered,
|
type: :ordered,
|
||||||
size: @account.followers_count,
|
size: @account.followers_count,
|
||||||
items: follows.map { |follow| ActivityPub::TagManager.instance.uri_for(follow.account) },
|
items: follows.map { |follow| ActivityPub::TagManager.instance.uri_for(follow.account) },
|
||||||
part_of: account_followers_url(@account),
|
part_of: ActivityPub::TagManager.instance.followers_uri_for(@account),
|
||||||
next: next_page_url,
|
next: next_page_url,
|
||||||
prev: prev_page_url
|
prev: prev_page_url
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
ActivityPub::CollectionPresenter.new(
|
ActivityPub::CollectionPresenter.new(
|
||||||
id: account_followers_url(@account),
|
id: ActivityPub::TagManager.instance.followers_uri_for(@account),
|
||||||
type: :ordered,
|
type: :ordered,
|
||||||
size: @account.followers_count,
|
size: @account.followers_count,
|
||||||
first: page_url(1)
|
first: page_url(1)
|
||||||
|
|
|
@ -49,7 +49,7 @@ class FollowingAccountsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def page_url(page)
|
def page_url(page)
|
||||||
account_following_index_url(@account, page: page) unless page.nil?
|
ActivityPub::TagManager.instance.following_uri_for(@account, page: page) unless page.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def next_page_url
|
def next_page_url
|
||||||
|
@ -63,17 +63,17 @@ class FollowingAccountsController < ApplicationController
|
||||||
def collection_presenter
|
def collection_presenter
|
||||||
if page_requested?
|
if page_requested?
|
||||||
ActivityPub::CollectionPresenter.new(
|
ActivityPub::CollectionPresenter.new(
|
||||||
id: account_following_index_url(@account, page: params.fetch(:page, 1)),
|
id: page_url(params.fetch(:page, 1)),
|
||||||
type: :ordered,
|
type: :ordered,
|
||||||
size: @account.following_count,
|
size: @account.following_count,
|
||||||
items: follows.map { |follow| ActivityPub::TagManager.instance.uri_for(follow.target_account) },
|
items: follows.map { |follow| ActivityPub::TagManager.instance.uri_for(follow.target_account) },
|
||||||
part_of: account_following_index_url(@account),
|
part_of: ActivityPub::TagManager.instance.following_uri_for(@account),
|
||||||
next: next_page_url,
|
next: next_page_url,
|
||||||
prev: prev_page_url
|
prev: prev_page_url
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
ActivityPub::CollectionPresenter.new(
|
ActivityPub::CollectionPresenter.new(
|
||||||
id: account_following_index_url(@account),
|
id: ActivityPub::TagManager.instance.following_uri_for(@account),
|
||||||
type: :ordered,
|
type: :ordered,
|
||||||
size: @account.following_count,
|
size: @account.following_count,
|
||||||
first: page_url(1)
|
first: page_url(1)
|
||||||
|
|
|
@ -39,13 +39,25 @@ 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?
|
||||||
|
ap_account_url(target.id)
|
||||||
|
else
|
||||||
|
account_url(target)
|
||||||
|
end
|
||||||
when :conversation
|
when :conversation
|
||||||
context_url(target) unless target.parent_account_id.nil? || target.parent_status_id.nil?
|
context_url(target) unless target.parent_account_id.nil? || target.parent_status_id.nil?
|
||||||
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_ap_account_status_url(target.account, target) if target.reblog?
|
||||||
|
|
||||||
account_status_url(target.account, target)
|
ap_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
|
||||||
|
@ -57,7 +69,7 @@ class ActivityPub::TagManager
|
||||||
return quote.approval_uri unless quote.quoted_account&.local?
|
return quote.approval_uri unless quote.quoted_account&.local?
|
||||||
return if check_approval && !quote.accepted?
|
return if check_approval && !quote.accepted?
|
||||||
|
|
||||||
account_quote_authorization_url(quote.quoted_account, quote)
|
quote.quoted_account.numeric_ap_id? ? ap_account_quote_authorization_url(quote.quoted_account_id, quote) : account_quote_authorization_url(quote.quoted_account, quote)
|
||||||
end
|
end
|
||||||
|
|
||||||
def key_uri_for(target)
|
def key_uri_for(target)
|
||||||
|
@ -68,6 +80,10 @@ class ActivityPub::TagManager
|
||||||
account_url(username: username)
|
account_url(username: username)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def uri_for_account_id(id)
|
||||||
|
ap_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
|
||||||
|
@ -75,7 +91,7 @@ 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_ap_account_status_url(target.account.id, target) : activity_account_status_url(target.account, target)
|
||||||
end
|
end
|
||||||
|
|
||||||
def context_uri_for(target, page_params = nil)
|
def context_uri_for(target, page_params = nil)
|
||||||
|
@ -87,49 +103,61 @@ class ActivityPub::TagManager
|
||||||
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? ? ap_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? ? ap_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? ? ap_account_status_shares_url(target.account.id, target) : account_status_shares_url(target.account, target)
|
||||||
end
|
end
|
||||||
|
|
||||||
def following_uri_for(target, ...)
|
def following_uri_for(target, ...)
|
||||||
raise ArgumentError, 'target must be a local account' unless target.local?
|
raise ArgumentError, 'target must be a local account' unless target.local?
|
||||||
|
|
||||||
account_following_index_url(target, ...)
|
target.numeric_ap_id? ? ap_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? ? ap_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? ? ap_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?
|
||||||
|
ap_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?
|
||||||
|
ap_account_outbox_url(target.id, ...)
|
||||||
|
else
|
||||||
|
account_outbox_url(target, ...)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Primary audience of a status
|
# Primary audience of a status
|
||||||
|
@ -262,10 +290,9 @@ class ActivityPub::TagManager
|
||||||
|
|
||||||
path_params = Rails.application.routes.recognize_path(uri)
|
path_params = Rails.application.routes.recognize_path(uri)
|
||||||
|
|
||||||
# TODO: handle numeric IDs
|
|
||||||
case path_params[:controller]
|
case path_params[:controller]
|
||||||
when 'accounts'
|
when 'accounts'
|
||||||
[:username, path_params[:username]]
|
path_params.key?(:username) ? [:username, path_params[:username]] : [:id, path_params[:id]]
|
||||||
when 'instance_actors'
|
when 'instance_actors'
|
||||||
[:id, -99]
|
[:id, -99]
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
# requested_review_at :datetime
|
# requested_review_at :datetime
|
||||||
# indexable :boolean default(FALSE), not null
|
# indexable :boolean default(FALSE), not null
|
||||||
# attribution_domains :string default([]), is an Array
|
# attribution_domains :string default([]), is an Array
|
||||||
|
# id_scheme :integer default("username_ap_id")
|
||||||
#
|
#
|
||||||
|
|
||||||
class Account < ApplicationRecord
|
class Account < ApplicationRecord
|
||||||
|
@ -105,6 +106,7 @@ class Account < ApplicationRecord
|
||||||
|
|
||||||
enum :protocol, { ostatus: 0, activitypub: 1 }
|
enum :protocol, { ostatus: 0, activitypub: 1 }
|
||||||
enum :suspension_origin, { local: 0, remote: 1 }, prefix: true
|
enum :suspension_origin, { local: 0, remote: 1 }, prefix: true
|
||||||
|
enum :id_scheme, { username_ap_id: 0, numeric_ap_id: 1 }
|
||||||
|
|
||||||
validates :username, presence: true
|
validates :username, presence: true
|
||||||
validates_with UniqueUsernameValidator, if: -> { will_save_change_to_username? }
|
validates_with UniqueUsernameValidator, if: -> { will_save_change_to_username? }
|
||||||
|
|
|
@ -215,8 +215,9 @@ 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|
|
followers.where(domain: nil).pluck_each(:id_scheme, :id, :username) do |id_scheme, id, username|
|
||||||
Xorcist.xor!(digest, Digest::SHA256.digest(ActivityPub::TagManager.instance.uri_for_username(username)))
|
uri = id_scheme == '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
|
||||||
|
|
|
@ -55,7 +55,7 @@ class ActivityPub::DeliveryWorker
|
||||||
end
|
end
|
||||||
|
|
||||||
def synchronization_header
|
def synchronization_header
|
||||||
"collectionId=\"#{account_followers_url(@source_account)}\", digest=\"#{@source_account.remote_followers_hash(@inbox_url)}\", url=\"#{account_followers_synchronization_url(@source_account)}\""
|
"collectionId=\"#{ActivityPub::TagManager.instance.followers_uri_for(@source_account)}\", digest=\"#{@source_account.remote_followers_hash(@inbox_url)}\", url=\"#{account_followers_synchronization_url(@source_account)}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_request
|
def perform_request
|
||||||
|
|
|
@ -95,7 +95,20 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
get '/authorize_follow', to: redirect { |_, request| "/authorize_interaction?#{request.params.to_query}" }
|
get '/authorize_follow', to: redirect { |_, request| "/authorize_interaction?#{request.params.to_query}" }
|
||||||
|
|
||||||
resources :accounts, path: 'users', only: [:show], param: :username do
|
concern :account_resources do
|
||||||
|
resources :followers, only: [:index], controller: :follower_accounts
|
||||||
|
resources :following, only: [:index], controller: :following_accounts
|
||||||
|
|
||||||
|
scope module: :activitypub do
|
||||||
|
resource :outbox, only: [:show]
|
||||||
|
resource :inbox, only: [:create]
|
||||||
|
resources :collections, only: [:show]
|
||||||
|
resource :followers_synchronization, only: [:show]
|
||||||
|
resources :quote_authorizations, only: [:show]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
resources :accounts, path: 'users', only: [:show], param: :username, concerns: :account_resources do
|
||||||
resources :statuses, only: [:show] do
|
resources :statuses, only: [:show] do
|
||||||
member do
|
member do
|
||||||
get :activity
|
get :activity
|
||||||
|
@ -106,16 +119,19 @@ Rails.application.routes.draw do
|
||||||
resources :likes, only: [:index], module: :activitypub
|
resources :likes, only: [:index], module: :activitypub
|
||||||
resources :shares, only: [:index], module: :activitypub
|
resources :shares, only: [:index], module: :activitypub
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
resources :followers, only: [:index], controller: :follower_accounts
|
scope path: 'ap', as: 'ap' do
|
||||||
resources :following, only: [:index], controller: :following_accounts
|
resources :accounts, path: 'users', only: [:show], param: :id, concerns: :account_resources do
|
||||||
|
resources :statuses, module: :activitypub, only: [:show] do
|
||||||
|
member do
|
||||||
|
get :activity
|
||||||
|
end
|
||||||
|
|
||||||
scope module: :activitypub do
|
resources :replies, only: [:index]
|
||||||
resource :outbox, only: [:show]
|
resources :likes, only: [:index]
|
||||||
resource :inbox, only: [:create]
|
resources :shares, only: [:index]
|
||||||
resources :collections, only: [:show]
|
end
|
||||||
resource :followers_synchronization, only: [:show]
|
|
||||||
resources :quote_authorizations, only: [:show]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
7
db/migrate/20250924170259_add_id_scheme_to_accounts.rb
Normal file
7
db/migrate/20250924170259_add_id_scheme_to_accounts.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddIdSchemeToAccounts < ActiveRecord::Migration[8.0]
|
||||||
|
def change
|
||||||
|
add_column :accounts, :id_scheme, :integer, default: 0
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2025_09_12_082651) do
|
ActiveRecord::Schema[8.0].define(version: 2025_09_24_170259) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pg_catalog.plpgsql"
|
enable_extension "pg_catalog.plpgsql"
|
||||||
|
|
||||||
|
@ -199,6 +199,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_12_082651) do
|
||||||
t.boolean "indexable", default: false, null: false
|
t.boolean "indexable", default: false, null: false
|
||||||
t.string "attribution_domains", default: [], array: true
|
t.string "attribution_domains", default: [], array: true
|
||||||
t.string "following_url", default: "", null: false
|
t.string "following_url", default: "", null: false
|
||||||
|
t.integer "id_scheme", default: 0
|
||||||
t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
|
t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
|
||||||
t.index "lower((username)::text), COALESCE(lower((domain)::text), ''::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
|
t.index "lower((username)::text), COALESCE(lower((domain)::text), ''::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
|
||||||
t.index ["domain", "id"], name: "index_accounts_on_domain_and_id"
|
t.index ["domain", "id"], name: "index_accounts_on_domain_and_id"
|
||||||
|
|
|
@ -29,6 +29,15 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.url_for(account))
|
expect(subject.url_for(account))
|
||||||
.to eq("#{host_prefix}/@#{account.username}")
|
.to eq("#{host_prefix}/@#{account.username}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
|
||||||
|
it 'returns a string starting with web domain and with the expected path' do
|
||||||
|
expect(subject.url_for(account))
|
||||||
|
.to eq("#{host_prefix}/@#{account.username}")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a remote account' do
|
context 'with a remote account' do
|
||||||
|
@ -46,6 +55,16 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.url_for(status))
|
expect(subject.url_for(status))
|
||||||
.to eq("#{host_prefix}/@#{status.account.username}/#{status.id}")
|
.to eq("#{host_prefix}/@#{status.account.username}/#{status.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
let(:status) { Fabricate(:status, account: account) }
|
||||||
|
|
||||||
|
it 'returns a string starting with web domain and with the expected path' do
|
||||||
|
expect(subject.url_for(status))
|
||||||
|
.to eq("#{host_prefix}/@#{status.account.username}/#{status.id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a remote status' do
|
context 'with a remote status' do
|
||||||
|
@ -73,6 +92,15 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.uri_for(account))
|
expect(subject.uri_for(account))
|
||||||
.to eq("#{host_prefix}/users/#{account.username}")
|
.to eq("#{host_prefix}/users/#{account.username}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
|
||||||
|
it 'returns a string starting with web domain and with the expected path' do
|
||||||
|
expect(subject.uri_for(account))
|
||||||
|
.to eq("#{host_prefix}/ap/users/#{account.id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a remote account' do
|
context 'with a remote account' do
|
||||||
|
@ -90,6 +118,16 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.uri_for(status))
|
expect(subject.uri_for(status))
|
||||||
.to eq("#{host_prefix}/users/#{status.account.username}/statuses/#{status.id}")
|
.to eq("#{host_prefix}/users/#{status.account.username}/statuses/#{status.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
let(:status) { Fabricate(:status, account: account) }
|
||||||
|
|
||||||
|
it 'returns a string starting with web domain and with the expected path' do
|
||||||
|
expect(subject.uri_for(status))
|
||||||
|
.to eq("#{host_prefix}/ap/users/#{status.account.id}/statuses/#{status.id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a remote status' do
|
context 'with a remote status' do
|
||||||
|
@ -108,6 +146,16 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.uri_for(status.conversation))
|
expect(subject.uri_for(status.conversation))
|
||||||
.to eq("#{host_prefix}/contexts/#{status.account.id}-#{status.id}")
|
.to eq("#{host_prefix}/contexts/#{status.account.id}-#{status.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
let(:status) { Fabricate(:status, account: account) }
|
||||||
|
|
||||||
|
it 'returns a string starting with web domain and with the expected path' do
|
||||||
|
expect(subject.uri_for(status.conversation))
|
||||||
|
.to eq("#{host_prefix}/contexts/#{status.account.id}-#{status.id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a remote conversation' do
|
context 'with a remote conversation' do
|
||||||
|
@ -139,6 +187,15 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.key_uri_for(account))
|
expect(subject.key_uri_for(account))
|
||||||
.to eq("#{host_prefix}/users/#{account.username}#main-key")
|
.to eq("#{host_prefix}/users/#{account.username}#main-key")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
|
||||||
|
it 'returns a string starting with web domain and with the expected path' do
|
||||||
|
expect(subject.key_uri_for(account))
|
||||||
|
.to eq("#{host_prefix}/ap/users/#{account.id}#main-key")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -167,6 +224,17 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.approval_uri_for(quote))
|
expect(subject.approval_uri_for(quote))
|
||||||
.to eq("#{host_prefix}/users/#{quote.quoted_account.username}/quote_authorizations/#{quote.id}")
|
.to eq("#{host_prefix}/users/#{quote.quoted_account.username}/quote_authorizations/#{quote.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:quoted_account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
let(:quoted_status) { Fabricate(:status, account: quoted_account) }
|
||||||
|
let(:quote) { Fabricate(:quote, state: :accepted, quoted_status: quoted_status) }
|
||||||
|
|
||||||
|
it 'returns a string with the web domain and expected path' do
|
||||||
|
expect(subject.approval_uri_for(quote))
|
||||||
|
.to eq("#{host_prefix}/ap/users/#{quote.quoted_account_id}/quote_authorizations/#{quote.id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with an unapproved local quote' do
|
context 'with an unapproved local quote' do
|
||||||
|
@ -176,6 +244,17 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.approval_uri_for(quote))
|
expect(subject.approval_uri_for(quote))
|
||||||
.to be_nil
|
.to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:quoted_account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
let(:quoted_status) { Fabricate(:status, account: quoted_account) }
|
||||||
|
let(:quote) { Fabricate(:quote, state: :rejected, quoted_status: quoted_status) }
|
||||||
|
|
||||||
|
it 'returns nil' do
|
||||||
|
expect(subject.approval_uri_for(quote))
|
||||||
|
.to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a valid remote approval' do
|
context 'with a valid remote approval' do
|
||||||
|
@ -195,6 +274,17 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.approval_uri_for(quote, check_approval: false))
|
expect(subject.approval_uri_for(quote, check_approval: false))
|
||||||
.to eq("#{host_prefix}/users/#{quote.quoted_account.username}/quote_authorizations/#{quote.id}")
|
.to eq("#{host_prefix}/users/#{quote.quoted_account.username}/quote_authorizations/#{quote.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:quoted_account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
let(:quoted_status) { Fabricate(:status, account: quoted_account) }
|
||||||
|
let(:quote) { Fabricate(:quote, state: :rejected, quoted_status: quoted_status) }
|
||||||
|
|
||||||
|
it 'returns a string with the web domain and expected path' do
|
||||||
|
expect(subject.approval_uri_for(quote, check_approval: false))
|
||||||
|
.to eq("#{host_prefix}/ap/users/#{quote.quoted_account_id}/quote_authorizations/#{quote.id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -206,6 +296,16 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.replies_uri_for(status))
|
expect(subject.replies_uri_for(status))
|
||||||
.to eq("#{host_prefix}/users/#{status.account.username}/statuses/#{status.id}/replies")
|
.to eq("#{host_prefix}/users/#{status.account.username}/statuses/#{status.id}/replies")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
let(:status) { Fabricate(:status, account: account) }
|
||||||
|
|
||||||
|
it 'returns a string starting with web domain and with the expected path' do
|
||||||
|
expect(subject.replies_uri_for(status))
|
||||||
|
.to eq("#{host_prefix}/ap/users/#{status.account.id}/statuses/#{status.id}/replies")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -217,6 +317,16 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.likes_uri_for(status))
|
expect(subject.likes_uri_for(status))
|
||||||
.to eq("#{host_prefix}/users/#{status.account.username}/statuses/#{status.id}/likes")
|
.to eq("#{host_prefix}/users/#{status.account.username}/statuses/#{status.id}/likes")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
let(:status) { Fabricate(:status, account: account) }
|
||||||
|
|
||||||
|
it 'returns a string starting with web domain and with the expected path' do
|
||||||
|
expect(subject.likes_uri_for(status))
|
||||||
|
.to eq("#{host_prefix}/ap/users/#{status.account.id}/statuses/#{status.id}/likes")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -228,6 +338,16 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.shares_uri_for(status))
|
expect(subject.shares_uri_for(status))
|
||||||
.to eq("#{host_prefix}/users/#{status.account.username}/statuses/#{status.id}/shares")
|
.to eq("#{host_prefix}/users/#{status.account.username}/statuses/#{status.id}/shares")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
let(:status) { Fabricate(:status, account: account) }
|
||||||
|
|
||||||
|
it 'returns a string starting with web domain and with the expected path' do
|
||||||
|
expect(subject.shares_uri_for(status))
|
||||||
|
.to eq("#{host_prefix}/ap/users/#{status.account.id}/statuses/#{status.id}/shares")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -239,6 +359,15 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.following_uri_for(account))
|
expect(subject.following_uri_for(account))
|
||||||
.to eq("#{host_prefix}/users/#{account.username}/following")
|
.to eq("#{host_prefix}/users/#{account.username}/following")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
|
||||||
|
it 'returns a string starting with web domain and with the expected path' do
|
||||||
|
expect(subject.following_uri_for(account))
|
||||||
|
.to eq("#{host_prefix}/ap/users/#{account.id}/following")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -250,6 +379,15 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.followers_uri_for(account))
|
expect(subject.followers_uri_for(account))
|
||||||
.to eq("#{host_prefix}/users/#{account.username}/followers")
|
.to eq("#{host_prefix}/users/#{account.username}/followers")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
|
||||||
|
it 'returns a string starting with web domain and with the expected path' do
|
||||||
|
expect(subject.followers_uri_for(account))
|
||||||
|
.to eq("#{host_prefix}/ap/users/#{account.id}/followers")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -268,6 +406,15 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.inbox_uri_for(account))
|
expect(subject.inbox_uri_for(account))
|
||||||
.to eq("#{host_prefix}/users/#{account.username}/inbox")
|
.to eq("#{host_prefix}/users/#{account.username}/inbox")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
|
||||||
|
it 'returns a string starting with web domain and with the expected path' do
|
||||||
|
expect(subject.inbox_uri_for(account))
|
||||||
|
.to eq("#{host_prefix}/ap/users/#{account.id}/inbox")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -286,6 +433,15 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.outbox_uri_for(account))
|
expect(subject.outbox_uri_for(account))
|
||||||
.to eq("#{host_prefix}/users/#{account.username}/outbox")
|
.to eq("#{host_prefix}/users/#{account.username}/outbox")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:account) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
|
||||||
|
it 'returns a string starting with web domain and with the expected path' do
|
||||||
|
expect(subject.outbox_uri_for(account))
|
||||||
|
.to eq("#{host_prefix}/ap/users/#{account.id}/outbox")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -300,16 +456,28 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.to(status)).to eq [account_followers_url(status.account)]
|
expect(subject.to(status)).to eq [account_followers_url(status.account)]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns followers collection for unlisted status when using a numeric ID based scheme' do
|
||||||
|
status = Fabricate(:status, visibility: :unlisted, account: Fabricate(:account, id_scheme: :numeric_ap_id))
|
||||||
|
expect(subject.to(status)).to eq [ap_account_followers_url(status.account_id)]
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns followers collection for private status' do
|
it 'returns followers collection for private status' do
|
||||||
status = Fabricate(:status, visibility: :private)
|
status = Fabricate(:status, visibility: :private)
|
||||||
expect(subject.to(status)).to eq [account_followers_url(status.account)]
|
expect(subject.to(status)).to eq [account_followers_url(status.account)]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns followers collection for private status when using a numeric ID based scheme' do
|
||||||
|
status = Fabricate(:status, visibility: :private, account: Fabricate(:account, id_scheme: :numeric_ap_id))
|
||||||
|
expect(subject.to(status)).to eq [ap_account_followers_url(status.account_id)]
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns URIs of mentions for direct status' do
|
it 'returns URIs of mentions for direct status' do
|
||||||
status = Fabricate(:status, visibility: :direct)
|
status = Fabricate(:status, visibility: :direct)
|
||||||
mentioned = Fabricate(:account)
|
mentioned = Fabricate(:account)
|
||||||
|
mentioned_numeric = Fabricate(:account, id_scheme: :numeric_ap_id)
|
||||||
status.mentions.create(account: mentioned)
|
status.mentions.create(account: mentioned)
|
||||||
expect(subject.to(status)).to eq [subject.uri_for(mentioned)]
|
status.mentions.create(account: mentioned_numeric)
|
||||||
|
expect(subject.to(status)).to eq [subject.uri_for(mentioned), subject.uri_for(mentioned_numeric)]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns URIs of mentioned group's followers for direct statuses to groups" do
|
it "returns URIs of mentioned group's followers for direct statuses to groups" do
|
||||||
|
@ -350,6 +518,11 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
expect(subject.cc(status)).to eq [account_followers_url(status.account)]
|
expect(subject.cc(status)).to eq [account_followers_url(status.account)]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns followers collection for public status when using a numeric ID based scheme' do
|
||||||
|
status = Fabricate(:status, visibility: :public, account: Fabricate(:account, id_scheme: :numeric_ap_id))
|
||||||
|
expect(subject.cc(status)).to eq [ap_account_followers_url(status.account_id)]
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns public collection for unlisted status' do
|
it 'returns public collection for unlisted status' do
|
||||||
status = Fabricate(:status, visibility: :unlisted)
|
status = Fabricate(:status, visibility: :unlisted)
|
||||||
expect(subject.cc(status)).to eq ['https://www.w3.org/ns/activitystreams#Public']
|
expect(subject.cc(status)).to eq ['https://www.w3.org/ns/activitystreams#Public']
|
||||||
|
@ -368,8 +541,10 @@ RSpec.describe ActivityPub::TagManager do
|
||||||
it 'returns URIs of mentions for non-direct status' do
|
it 'returns URIs of mentions for non-direct status' do
|
||||||
status = Fabricate(:status, visibility: :public)
|
status = Fabricate(:status, visibility: :public)
|
||||||
mentioned = Fabricate(:account)
|
mentioned = Fabricate(:account)
|
||||||
|
mentioned_numeric = Fabricate(:account, id_scheme: :numeric_ap_id)
|
||||||
status.mentions.create(account: mentioned)
|
status.mentions.create(account: mentioned)
|
||||||
expect(subject.cc(status)).to include(subject.uri_for(mentioned))
|
status.mentions.create(account: mentioned_numeric)
|
||||||
|
expect(subject.cc(status)).to include(subject.uri_for(mentioned), subject.uri_for(mentioned_numeric))
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with followers and requested followers' do
|
context 'with followers and requested followers' do
|
||||||
|
|
|
@ -563,6 +563,22 @@ RSpec.describe Account::Interactions do
|
||||||
me.follow!(remote_alice)
|
me.follow!(remote_alice)
|
||||||
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using numeric ID based scheme' do
|
||||||
|
let(:me) { Fabricate(:account, username: 'Me', id_scheme: :numeric_ap_id) }
|
||||||
|
|
||||||
|
it 'returns correct hash for local users' do
|
||||||
|
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'invalidates cache as needed when removing or adding followers' do
|
||||||
|
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
||||||
|
me.unfollow!(remote_alice)
|
||||||
|
expect(remote_alice.local_followers_hash).to eq '0000000000000000000000000000000000000000000000000000000000000000'
|
||||||
|
me.follow!(remote_alice)
|
||||||
|
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'muting an account' do
|
describe 'muting an account' do
|
||||||
|
|
|
@ -5,6 +5,14 @@ require 'rails_helper'
|
||||||
RSpec.describe 'Accounts show response' do
|
RSpec.describe 'Accounts show response' do
|
||||||
let(:account) { Fabricate(:account) }
|
let(:account) { Fabricate(:account) }
|
||||||
|
|
||||||
|
context 'with numeric-based identifiers' do
|
||||||
|
it 'returns http success' do
|
||||||
|
get "/ap/users/#{account.id}"
|
||||||
|
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'with an unapproved account' do
|
context 'with an unapproved account' do
|
||||||
before { account.user.update(approved: false) }
|
before { account.user.update(approved: false) }
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ RSpec.describe ActivityPub::SynchronizeFollowersService do
|
||||||
subject { described_class.new }
|
subject { described_class.new }
|
||||||
|
|
||||||
let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account', inbox_url: 'http://example.com/inbox') }
|
let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account', inbox_url: 'http://example.com/inbox') }
|
||||||
let(:alice) { Fabricate(:account, username: 'alice') }
|
let(:alice) { Fabricate(:account, username: 'alice', id_scheme: :numeric_ap_id) }
|
||||||
let(:bob) { Fabricate(:account, username: 'bob') }
|
let(:bob) { Fabricate(:account, username: 'bob') }
|
||||||
let(:eve) { Fabricate(:account, username: 'eve') }
|
let(:eve) { Fabricate(:account, username: 'eve') }
|
||||||
let(:mallory) { Fabricate(:account, username: 'mallory') }
|
let(:mallory) { Fabricate(:account, username: 'mallory') }
|
||||||
|
|
|
@ -25,12 +25,23 @@ RSpec.describe ActivityPub::DeliveryWorker do
|
||||||
.to have_been_made.once
|
.to have_been_made.once
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using a numeric ID based scheme' do
|
||||||
|
let(:sender) { Fabricate(:account, id_scheme: :numeric_ap_id) }
|
||||||
|
|
||||||
|
it 'performs a request to synchronize collection' do
|
||||||
|
subject.perform(payload, sender.id, url, { synchronize_followers: true })
|
||||||
|
|
||||||
|
expect(request_to_url)
|
||||||
|
.to have_been_made.once
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def request_to_url
|
def request_to_url
|
||||||
a_request(:post, url)
|
a_request(:post, url)
|
||||||
.with(
|
.with(
|
||||||
headers: {
|
headers: {
|
||||||
'Collection-Synchronization' => <<~VALUES.squish,
|
'Collection-Synchronization' => <<~VALUES.squish,
|
||||||
collectionId="#{account_followers_url(sender)}", digest="somehash", url="#{account_followers_synchronization_url(sender)}"
|
collectionId="#{ActivityPub::TagManager.instance.followers_uri_for(sender)}", digest="somehash", url="#{account_followers_synchronization_url(sender)}"
|
||||||
VALUES
|
VALUES
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user