about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2018-10-25 18:13:19 +0200
committerEugen Rochko <eugen@zeonfederated.com>2018-10-25 18:13:19 +0200
commit7fee968e9fb75d0f6d381009d5c4403c5a027174 (patch)
treed66891c876a3dcd0ba6e5353418fb813395f6462 /app
parentd4cf963749d2f6bb8e47a670e8cc4819ff659f49 (diff)
Do not fetch preview card for mentioned users (#6934)
Diffstat (limited to 'app')
-rw-r--r--app/services/fetch_link_card_service.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb
index 4169c685b..4551aa7e0 100644
--- a/app/services/fetch_link_card_service.rb
+++ b/app/services/fetch_link_card_service.rb
@@ -17,7 +17,8 @@ class FetchLinkCardService < BaseService
 
     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?
@@ -81,9 +82,16 @@ class FetchLinkCardService < BaseService
     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