Fix: 一部サーバーの投稿が参照引用できない問題・参照引用時、フェッチを基本しないよう変更 (#360)
This commit is contained in:
parent
6dbe5c882d
commit
1f73b81bd8
7 changed files with 81 additions and 18 deletions
|
@ -544,7 +544,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
url = quote
|
||||
|
||||
if url.present?
|
||||
ResolveURLService.new.call(url, on_behalf_of: @account, local_only: true).present?
|
||||
ActivityPub::TagManager.instance.uri_to_resource(url, Status)&.local?
|
||||
else
|
||||
false
|
||||
end
|
||||
|
|
|
@ -208,7 +208,7 @@ class ActivityPub::TagManager
|
|||
uri_to_resource(uri, Account)
|
||||
end
|
||||
|
||||
def uri_to_resource(uri, klass)
|
||||
def uri_to_resource(uri, klass, url: false)
|
||||
return if uri.nil?
|
||||
|
||||
if local_uri?(uri)
|
||||
|
@ -221,7 +221,9 @@ class ActivityPub::TagManager
|
|||
elsif OStatus::TagManager.instance.local_id?(uri)
|
||||
klass.find_by(id: OStatus::TagManager.instance.unique_tag_to_local_id(uri, klass.to_s))
|
||||
else
|
||||
klass.find_by(uri: uri.split('#').first)
|
||||
resource = klass.find_by(uri: uri.split('#').first)
|
||||
resource ||= klass.where('uri != url').find_by(url: uri.split('#').first) if url
|
||||
resource
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
nil
|
||||
|
|
|
@ -141,11 +141,20 @@ class ProcessReferencesService < BaseService
|
|||
end
|
||||
|
||||
def url_to_status(url)
|
||||
ResolveURLService.new.call(url, on_behalf_of: @status.account, fetch_remote: @fetch_remote && @no_fetch_urls.exclude?(url))
|
||||
status = ActivityPub::TagManager.instance.uri_to_resource(url, Status, url: true)
|
||||
status ||= ResolveURLService.new.call(url, on_behalf_of: @status.account) if @fetch_remote && @no_fetch_urls.exclude?(url)
|
||||
referrable?(status) ? status : nil
|
||||
end
|
||||
|
||||
def referrable?(target_status)
|
||||
return false if target_status.nil?
|
||||
return @referrable if defined?(@referrable)
|
||||
|
||||
@referrable = StatusPolicy.new(@status.account, target_status).show?
|
||||
end
|
||||
|
||||
def quotable?(target_status)
|
||||
target_status.account.allow_quote? && (!@status.local? || StatusPolicy.new(@status.account, target_status).quote?)
|
||||
target_status.account.allow_quote? && StatusPolicy.new(@status.account, target_status).quote?
|
||||
end
|
||||
|
||||
def add_references
|
||||
|
|
|
@ -6,16 +6,15 @@ class ResolveURLService < BaseService
|
|||
|
||||
USERNAME_STATUS_RE = %r{/@(?<username>#{Account::USERNAME_RE})/(?<status_id>[0-9]+)\Z}
|
||||
|
||||
def call(url, on_behalf_of: nil, fetch_remote: true, local_only: false)
|
||||
def call(url, on_behalf_of: nil)
|
||||
@url = url
|
||||
@on_behalf_of = on_behalf_of
|
||||
@fetch_remote = fetch_remote
|
||||
|
||||
if local_url?
|
||||
process_local_url
|
||||
elsif !local_only && fetch_remote && !fetched_resource.nil?
|
||||
elsif !fetched_resource.nil?
|
||||
process_url
|
||||
elsif !local_only
|
||||
else
|
||||
process_url_from_db
|
||||
end
|
||||
end
|
||||
|
@ -38,7 +37,7 @@ class ResolveURLService < BaseService
|
|||
return account unless account.nil?
|
||||
end
|
||||
|
||||
return unless @on_behalf_of.present? && (!@fetch_remote || [401, 403, 404].include?(fetch_resource_service.response_code))
|
||||
return unless @on_behalf_of.present? && [401, 403, 404].include?(fetch_resource_service.response_code)
|
||||
|
||||
# It may happen that the resource is a private toot, and thus not fetchable,
|
||||
# but we can return the toot if we already know about it.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue