statuses_helper.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # frozen_string_literal: true
  2. module StatusesHelper
  3. EMBEDDED_CONTROLLER = 'statuses'
  4. EMBEDDED_ACTION = 'embed'
  5. def link_to_newer(url)
  6. link_to t('statuses.show_newer'), url, class: 'load-more load-gap'
  7. end
  8. def link_to_older(url)
  9. link_to t('statuses.show_older'), url, class: 'load-more load-gap'
  10. end
  11. def nothing_here(extra_classes = '')
  12. content_tag(:div, class: "nothing-here #{extra_classes}") do
  13. t('accounts.nothing_here')
  14. end
  15. end
  16. def media_summary(status)
  17. attachments = { image: 0, video: 0, audio: 0 }
  18. status.ordered_media_attachments.each do |media|
  19. if media.video?
  20. attachments[:video] += 1
  21. elsif media.audio?
  22. attachments[:audio] += 1
  23. else
  24. attachments[:image] += 1
  25. end
  26. end
  27. text = attachments.to_a.reject { |_, value| value.zero? }.map { |key, value| I18n.t("statuses.attached.#{key}", count: value) }.join(' · ')
  28. return if text.blank?
  29. I18n.t('statuses.attached.description', attached: text)
  30. end
  31. def status_text_summary(status)
  32. return if status.spoiler_text.blank?
  33. I18n.t('statuses.content_warning', warning: status.spoiler_text)
  34. end
  35. def poll_summary(status)
  36. return unless status.preloadable_poll
  37. status.preloadable_poll.options.map { |o| "[ ] #{o}" }.join("\n")
  38. end
  39. def status_description(status)
  40. components = [[media_summary(status), status_text_summary(status)].compact_blank.join(' · ')]
  41. if status.spoiler_text.blank?
  42. components << status.text
  43. components << poll_summary(status)
  44. end
  45. components.compact_blank.join("\n\n")
  46. end
  47. def stream_link_target
  48. embedded_view? ? '_blank' : nil
  49. end
  50. def fa_visibility_icon(status)
  51. case status.visibility
  52. when 'public'
  53. fa_icon 'globe fw'
  54. when 'unlisted'
  55. fa_icon 'unlock fw'
  56. when 'private'
  57. fa_icon 'lock fw'
  58. when 'direct'
  59. fa_icon 'at fw'
  60. end
  61. end
  62. def embedded_view?
  63. params[:controller] == EMBEDDED_CONTROLLER && params[:action] == EMBEDDED_ACTION
  64. end
  65. def prefers_autoplay?
  66. ActiveModel::Type::Boolean.new.cast(params[:autoplay]) || current_user&.setting_auto_play_gif
  67. end
  68. end