2
0

Add support for Update of converted object types (#36322)

This commit is contained in:
Claire
2025-10-28 15:05:14 +01:00
committed by GitHub
parent 9c7d09993d
commit 8fb524e07f
5 changed files with 108 additions and 27 deletions

View File

@@ -1,8 +1,6 @@
# frozen_string_literal: true
class ActivityPub::Activity::Create < ActivityPub::Activity
include FormattingHelper
def perform
@account.schedule_refresh_if_stale!
@@ -99,9 +97,9 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
uri: @status_parser.uri,
url: @status_parser.url || @status_parser.uri,
account: @account,
text: converted_object_type? ? converted_text : (@status_parser.text || ''),
text: @status_parser.processed_text,
language: @status_parser.language,
spoiler_text: converted_object_type? ? '' : (@status_parser.spoiler_text || ''),
spoiler_text: @status_parser.processed_spoiler_text,
created_at: @status_parser.created_at,
edited_at: @status_parser.edited_at && @status_parser.edited_at != @status_parser.created_at ? @status_parser.edited_at : nil,
override_timestamps: @options[:override_timestamps],
@@ -405,18 +403,6 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
value_or_id(@object['inReplyTo'])
end
def converted_text
[formatted_title, @status_parser.spoiler_text.presence, formatted_url].compact.join("\n\n")
end
def formatted_title
"<h2>#{@status_parser.title}</h2>" if @status_parser.title.present?
end
def formatted_url
linkify(@status_parser.url || @status_parser.uri)
end
def unsupported_media_type?(mime_type)
mime_type.present? && !MediaAttachment.supported_mime_types.include?(mime_type)
end

View File

@@ -8,10 +8,8 @@ class ActivityPub::Activity::Update < ActivityPub::Activity
if equals_or_includes_any?(@object['type'], %w(Application Group Organization Person Service))
update_account
elsif equals_or_includes_any?(@object['type'], %w(Note Question))
elsif supported_object_type? || converted_object_type?
update_status
elsif converted_object_type?
Status.find_by(uri: object_uri, account_id: @account.id)
end
end

View File

@@ -1,6 +1,7 @@
# frozen_string_literal: true
class ActivityPub::Parser::StatusParser
include FormattingHelper
include JsonLdHelper
NORMALIZED_LOCALE_NAMES = LanguagesHelper::SUPPORTED_LOCALES.keys.index_by(&:downcase).freeze
@@ -44,6 +45,16 @@ class ActivityPub::Parser::StatusParser
end
end
def processed_text
return text || '' unless converted_object_type?
[
title.presence && "<h2>#{title}</h2>",
spoiler_text.presence,
linkify(url || uri),
].compact.join("\n\n")
end
def spoiler_text
if @object['summary'].present?
@object['summary']
@@ -52,6 +63,12 @@ class ActivityPub::Parser::StatusParser
end
end
def processed_spoiler_text
return '' if converted_object_type?
spoiler_text || ''
end
def title
if @object['name'].present?
@object['name']
@@ -145,6 +162,10 @@ class ActivityPub::Parser::StatusParser
as_array(@object['quoteAuthorization']).first
end
def converted_object_type?
equals_or_includes_any?(@object['type'], ActivityPub::Activity::CONVERTED_TYPES)
end
private
def quote_subpolicy(subpolicy)

View File

@@ -20,7 +20,6 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
@request_id = request_id
@quote = nil
# Only native types can be updated at the moment
return @status if !expected_type? || already_updated_more_recently?
if @status_parser.edited_at.present? && (@status.edited_at.nil? || @status_parser.edited_at > @status.edited_at)
@@ -170,8 +169,8 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
end
def update_immediate_attributes!
@status.text = @status_parser.text || ''
@status.spoiler_text = @status_parser.spoiler_text || ''
@status.text = @status_parser.processed_text
@status.spoiler_text = @status_parser.processed_spoiler_text
@status.sensitive = @account.sensitized? || @status_parser.sensitive || false
@status.language = @status_parser.language
@@ -351,7 +350,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
end
def expected_type?
equals_or_includes_any?(@json['type'], %w(Note Question))
equals_or_includes_any?(@json['type'], ActivityPub::Activity::SUPPORTED_TYPES) || equals_or_includes_any?(@json['type'], ActivityPub::Activity::CONVERTED_TYPES)
end
def record_previous_edit!