Do not fetch preview card for mentioned users (#6934)

lolsob-rspec
ThibG 2018-10-25 18:13:19 +02:00 committed by Eugen Rochko
parent b110105a53
commit 8d76db2714
1 changed files with 10 additions and 2 deletions

View File

@ -17,6 +17,7 @@ class FetchLinkCardService < BaseService
return if @url.nil? || @status.preview_cards.any? return if @url.nil? || @status.preview_cards.any?
@mentions = status.mentions
@url = @url.to_s @url = @url.to_s
RedisLock.acquire(lock_options) do |lock| RedisLock.acquire(lock_options) do |lock|
@ -81,9 +82,16 @@ class FetchLinkCardService < BaseService
uri.host.blank? || TagManager.instance.local_url?(uri.to_s) || !%w(http https).include?(uri.scheme) uri.host.blank? || TagManager.instance.local_url?(uri.to_s) || !%w(http https).include?(uri.scheme)
end 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) def skip_link?(a)
# Avoid links for hashtags and mentions (microformats) # 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 end
def attempt_oembed def attempt_oembed