diff options
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/post_status_service.rb | 15 | ||||
-rw-r--r-- | app/services/remove_status_service.rb | 37 |
2 files changed, 36 insertions, 16 deletions
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index dc1a3bcdc..8a1ca3eca 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -30,6 +30,7 @@ class PostStatusService < BaseService # @option [String] :language # @option [String] :scheduled_at # @option [String] :delete_after + # @option [String] :defederate_after # @option [Account] :mentions Optional accounts to mention out-of-body # @option [Boolean] :noreplies Author does not accept replies # @option [Boolean] :nocrawl Optional skip link card generation @@ -76,6 +77,7 @@ class PostStatusService < BaseService distribute: @options[:distribute], nocrawl: @options[:nocrawl], delete_after: @delete_after.nil? ? nil : @delete_after + 1.minute, + defederate_after: @defederate_after.nil? ? nil : @defederate_after + 1.minute, reject_replies: @options[:noreplies] || false, }.compact @@ -201,6 +203,18 @@ class PostStatusService < BaseService end @delete_after = nil if @delete_after.present? && (@delete_after < MIN_DESTRUCT_OFFSET) + case @options[:defederate_after].class + when NilClass + @defederate_after = @account.user.setting_roar_defederate.to_i.days + when ActiveSupport::Duration + @defederate_after = @options[:defederate_after] + when Integer + @defederate_after = @options[:defederate_after].minutes + when Float + @defederate_after = @options[:defederate_after].minutes + end + @defederate_after = nil if @defederate_after.present? && (@defederate_after < MIN_DESTRUCT_OFFSET) + rescue ArgumentError raise ActiveRecord::RecordInvalid end @@ -310,6 +324,7 @@ class PostStatusService < BaseService visibility: @visibility, local_only: @local_only, delete_after: @delete_after, + defederate_after: @defederate_after, reject_replies: @options[:noreplies] || false, sharekey: @options[:sharekey], language: language_from_option(@options[:language]) || @account.user_default_language&.presence || 'en', diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb index 20648217d..797794a19 100644 --- a/app/services/remove_status_service.rb +++ b/app/services/remove_status_service.rb @@ -16,22 +16,24 @@ class RemoveStatusService < BaseService @stream_entry = status.stream_entry @options = options - RedisLock.acquire(lock_options) do |lock| - if lock.acquired? - remove_from_queued - remove_from_self if status.account.local? - remove_from_followers - remove_from_lists - remove_from_affected - remove_reblogs - remove_from_hashtags - remove_from_public - remove_from_media if status.media_attachments.any? - remove_from_direct if status.direct_visibility? - - @status.destroy! - else - raise Mastodon::RaceConditionError + unless options[:defederate_only] + RedisLock.acquire(lock_options) do |lock| + if lock.acquired? + remove_from_queued + remove_from_self if status.account.local? + remove_from_followers + remove_from_lists + remove_from_affected + remove_reblogs + remove_from_hashtags + remove_from_public + remove_from_media if status.media_attachments.any? + remove_from_direct if status.direct_visibility? + + @status.destroy! + else + raise Mastodon::RaceConditionError + end end end @@ -44,6 +46,9 @@ class RemoveStatusService < BaseService remove_from_remote_followers remove_from_remote_affected + + @status.update(local_only: true) if options[:defederate_only] + Rails.cache.delete("statuses/#{@status.id}") end private |