diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-03-25 02:13:30 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-03-25 02:13:30 +0100 |
commit | a08e724476f47b85de9bb334eeadaf882a7a23ee (patch) | |
tree | d779668fa289d2b7077c878b19fc6691a57142b7 /app/helpers/application_helper.rb | |
parent | 9594f0e858172b9295c5598fcb6ab10506d3046d (diff) |
Fix subscriptions:clear task, refactor feeds, refactor streamable activites
and atom feed generation to some extent, as well as the way mentions are stored
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r-- | app/helpers/application_helper.rb | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 04eec89df..a56bbe59e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -20,13 +20,25 @@ module ApplicationHelper end end - def linkify(status) - mention_hash = {} - status.mentions.each { |m| mention_hash[m.acct] = m } - coder = HTMLEntities.new + def account_from_mentions(search_string, mentions) + mentions.each { |x| return x.account if x.account.acct.eql?(search_string) } + + # If that was unsuccessful, try fetching user from db separately + # But this shouldn't ever happen if the mentions were created correctly! + username, domain = search_string.split('@') + + if domain == Rails.configuration.x.local_domain + account = Account.find_local(username) + else + account = Account.find_by(username: username, domain: domain) + end + + account + end - auto_link(coder.encode(status.text), link: :urls, html: { rel: 'nofollow noopener' }).gsub(Account::MENTION_RE) do |m| - account = mention_hash[Account::MENTION_RE.match(m)[1]] + def linkify(status) + auto_link(HTMLEntities.new.encode(status.text), link: :urls, html: { rel: 'nofollow noopener' }).gsub(Account::MENTION_RE) do |m| + account = account_from_mentions(Account::MENTION_RE.match(m)[1], status.mentions) "#{m.split('@').first}<a href=\"#{url_for_target(account)}\" class=\"mention\">@<span>#{account.acct}</span></a>" end.html_safe end |