闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. class RSS::Serializer
  3. private
  4. def render_statuses(builder, statuses)
  5. statuses.each do |status|
  6. builder.item do |item|
  7. item.title(status_title(status))
  8. .link(ActivityPub::TagManager.instance.url_for(status))
  9. .pub_date(status.created_at)
  10. .description(status.spoiler_text.presence || Formatter.instance.format(status, inline_poll_options: true).to_str)
  11. status.media_attachments.each do |media|
  12. item.enclosure(full_asset_url(media.file.url(:original, false)), media.file.content_type, media.file.size)
  13. end
  14. end
  15. end
  16. end
  17. def status_title(status)
  18. return "#{status.account.acct} deleted status" if status.destroyed?
  19. preview = status.proper.spoiler_text.presence || status.proper.text
  20. if preview.length > 30 || preview[0, 30].include?("\n")
  21. preview = preview[0, 30]
  22. preview = preview[0, preview.index("\n").presence || 30] + '…'
  23. end
  24. preview = "#{status.proper.spoiler_text.present? ? 'CW ' : ''}#{preview}#{status.proper.sensitive? ? ' (sensitive)' : ''}"
  25. if status.reblog?
  26. "#{status.account.acct} boosted #{status.reblog.account.acct}: #{preview}"
  27. else
  28. "#{status.account.acct}: #{preview}"
  29. end
  30. end
  31. end