Merge remote-tracking branch 'parent/main' into upstream-20250403
This commit is contained in:
commit
32f5604499
265 changed files with 6227 additions and 3383 deletions
|
@ -130,12 +130,7 @@ class ActivityPub::Activity
|
|||
|
||||
def first_mentioned_local_account
|
||||
audience = (as_array(@json['to']) + as_array(@json['cc'])).map { |x| value_or_id(x) }.uniq
|
||||
local_usernames = audience.select { |uri| ActivityPub::TagManager.instance.local_uri?(uri) }
|
||||
.map { |uri| ActivityPub::TagManager.instance.uri_to_local_id(uri, :username) }
|
||||
|
||||
return if local_usernames.empty?
|
||||
|
||||
Account.local.where(username: local_usernames).first
|
||||
ActivityPub::TagManager.instance.uris_to_local_accounts(audience).first
|
||||
end
|
||||
|
||||
def first_local_follower
|
||||
|
|
|
@ -565,11 +565,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
def addresses_local_accounts?
|
||||
return true if @options[:delivered_to_account_id]
|
||||
|
||||
local_usernames = (audience_to + audience_cc).uniq.select { |uri| ActivityPub::TagManager.instance.local_uri?(uri) }.map { |uri| ActivityPub::TagManager.instance.uri_to_local_id(uri, :username) }
|
||||
|
||||
return false if local_usernames.empty?
|
||||
|
||||
Account.local.exists?(username: local_usernames)
|
||||
ActivityPub::TagManager.instance.uris_to_local_accounts((audience_to + audience_cc).uniq).exists?
|
||||
end
|
||||
|
||||
def tombstone_exists?
|
||||
|
|
|
@ -242,6 +242,19 @@ class ActivityPub::TagManager
|
|||
path_params[param]
|
||||
end
|
||||
|
||||
def uris_to_local_accounts(uris)
|
||||
usernames = []
|
||||
ids = []
|
||||
|
||||
uris.each do |uri|
|
||||
param, value = uri_to_local_account_params(uri)
|
||||
usernames << value.downcase if param == :username
|
||||
ids << value if param == :id
|
||||
end
|
||||
|
||||
Account.local.with_username(usernames).or(Account.local.where(id: ids))
|
||||
end
|
||||
|
||||
def uri_to_actor(uri)
|
||||
uri_to_resource(uri, Account)
|
||||
end
|
||||
|
@ -252,7 +265,7 @@ class ActivityPub::TagManager
|
|||
if local_uri?(uri)
|
||||
case klass.name
|
||||
when 'Account'
|
||||
klass.find_local(uri_to_local_id(uri, :username))
|
||||
uris_to_local_accounts([uri]).first
|
||||
else
|
||||
StatusFinder.new(uri).status
|
||||
end
|
||||
|
@ -334,4 +347,20 @@ class ActivityPub::TagManager
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def uri_to_local_account_params(uri)
|
||||
return unless local_uri?(uri)
|
||||
|
||||
path_params = Rails.application.routes.recognize_path(uri)
|
||||
|
||||
# TODO: handle numeric IDs
|
||||
case path_params[:controller]
|
||||
when 'accounts'
|
||||
[:username, path_params[:username]]
|
||||
when 'instance_actors'
|
||||
[:id, -99]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue