Bläddra i källkod

don't send spammy mentions

nightpool 4 månader sedan
förälder
incheckning
40bd7a4282
2 ändrade filer med 14 tillägg och 1 borttagningar
  1. 6
    1
      app/lib/activitypub/activity.rb
  2. 8
    0
      app/models/status.rb

+ 6
- 1
app/lib/activitypub/activity.rb Visa fil

@@ -90,7 +90,7 @@ class ActivityPub::Activity
90 90
     crawl_links(status)
91 91
 
92 92
     notify_about_reblog(status) if reblog_of_local_account?(status)
93
-    notify_about_mentions(status)
93
+    notify_about_mentions(status) unless spammy_mentions?(status)
94 94
 
95 95
     # Only continue if the status is supposed to have arrived in real-time.
96 96
     # Note that if @options[:override_timestamps] isn't set, the status
@@ -105,6 +105,11 @@ class ActivityPub::Activity
105 105
     status.reblog? && status.reblog.account.local?
106 106
   end
107 107
 
108
+  def spammy_mentions?(status)
109
+    status.has_non_mention_links? &&
110
+    @account.followers.local.count == 0
111
+  end
112
+
108 113
   def notify_about_reblog(status)
109 114
     NotifyService.new.call(status.reblog.account, status)
110 115
   end

+ 8
- 0
app/models/status.rb Visa fil

@@ -431,6 +431,14 @@ class Status < ApplicationRecord
431 431
     end
432 432
   end
433 433
 
434
+  def has_non_mention_links?
435
+    if local?
436
+      text.match? %r{https?://\w}
437
+    else
438
+      Nokogiri::HTML.fragment(text).css('a:not(.mention)').present?
439
+    end
440
+  end
441
+
434 442
   private
435 443
 
436 444
   def update_status_stat!(attrs)

Laddar…
Avbryt
Spara