Add initial support for ingesting and verifying remote quote posts (#34370)
This commit is contained in:
parent
a324edabdf
commit
df2611a10f
33 changed files with 1643 additions and 22 deletions
|
@ -45,9 +45,12 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
@unresolved_mentions = []
|
||||
@silenced_account_ids = []
|
||||
@params = {}
|
||||
@quote = nil
|
||||
@quote_uri = nil
|
||||
|
||||
process_status_params
|
||||
process_tags
|
||||
process_quote
|
||||
process_audience
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
|
@ -55,6 +58,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
attach_tags(@status)
|
||||
attach_mentions(@status)
|
||||
attach_counts(@status)
|
||||
attach_quote(@status)
|
||||
end
|
||||
|
||||
resolve_thread(@status)
|
||||
|
@ -189,6 +193,16 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
end
|
||||
end
|
||||
|
||||
def attach_quote(status)
|
||||
return if @quote.nil?
|
||||
|
||||
@quote.status = status
|
||||
@quote.save
|
||||
ActivityPub::VerifyQuoteService.new.call(@quote, fetchable_quoted_uri: @quote_uri, request_id: @options[:request_id])
|
||||
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS
|
||||
ActivityPub::RefetchAndVerifyQuoteWorker.perform_in(rand(30..600).seconds, @quote.id, @quote_uri, { 'request_id' => @options[:request_id] })
|
||||
end
|
||||
|
||||
def process_tags
|
||||
return if @object['tag'].nil?
|
||||
|
||||
|
@ -203,6 +217,17 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
end
|
||||
end
|
||||
|
||||
def process_quote
|
||||
return unless Mastodon::Feature.inbound_quotes_enabled?
|
||||
|
||||
@quote_uri = @status_parser.quote_uri
|
||||
return if @quote_uri.blank?
|
||||
|
||||
approval_uri = @status_parser.quote_approval_uri
|
||||
approval_uri = nil if unsupported_uri_scheme?(approval_uri)
|
||||
@quote = Quote.new(account: @account, approval_uri: approval_uri)
|
||||
end
|
||||
|
||||
def process_hashtag(tag)
|
||||
return if tag['name'].blank?
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity
|
|||
if @account.uri == object_uri
|
||||
delete_person
|
||||
else
|
||||
delete_note
|
||||
delete_object
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -17,7 +17,7 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity
|
|||
end
|
||||
end
|
||||
|
||||
def delete_note
|
||||
def delete_object
|
||||
return if object_uri.nil?
|
||||
|
||||
with_redis_lock("delete_status_in_progress:#{object_uri}", raise_on_failure: false) do
|
||||
|
@ -32,21 +32,38 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity
|
|||
Tombstone.find_or_create_by(uri: object_uri, account: @account)
|
||||
end
|
||||
|
||||
@status = Status.find_by(uri: object_uri, account: @account)
|
||||
@status ||= Status.find_by(uri: @object['atomUri'], account: @account) if @object.is_a?(Hash) && @object['atomUri'].present?
|
||||
|
||||
return if @status.nil?
|
||||
|
||||
forwarder.forward! if forwarder.forwardable?
|
||||
delete_now!
|
||||
case @object['type']
|
||||
when 'QuoteAuthorization'
|
||||
revoke_quote
|
||||
when 'Note', 'Question'
|
||||
delete_status
|
||||
else
|
||||
delete_status || revoke_quote
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def delete_status
|
||||
@status = Status.find_by(uri: object_uri, account: @account)
|
||||
@status ||= Status.find_by(uri: @object['atomUri'], account: @account) if @object.is_a?(Hash) && @object['atomUri'].present?
|
||||
|
||||
return if @status.nil?
|
||||
|
||||
forwarder.forward! if forwarder.forwardable?
|
||||
RemoveStatusService.new.call(@status, redraft: false)
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def revoke_quote
|
||||
@quote = Quote.find_by(approval_uri: object_uri, quoted_account: @account)
|
||||
return if @quote.nil?
|
||||
|
||||
ActivityPub::Forwarder.new(@account, @json, @quote.status).forward!
|
||||
@quote.reject!
|
||||
end
|
||||
|
||||
def forwarder
|
||||
@forwarder ||= ActivityPub::Forwarder.new(@account, @json, @status)
|
||||
end
|
||||
|
||||
def delete_now!
|
||||
RemoveStatusService.new.call(@status, redraft: false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -101,6 +101,16 @@ class ActivityPub::Parser::StatusParser
|
|||
@object.dig(:shares, :totalItems)
|
||||
end
|
||||
|
||||
def quote_uri
|
||||
%w(quote _misskey_quote quoteUrl quoteUri).filter_map do |key|
|
||||
value_or_id(as_array(@object[key]).first)
|
||||
end.first
|
||||
end
|
||||
|
||||
def quote_approval_uri
|
||||
as_array(@object['quoteAuthorization']).first
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def raw_language_code
|
||||
|
|
|
@ -71,6 +71,23 @@ class StatusCacheHydrator
|
|||
payload[:bookmarked] = Bookmark.exists?(account_id: account_id, status_id: status.id)
|
||||
payload[:pinned] = StatusPin.exists?(account_id: account_id, status_id: status.id) if status.account_id == account_id
|
||||
payload[:filtered] = mapped_applied_custom_filter(account_id, status)
|
||||
payload[:quote] = hydrate_quote_payload(payload[:quote], status.quote, account_id) if payload[:quote]
|
||||
end
|
||||
|
||||
def hydrate_quote_payload(empty_payload, quote, account_id)
|
||||
# TODO: properly handle quotes, including visibility and access control
|
||||
|
||||
empty_payload.tap do |payload|
|
||||
# Nothing to do if we're in the shallow (depth limit) case
|
||||
next unless payload.key?(:quoted_status)
|
||||
|
||||
# TODO: handle hiding a rendered status or showing a non-rendered status according to visibility
|
||||
if quote&.quoted_status.nil?
|
||||
payload[:quoted_status] = nil
|
||||
elsif payload[:quoted_status].present?
|
||||
payload[:quoted_status] = StatusCacheHydrator.new(quote.quoted_status).hydrate(account_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def mapped_applied_custom_filter(account_id, status)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue