statuses_helper.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # frozen_string_literal: true
  2. module StatusesHelper
  3. VISIBLITY_ICONS = {
  4. public: 'globe',
  5. unlisted: 'lock_open',
  6. private: 'lock',
  7. direct: 'alternate_email',
  8. }.freeze
  9. def nothing_here(extra_classes = '')
  10. tag.div(class: ['nothing-here', extra_classes]) do
  11. t('accounts.nothing_here')
  12. end
  13. end
  14. def media_summary(status)
  15. attachments = { image: 0, video: 0, audio: 0 }
  16. status.ordered_media_attachments.each do |media|
  17. if media.video?
  18. attachments[:video] += 1
  19. elsif media.audio?
  20. attachments[:audio] += 1
  21. else
  22. attachments[:image] += 1
  23. end
  24. end
  25. text = attachments.to_a.reject { |_, value| value.zero? }.map { |key, value| I18n.t("statuses.attached.#{key}", count: value) }.join(' · ')
  26. return if text.blank?
  27. I18n.t('statuses.attached.description', attached: text)
  28. end
  29. def status_text_summary(status)
  30. return if status.spoiler_text.blank?
  31. I18n.t('statuses.content_warning', warning: status.spoiler_text)
  32. end
  33. def poll_summary(status)
  34. return unless status.preloadable_poll
  35. status.preloadable_poll.options.map { |o| "[ ] #{o}" }.join("\n")
  36. end
  37. def status_description(status)
  38. components = [[media_summary(status), status_text_summary(status)].compact_blank.join(' · ')]
  39. if status.spoiler_text.blank?
  40. components << status.text
  41. components << poll_summary(status)
  42. end
  43. components.compact_blank.join("\n\n")
  44. end
  45. def visibility_icon(status)
  46. VISIBLITY_ICONS[status.visibility.to_sym]
  47. end
  48. def prefers_autoplay?
  49. ActiveModel::Type::Boolean.new.cast(params[:autoplay]) || current_user&.setting_auto_play_gif
  50. end
  51. end