about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/activitypub/activity.rb7
-rw-r--r--app/lib/formatter.rb11
2 files changed, 16 insertions, 2 deletions
diff --git a/app/lib/activitypub/activity.rb b/app/lib/activitypub/activity.rb
index 2b5d3ffc2..85a3370ee 100644
--- a/app/lib/activitypub/activity.rb
+++ b/app/lib/activitypub/activity.rb
@@ -98,7 +98,7 @@ class ActivityPub::Activity
     crawl_links(status)
 
     notify_about_reblog(status) if reblog_of_local_account?(status) && !reblog_by_following_group_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
@@ -117,6 +117,11 @@ class ActivityPub::Activity
     status.reblog? && status.account.group? && status.reblog.account.following?(status.account)
   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, :reblog, status)
   end
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index 7f217ae9f..e0e5012de 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -267,8 +267,9 @@ class Formatter
 
   def link_to_mention(entity, linkable_accounts)
     acct = entity[:screen_name]
+    username, domain = acct.split('@')
 
-    return link_to_account(acct) unless linkable_accounts
+    return link_to_account(acct) unless linkable_accounts and domain != "twitter.com"
 
     account = linkable_accounts.find { |item| TagManager.instance.same_acct?(item.acct, acct) }
     account ? mention_html(account) : "@#{encode(acct)}"
@@ -277,6 +278,10 @@ class Formatter
   def link_to_account(acct)
     username, domain = acct.split('@')
 
+    if domain == "twitter.com"
+      return mention_twitter_html(username)
+    end
+
     domain  = nil if TagManager.instance.local_domain?(domain)
     account = EntityCache.instance.mention(username, domain)
 
@@ -304,4 +309,8 @@ class Formatter
   def mention_html(account)
     "<span class=\"h-card\"><a href=\"#{encode(ActivityPub::TagManager.instance.url_for(account))}\" class=\"u-url mention\">@<span>#{encode(account.username)}</span></a></span>"
   end
+
+  def mention_twitter_html(username)
+      "<span class=\"h-card\"><a href=\"https://twitter.com/#{username}\" class=\"u-url mention\">@<span>#{username}@twitter.com</span></a></span>"
+  end
 end