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.

53 lines
1.5 KiB

  1. # frozen_string_literal: true
  2. module StreamEntriesHelper
  3. def display_name(account)
  4. account.display_name.blank? ? account.username : account.display_name
  5. end
  6. def acct(account)
  7. "@#{account.acct}#{@external_links && account.local? ? "@#{Rails.configuration.x.local_domain}" : ''}"
  8. end
  9. def avatar_for_status_url(status)
  10. status.reblog? ? status.reblog.account.avatar.url(:original) : status.account.avatar.url(:original)
  11. end
  12. def entry_classes(status, is_predecessor, is_successor, include_threads)
  13. classes = ['entry']
  14. classes << 'entry-reblog u-repost-of h-cite' if status.reblog?
  15. classes << 'entry-predecessor u-in-reply-to h-cite' if is_predecessor
  16. classes << 'entry-successor u-comment h-cite' if is_successor
  17. classes << 'entry-center h-entry' if include_threads
  18. classes.join(' ')
  19. end
  20. def relative_time(date)
  21. date < 5.days.ago ? date.strftime('%d.%m.%Y') : "#{time_ago_in_words(date)} ago"
  22. end
  23. def reblogged_by_me_class(status)
  24. user_signed_in? && @reblogged.key?(status.id) ? 'reblogged' : ''
  25. end
  26. def favourited_by_me_class(status)
  27. user_signed_in? && @favourited.key?(status.id) ? 'favourited' : ''
  28. end
  29. def proper_status(status)
  30. status.reblog? ? status.reblog : status
  31. end
  32. def rtl?(text)
  33. return false if text.empty?
  34. matches = /[\p{Hebrew}|\p{Arabic}|\p{Syriac}|\p{Thaana}|\p{Nko}]+/m.match(text)
  35. return false unless matches
  36. rtl_size = matches.to_a.reduce(0) { |acc, elem| acc + elem.size }.to_f
  37. ltr_size = text.strip.size.to_f
  38. rtl_size / ltr_size > 0.3
  39. end
  40. end