From 40bd7a4282b2a1ed2da00a94115be4be4711cfd6 Mon Sep 17 00:00:00 2001 From: nightpool Date: Sat, 15 Jun 2019 11:46:08 -0400 Subject: [PATCH] don't send spammy mentions --- app/lib/activitypub/activity.rb | 7 ++++++- app/models/status.rb | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/lib/activitypub/activity.rb b/app/lib/activitypub/activity.rb index 54b175613..e82af3ce6 100644 --- a/app/lib/activitypub/activity.rb +++ b/app/lib/activitypub/activity.rb @@ -90,7 +90,7 @@ class ActivityPub::Activity crawl_links(status) notify_about_reblog(status) if reblog_of_local_account?(status) - notify_about_mentions(status) + notify_about_mentions(status) unless spammy_mentions?(status) # Only continue if the status is supposed to have arrived in real-time. # Note that if @options[:override_timestamps] isn't set, the status @@ -105,6 +105,11 @@ class ActivityPub::Activity status.reblog? && status.reblog.account.local? end + def spammy_mentions?(status) + status.has_non_mention_links? && + @account.followers.local.count == 0 + end + def notify_about_reblog(status) NotifyService.new.call(status.reblog.account, status) end diff --git a/app/models/status.rb b/app/models/status.rb index 8d31fd382..3fee5b6f4 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -431,6 +431,14 @@ class Status < ApplicationRecord end end + def has_non_mention_links? + if local? + text.match? %r{https?://\w} + else + Nokogiri::HTML.fragment(text).css('a:not(.mention)').present? + end + end + private def update_status_stat!(attrs)