about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorshel <Yiskah.Raphen@gmail.com>2017-03-31 10:34:14 -0400
committerGitHub <noreply@github.com>2017-03-31 10:34:14 -0400
commitf20f6b25b98efffca47caae713f8dc5e1d0d4bd1 (patch)
tree104152d4bd6f9889f38b2f46fee108185c3b29f7 /app/lib
parent76188d61f2c3bb5747208df92835e912db18d7b6 (diff)
parent680f9efe9c4aa7fce1f4dd6a35ef4aca7a80c1f3 (diff)
Merge branch 'master' into patch-2
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/formatter.rb16
-rw-r--r--app/lib/tag_manager.rb6
2 files changed, 19 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)
diff --git a/app/lib/tag_manager.rb b/app/lib/tag_manager.rb
index 34c3edc4b..2a5e7a409 100644
--- a/app/lib/tag_manager.rb
+++ b/app/lib/tag_manager.rb
@@ -60,6 +60,12 @@ class TagManager
     domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.local_domain).zero?
   end
 
+  def same_acct?(canonical, needle)
+    return true if canonical.casecmp(needle).zero?
+    username, domain = needle.split('@')
+    local_domain?(domain) && canonical.casecmp(username).zero?
+  end
+
   def local_url?(url)
     uri    = Addressable::URI.parse(url)
     domain = uri.host + (uri.port ? ":#{uri.port}" : '')