Skip to content

Commit

Permalink
Do not fetch preview card for mentioned users (#6934)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and Gargron committed Oct 25, 2018
1 parent d4cf963 commit 7fee968
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/services/fetch_link_card_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def call(status)

return if @url.nil? || @status.preview_cards.any?

@url = @url.to_s
@mentions = status.mentions
@url = @url.to_s

RedisLock.acquire(lock_options) do |lock|
if lock.acquired?
Expand Down Expand Up @@ -81,9 +82,16 @@ def bad_url?(uri)
uri.host.blank? || TagManager.instance.local_url?(uri.to_s) || !%w(http https).include?(uri.scheme)
end

def mention_link?(a)
return false if @mentions.nil?
@mentions.any? do |mention|
a['href'] == TagManager.instance.url_for(mention.target)
end
end

def skip_link?(a)
# Avoid links for hashtags and mentions (microformats)
a['rel']&.include?('tag') || a['class']&.include?('u-url')
a['rel']&.include?('tag') || a['class']&.include?('u-url') || mention_link?(a)
end

def attempt_oembed
Expand Down

0 comments on commit 7fee968

Please sign in to comment.