diff options
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 |