about summary refs log tree commit diff
path: root/app/lib/formatter.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-03-28 14:16:08 +0200
committerEugen Rochko <eugen@zeonfederated.com>2017-03-28 14:16:08 +0200
commit139fc994e218f3d2e95f38d5f6dae11e8b0b8d58 (patch)
tree57ca0638fd5d09334a3a91de1cc41ddec03ece69 /app/lib/formatter.rb
parent1c6b02f936b984a17343b85a5cfb07ed93dd1cfb (diff)
Fix #408 - link @ names in bios
Diffstat (limited to 'app/lib/formatter.rb')
-rw-r--r--app/lib/formatter.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index b58952ae0..da7ad2027 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -9,8 +9,6 @@ class Formatter
   include ActionView::Helpers::TextHelper
   include ActionView::Helpers::SanitizeHelper
 
-  AUTOLINK_RE = /https?:\/\/([\S]+\.[!#$&-;=?-[\]_a-z~]|%[\w\d]{2}]+[\w])/i
-
   def format(status)
     return reformat(status.content) unless status.local?
 
@@ -39,6 +37,7 @@ class Formatter
 
     html = encode(account.note)
     html = link_urls(html)
+    html = link_accounts(html)
     html = link_hashtags(html)
 
     html.html_safe # rubocop:disable Rails/OutputSafety
@@ -59,12 +58,23 @@ class Formatter
   def link_mentions(html, mentions)
     html.gsub(Account::MENTION_RE) do |match|
       acct    = Account::MENTION_RE.match(match)[1]
-      mention = mentions.find { |item| item.account.acct.casecmp(acct).zero? }
+      mention = mentions.find { |item| TagManager.instance.same_acct?(item.account.acct, acct) }
 
       mention.nil? ? match : mention_html(match, mention.account)
     end
   end
 
+  def link_accounts(html)
+    html.gsub(Account::MENTION_RE) do |match|
+      acct = Account::MENTION_RE.match(match)[1]
+      username, domain = acct.split('@')
+      domain = nil if TagManager.instance.local_domain?(domain)
+      account = Account.find_remote(username, domain)
+
+      account.nil? ? match : mention_html(match, account)
+    end
+  end
+
   def link_hashtags(html)
     html.gsub(Tag::HASHTAG_RE) do |match|
       hashtag_html(match)