about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/lib/formatter.rb26
-rw-r--r--app/serializers/activitypub/note_serializer.rb2
2 files changed, 17 insertions, 11 deletions
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index 513b85fc3..5cc4761e5 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -41,10 +41,12 @@ class Formatter
 
     summary = nil
     raw_content = status.text
+    summary_mode = false
 
     if status.title.present?
       summary = status.spoiler_text.presence || status.text
-      raw_content = options[:article_content] ? status.text : summary
+      summary_mode = !options[:article_content]
+      raw_content = summary_mode ? summary : status.text
     end
 
     if options[:inline_poll_options] && status.preloadable_poll
@@ -54,23 +56,27 @@ class Formatter
     return '' if raw_content.blank?
     return format_remote_content(raw_content, status.emojis, summary: summary, **options) unless status.local?
 
+    html = raw_content
+    html = "RT @#{prepend_reblog} #{html}" if prepend_reblog
+    html = "📄 #{html}" if summary_mode
+    return html if options[:plaintext]
+
     linkable_accounts = status.active_mentions.map(&:account)
     linkable_accounts << status.account
 
-    html = raw_content
-    html = "RT @#{prepend_reblog} #{html}" if prepend_reblog
-    html = format_markdown(html) if status.content_type == 'text/markdown'
-    html = encode_and_link_urls(html, linkable_accounts, keep_html: %w(text/markdown text/html).include?(status.content_type))
-    html = reformat(html, true) if %w(text/markdown text/html).include?(status.content_type)
+    keep_html = !summary_mode && %w(text/markdown text/html).include?(status.content_type)
+
+    html = format_markdown(html) if !summary_mode && status.content_type == 'text/markdown'
+    html = encode_and_link_urls(html, linkable_accounts, keep_html: keep_html)
+    html = reformat(html, true) if keep_html
     html = encode_custom_emojis(html, status.emojis, options[:autoplay]) if options[:custom_emojify]
 
-    unless %w(text/markdown text/html).include?(status.content_type)
+    unless keep_html
       html = simple_format(html, {}, sanitize: false)
       html = html.delete("\n")
     end
 
-    html = format_article_content(summary, html) if options[:article_content] && summary.present?
-    html = format_article_summary(html, status) if !options[:article_content] && summary.present?
+    html = summary_mode ? format_article_summary(html, status) : format_article_content(summary, html) if summary.present?
     html.html_safe # rubocop:disable Rails/OutputSafety
   end
 
@@ -93,7 +99,7 @@ class Formatter
 
   def format_article_summary(html, status)
     status_url = ActivityPub::TagManager.instance.url_for(status)
-    "#{html}\n<p data-name=\"permalink\"><span>📄&nbsp;</span>#{link_url(status_url)}</p>"
+    "#{html}\n<p data-name=\"permalink\">#{link_url(status_url)}</p>"
   end
 
   def format_article_content(summary, html)
diff --git a/app/serializers/activitypub/note_serializer.rb b/app/serializers/activitypub/note_serializer.rb
index b86ab932e..acadce1b2 100644
--- a/app/serializers/activitypub/note_serializer.rb
+++ b/app/serializers/activitypub/note_serializer.rb
@@ -55,7 +55,7 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
   end
 
   def summary
-    return Formatter.instance.format(object) if title_present?
+    return Formatter.instance.format(object, plaintext: true) || Setting.outgoing_spoilers.presence if title_present?
 
     object.spoiler_text.presence || (instance_options[:allow_local_only] ? nil : Setting.outgoing_spoilers.presence)
   end