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

41 lines
1.4 KiB

  1. module StreamEntriesHelper
  2. def display_name(account)
  3. account.display_name.blank? ? account.username : account.display_name
  4. end
  5. def avatar_for_status_url(status)
  6. status.reblog? ? status.reblog.account.avatar.url(:medium) : status.account.avatar.url(:medium)
  7. end
  8. def entry_classes(status, is_predecessor, is_successor, include_threads)
  9. classes = ['entry']
  10. classes << 'entry-reblog' if status.reblog?
  11. classes << 'entry-predecessor' if is_predecessor
  12. classes << 'entry-successor' if is_successor
  13. classes << 'entry-center' if include_threads
  14. classes.join(' ')
  15. end
  16. def relative_time(date)
  17. date < 5.days.ago ? date.strftime("%d.%m.%Y") : "#{time_ago_in_words(date)} ago"
  18. end
  19. def linkify(status)
  20. mention_hash = {}
  21. status.mentions.each { |m| mention_hash[m.acct] = m }
  22. coder = HTMLEntities.new
  23. auto_link(coder.encode(status.text), link: :urls, html: { target: '_blank', rel: 'nofollow' }).gsub(Account::MENTION_RE) do |m|
  24. account = mention_hash[Account::MENTION_RE.match(m)[1]]
  25. "#{m.split('@').first}<a href=\"#{url_for_target(account)}\" class=\"mention\">@<span>#{account.acct}</span></a>"
  26. end.html_safe
  27. end
  28. def reblogged_by_me_class(status)
  29. user_signed_in? && current_user.account.reblogged?(status) ? 'reblogged' : ''
  30. end
  31. def favourited_by_me_class(status)
  32. user_signed_in? && current_user.account.favourited?(status) ? 'favourited' : ''
  33. end
  34. end