Prepend “RE: <url>” fallback link to Mastodon-authored quote posts (#35971)

This commit is contained in:
Claire 2025-09-03 11:35:44 +02:00 committed by GitHub
parent 927468bce5
commit 624c024766
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 1 deletions

View File

@ -27,7 +27,9 @@ module FormattingHelper
module_function :extract_status_plain_text
def status_content_format(status)
html_aware_format(status.text, status.local?, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : []))
quoted_status = status.quote&.quoted_status if status.local?
html_aware_format(status.text, status.local?, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : []), quoted_status: quoted_status)
end
def rss_status_content_format(status)

View File

@ -44,6 +44,7 @@ class TextFormatter
end
html = simple_format(html, {}, sanitize: false).delete("\n") if multiline?
html = add_quote_fallback(html) if options[:quoted_status].present?
html.html_safe # rubocop:disable Rails/OutputSafety
end
@ -172,4 +173,15 @@ class TextFormatter
def preloaded_accounts?
preloaded_accounts.present?
end
def add_quote_fallback(html)
return html if options[:quoted_status].nil?
url = ActivityPub::TagManager.instance.url_for(options[:quoted_status]) || ActivityPub::TagManager.instance.uri_for(options[:quoted_status])
return html if url.blank? || html.include?(url)
<<~HTML.squish
<p class="quote-inline">RE: #{TextFormatter.shortened_link(url)}</p>#{html}
HTML
end
end

View File

@ -45,6 +45,13 @@ class StatusEdit < ApplicationRecord
delegate :local?, :application, :edited?, :edited_at,
:discarded?, :reply?, :visibility, :language, to: :status
def quote
underlying_quote = status.quote
return if underlying_quote.nil? || underlying_quote.id != quote_id
underlying_quote
end
def with_media?
ordered_media_attachments.any?
end