mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-23 13:05:12 +01:00
Fix #408 - link @ names in bios
This commit is contained in:
parent
1c6b02f936
commit
139fc994e2
@ -9,8 +9,6 @@ class Formatter
|
|||||||
include ActionView::Helpers::TextHelper
|
include ActionView::Helpers::TextHelper
|
||||||
include ActionView::Helpers::SanitizeHelper
|
include ActionView::Helpers::SanitizeHelper
|
||||||
|
|
||||||
AUTOLINK_RE = /https?:\/\/([\S]+\.[!#$&-;=?-[\]_a-z~]|%[\w\d]{2}]+[\w])/i
|
|
||||||
|
|
||||||
def format(status)
|
def format(status)
|
||||||
return reformat(status.content) unless status.local?
|
return reformat(status.content) unless status.local?
|
||||||
|
|
||||||
@ -39,6 +37,7 @@ class Formatter
|
|||||||
|
|
||||||
html = encode(account.note)
|
html = encode(account.note)
|
||||||
html = link_urls(html)
|
html = link_urls(html)
|
||||||
|
html = link_accounts(html)
|
||||||
html = link_hashtags(html)
|
html = link_hashtags(html)
|
||||||
|
|
||||||
html.html_safe # rubocop:disable Rails/OutputSafety
|
html.html_safe # rubocop:disable Rails/OutputSafety
|
||||||
@ -59,12 +58,23 @@ class Formatter
|
|||||||
def link_mentions(html, mentions)
|
def link_mentions(html, mentions)
|
||||||
html.gsub(Account::MENTION_RE) do |match|
|
html.gsub(Account::MENTION_RE) do |match|
|
||||||
acct = Account::MENTION_RE.match(match)[1]
|
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)
|
mention.nil? ? match : mention_html(match, mention.account)
|
||||||
end
|
end
|
||||||
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)
|
def link_hashtags(html)
|
||||||
html.gsub(Tag::HASHTAG_RE) do |match|
|
html.gsub(Tag::HASHTAG_RE) do |match|
|
||||||
hashtag_html(match)
|
hashtag_html(match)
|
||||||
|
@ -60,6 +60,12 @@ class TagManager
|
|||||||
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.local_domain).zero?
|
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.local_domain).zero?
|
||||||
end
|
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)
|
def local_url?(url)
|
||||||
uri = Addressable::URI.parse(url)
|
uri = Addressable::URI.parse(url)
|
||||||
domain = uri.host + (uri.port ? ":#{uri.port}" : '')
|
domain = uri.host + (uri.port ? ":#{uri.port}" : '')
|
||||||
|
Loading…
Reference in New Issue
Block a user