From 624c024766227255c78d31bd408876c64a8b279f Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 3 Sep 2025 11:35:44 +0200 Subject: [PATCH] =?UTF-8?q?Prepend=20=E2=80=9CRE:=20=E2=80=9D=20fallb?= =?UTF-8?q?ack=20link=20to=20Mastodon-authored=20quote=20posts=20(#35971)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/formatting_helper.rb | 4 +++- app/lib/text_formatter.rb | 12 ++++++++++++ app/models/status_edit.rb | 7 +++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/helpers/formatting_helper.rb b/app/helpers/formatting_helper.rb index c27edbb0730..68aad4f6771 100644 --- a/app/helpers/formatting_helper.rb +++ b/app/helpers/formatting_helper.rb @@ -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) diff --git a/app/lib/text_formatter.rb b/app/lib/text_formatter.rb index 45fb06e705d..963cc0d1c43 100644 --- a/app/lib/text_formatter.rb +++ b/app/lib/text_formatter.rb @@ -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 +

RE: #{TextFormatter.shortened_link(url)}

#{html} + HTML + end end diff --git a/app/models/status_edit.rb b/app/models/status_edit.rb index a3da1078535..d99591d7992 100644 --- a/app/models/status_edit.rb +++ b/app/models/status_edit.rb @@ -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