about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-08-23 13:00:34 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:20 -0500
commitb4d7ef9f2a24fe26fe47722d1742ae9a30739d2e (patch)
tree6e9e2ca90a78ae6f95fc3ba83922879c9ecc1c34
parent1d71987d13a48b23f50836f2edc2277a9f1d2773 (diff)
[Federation] Filter Twitter crossposter retweets
-rw-r--r--app/lib/activitypub/activity/create.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb
index 9ab60107b..0303b236f 100644
--- a/app/lib/activitypub/activity/create.rb
+++ b/app/lib/activitypub/activity/create.rb
@@ -46,7 +46,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
   end
 
   def create_status
-    return reject_payload! if unsupported_object_type? || invalid_origin?(object_uri) || Tombstone.exists?(uri: object_uri)
+    return reject_payload! if unsupported_object_type? || invalid_origin?(object_uri) || Tombstone.exists?(uri: object_uri) || twitter_retweet?
 
     RedisLock.acquire(lock_options) do |lock|
       if lock.acquired?
@@ -504,13 +504,18 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
     @reblog_uri = @object['reblog'].presence || @object['_misskey_quote'].presence
   end
 
+  def twitter_retweet?
+    text_from_content.present? && (text_from_content.include?('<p>🐦🔗') || text_from_content.include?('<p>RT @'))
+  end
+
   def text_from_content
-    return Formatter.instance.linkify([[text_from_name, text_from_summary.presence].compact.join("\n\n"), object_url || object_uri].join(' ')) if converted_object_type?
+    return @status_text if defined?(@status_text)
+    return @status_text = Formatter.instance.linkify([[text_from_name, text_from_summary.presence].compact.join("\n\n"), object_url || object_uri].join(' ')) if converted_object_type?
 
     if @object['content'].present?
-      @object['type'] == 'Article' ? Formatter.instance.format_article(@object['content']) : @object['content']
+      @status_text = @object['type'] == 'Article' ? Formatter.instance.format_article(@object['content']) : @object['content']
     elsif content_language_map?
-      @object['contentMap'].values.first
+      @status_text = @object['contentMap'].values.first
     end
   end