diff options
author | multiple creatures <dev@multiple-creature.party> | 2020-01-13 22:46:02 -0600 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2020-01-13 22:46:02 -0600 |
commit | 0b2b252c6f2e816a67d121a132e8b6fae9b5a3d8 (patch) | |
tree | 2f3a1a8fcaeb32715ef537ba8645c38569c4c667 | |
parent | 67516a07db44196cc4bb94bf94abe5c6f611cf07 (diff) |
fix setting `delete_after` and `defederate_after` on new posts
-rw-r--r-- | app/services/post_status_service.rb | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 8a1ca3eca..bf079d0b8 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -54,6 +54,10 @@ class PostStatusService < BaseService @preloaded_tags = @options[:preloaded_tags] || [] @preloaded_mentions = @options[:preloaded_mentions] || [] + @is_delayed = @options[:delayed].present? || @account&.user&.delayed_roars? + @delay_for = @is_delayed ? [5, @account&.user&.delayed_for.to_i].max : 1 + @delay_until = Time.now.utc + @delay_for.seconds + raise Mastodon::LengthValidationError, I18n.t('statuses.replies_rejected') if recipient_rejects_replies? raise Mastodon::LengthValidationError, I18n.t('statuses.kicked') if kicked? @@ -67,9 +71,6 @@ class PostStatusService < BaseService else return unless process_status! - is_delayed = @options[:delayed].present? || @account&.user&.delayed_roars? - delay_for = is_delayed ? [5, @account&.user&.delayed_for.to_i].max : 1 - delay_until = Time.now.utc + delay_for.seconds opts = { visibility: @visibility, local_only: @local_only, @@ -81,7 +82,7 @@ class PostStatusService < BaseService reject_replies: @options[:noreplies] || false, }.compact - PostStatusWorker.perform_at(delay_until, @status.id, opts) + PostStatusWorker.perform_at(@delay_until, @status.id, opts) DistributionWorker.perform_async(@status.id, delayed = true) unless @options[:distribute] == false end @@ -192,29 +193,30 @@ class PostStatusService < BaseService @scheduled_at = nil if scheduled_in_the_past? case @options[:delete_after].class - when NilClass - @delete_after = @account.user.setting_roar_lifespan.to_i.days when ActiveSupport::Duration @delete_after = @options[:delete_after] when Integer @delete_after = @options[:delete_after].minutes when Float @delete_after = @options[:delete_after].minutes + else + @delete_after = @account.user.roar_lifespan.days end @delete_after = nil if @delete_after.present? && (@delete_after < MIN_DESTRUCT_OFFSET) + @delete_after += @delay_for.seconds if @delete_after && @is_delayed 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 + else + @defederate_after = @account.user.roar_defederate.days end @defederate_after = nil if @defederate_after.present? && (@defederate_after < MIN_DESTRUCT_OFFSET) - + @defederate_after += @delay_for.seconds if @defederate_after && @is_delayed rescue ArgumentError raise ActiveRecord::RecordInvalid end @@ -229,6 +231,7 @@ class PostStatusService < BaseService return false if @status.destroyed? + set_expirations process_hashtags_service.call(@status, @tags, @preloaded_tags) process_mentions true @@ -275,6 +278,11 @@ class PostStatusService < BaseService ISO_639.find(str)&.alpha2 end + def set_expirations + @status.delete_after = @delete_after if @delete_after + @status.defederate_after = @defederate_after if @defederate_after + end + def process_hashtags_service ProcessHashtagsService.new end @@ -323,8 +331,6 @@ class PostStatusService < BaseService spoiler_text: @options[:spoiler_text] || '', 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', |