闭社主体 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.

70 lines
1.7 KiB

  1. # frozen_string_literal: true
  2. module StreamEntriesHelper
  3. EMBEDDED_CONTROLLER = 'stream_entries'
  4. EMBEDDED_ACTION = 'embed'
  5. def display_name(account)
  6. account.display_name.presence || account.username
  7. end
  8. def stream_link_target
  9. embedded_view? ? '_blank' : nil
  10. end
  11. def acct(account)
  12. if embedded_view? && account.local?
  13. "@#{account.acct}@#{Rails.configuration.x.local_domain}"
  14. else
  15. "@#{account.acct}"
  16. end
  17. end
  18. def style_classes(status, is_predecessor, is_successor, include_threads)
  19. classes = ['entry']
  20. classes << 'entry-predecessor' if is_predecessor
  21. classes << 'entry-reblog' if status.reblog?
  22. classes << 'entry-successor' if is_successor
  23. classes << 'entry-center' if include_threads
  24. classes.join(' ')
  25. end
  26. def microformats_classes(status, is_direct_parent, is_direct_child)
  27. classes = []
  28. classes << 'p-in-reply-to' if is_direct_parent
  29. classes << 'p-repost-of' if status.reblog? && is_direct_parent
  30. classes << 'p-comment' if is_direct_child
  31. classes.join(' ')
  32. end
  33. def microformats_h_class(status, is_predecessor, is_successor, include_threads)
  34. if is_predecessor || status.reblog? || is_successor
  35. 'h-cite'
  36. elsif include_threads
  37. ''
  38. else
  39. 'h-entry'
  40. end
  41. end
  42. def rtl?(text)
  43. rtl_characters = /[\p{Hebrew}|\p{Arabic}|\p{Syriac}|\p{Thaana}|\p{Nko}]+/m.match(text)
  44. if rtl_characters.present?
  45. total_size = text.strip.size.to_f
  46. rtl_size(rtl_characters.to_a) / total_size > 0.3
  47. else
  48. false
  49. end
  50. end
  51. private
  52. def rtl_size(characters)
  53. characters.reduce(0) { |acc, elem| acc + elem.size }.to_f
  54. end
  55. def embedded_view?
  56. params[:controller] == EMBEDDED_CONTROLLER && params[:action] == EMBEDDED_ACTION
  57. end
  58. end