about summary refs log tree commit diff
path: root/app/services/remove_status_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/remove_status_service.rb')
-rw-r--r--app/services/remove_status_service.rb47
1 files changed, 26 insertions, 21 deletions
diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb
index a5aafee21..8025f235b 100644
--- a/app/services/remove_status_service.rb
+++ b/app/services/remove_status_service.rb
@@ -15,13 +15,13 @@ class RemoveStatusService < BaseService
     @status   = status
     @account  = status.account
     @tags     = status.tags.pluck(:name).to_a
-    @mentions = status.active_mentions.includes(:account).to_a
+    @mentions = status.mentions.includes(:account).to_a
     @reblogs  = status.reblogs.includes(:account).to_a
     @options  = options
 
     RedisLock.acquire(lock_options) do |lock|
       if lock.acquired?
-        remove_from_self if status.account.local?
+        remove_from_self if status.account.local? && !@options[:unpublish]
         remove_from_followers
         remove_from_lists
         remove_from_affected
@@ -30,10 +30,10 @@ class RemoveStatusService < BaseService
         remove_from_public
         remove_from_media if status.media_attachments.any?
         remove_from_direct if status.direct_visibility?
-        remove_from_spam_check
-        remove_media
+        remove_from_spam_check unless @options[:unpublish]
+        remove_media unless @options[:unpublish]
 
-        @status.destroy! if @options[:immediate] || !@status.reported?
+        @status.destroy! if @options[:immediate] || !((@options[:unpublish] && @status.local?) || @status.reported?)
       else
         raise Mastodon::RaceConditionError
       end
@@ -44,10 +44,17 @@ class RemoveStatusService < BaseService
     # original object being removed implicitly removes reblogs
     # of it. The Delete activity of the original is forwarded
     # separately.
-    return if !@account.local? || @options[:original_removed]
+    return if !@account.local? || @options[:original_removed] || !(status.published? || @options[:unpublished])
 
     remove_from_remote_followers
     remove_from_remote_affected
+
+    @status.mentions.where(account_id: @options[:blocking]).destroy_all if @options[:blocking]
+
+    return unless @options[:unpublish]
+
+    @status.update(published: false, expires_at: nil, local_only: @status.local?)
+    DistributionWorker.perform_async(@status.id) if @status.local?
   end
 
   private
@@ -98,6 +105,10 @@ class RemoveStatusService < BaseService
       [signed_activity_json, @account.id, inbox_url]
     end
 
+    ActivityPub::DeliveryWorker.push_bulk(@account.following.inboxes) do |inbox_url|
+      [signed_activity_json, @account.id, inbox_url]
+    end
+
     relay! if relayable?
   end
 
@@ -107,12 +118,12 @@ class RemoveStatusService < BaseService
 
   def relay!
     ActivityPub::DeliveryWorker.push_bulk(Relay.enabled.pluck(:inbox_url)) do |inbox_url|
-      [signed_activity_json, @account.id, inbox_url]
+      [signed_activity_json(Addressable::URI.parse(inbox_url).host), @account.id, inbox_url]
     end
   end
 
   def signed_activity_json
-    @signed_activity_json ||= Oj.dump(serialize_payload(@status, @status.reblog? ? ActivityPub::UndoAnnounceSerializer : ActivityPub::DeleteSerializer, signer: @account))
+    @signed_activity_json ||= Oj.dump(serialize_payload(@status, @status.reblog? && @status.spoiler_text.blank? ? ActivityPub::UndoAnnounceSerializer : ActivityPub::DeleteSerializer, signer: @account))
   end
 
   def remove_reblogs
@@ -130,7 +141,7 @@ class RemoveStatusService < BaseService
       featured_tag.decrement(@status.id)
     end
 
-    return unless @status.public_visibility?
+    return unless @status.distributable?
 
     @tags.each do |hashtag|
       redis.publish("timeline:hashtag:#{hashtag.mb_chars.downcase}", @payload)
@@ -139,25 +150,19 @@ class RemoveStatusService < BaseService
   end
 
   def remove_from_public
-    return unless @status.public_visibility?
+    return unless @status.distributable?
 
     redis.publish('timeline:public', @payload)
-    if @status.local?
-      redis.publish('timeline:public:local', @payload)
-    else
-      redis.publish('timeline:public:remote', @payload)
-    end
+    redis.publish('timeline:public:local', @payload) if @status.local?
+    redis.publish('timeline:public:remote', @payload)
   end
 
   def remove_from_media
-    return unless @status.public_visibility?
+    return unless @status.distributable?
 
     redis.publish('timeline:public:media', @payload)
-    if @status.local?
-      redis.publish('timeline:public:local:media', @payload)
-    else
-      redis.publish('timeline:public:remote:media', @payload)
-    end
+    redis.publish('timeline:public:local:media', @payload) if @status.local?
+    redis.publish('timeline:public:remote:media', @payload)
   end
 
   def remove_from_direct