mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-09 16:20:09 +09:00
Reuse native plain text conversion for attachment-free content
This commit is contained in:
@@ -21,7 +21,15 @@ class Message < ApplicationRecord
|
||||
scope :with_presentation, -> { with_creator.with_attachment_details.with_boosts.preload(:room) }
|
||||
|
||||
def plain_text_body
|
||||
body.to_plain_text.presence || attachment&.filename&.to_s || ""
|
||||
content = body.body
|
||||
text = if content && content.fragment.find_all(ActionText::Attachment.tag_name).empty?
|
||||
# ActionText::Content#to_plain_text duplicates the fragment to replace
|
||||
# attachments. Without them, reuse its native Fragment conversion instead.
|
||||
content.fragment.to_plain_text.dup
|
||||
else
|
||||
body.to_plain_text
|
||||
end
|
||||
text.presence || attachment&.filename&.to_s || ""
|
||||
end
|
||||
|
||||
def content_type
|
||||
|
||||
Reference in New Issue
Block a user