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.

55 lines
1.7 KiB

8 years ago
8 years ago
  1. module ApplicationHelper
  2. def unique_tag(date, id, type)
  3. "tag:#{Rails.configuration.x.local_domain},#{date.strftime('%Y-%m-%d')}:objectId=#{id}:objectType=#{type}"
  4. end
  5. def unique_tag_to_local_id(tag, expected_type)
  6. matches = Regexp.new("objectId=([\\d]+):objectType=#{expected_type}").match(tag)
  7. return matches[1] unless matches.nil?
  8. end
  9. def local_id?(id)
  10. id.start_with?("tag:#{Rails.configuration.x.local_domain}")
  11. end
  12. def content_for_status(actual_status)
  13. if actual_status.local?
  14. linkify(actual_status)
  15. else
  16. sanitize(actual_status.content, tags: %w(a br p), attributes: %w(href rel))
  17. end
  18. end
  19. def account_from_mentions(search_string, mentions)
  20. mentions.each { |x| return x.account if x.account.acct.eql?(search_string) }
  21. nil
  22. # If that was unsuccessful, try fetching user from db separately
  23. # But this shouldn't ever happen if the mentions were created correctly!
  24. # username, domain = search_string.split('@')
  25. # if domain == Rails.configuration.x.local_domain
  26. # account = Account.find_local(username)
  27. # else
  28. # account = Account.find_remote(username, domain)
  29. # end
  30. # account
  31. end
  32. def linkify(status)
  33. auto_link(HTMLEntities.new.encode(status.text), link: :urls, html: { rel: 'nofollow noopener' }).gsub(Account::MENTION_RE) do |m|
  34. account = account_from_mentions(Account::MENTION_RE.match(m)[1], status.mentions)
  35. unless account.nil?
  36. "#{m.split('@').first}<a href=\"#{url_for_target(account)}\" class=\"mention\">@<span>#{account.acct}</span></a>"
  37. else
  38. m
  39. end
  40. end.html_safe
  41. end
  42. def active_nav_class(path)
  43. current_page?(path) ? 'active' : ''
  44. end
  45. end