about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/lib/bangtags.rb26
-rw-r--r--app/models/status.rb32
-rw-r--r--app/services/post_status_service.rb1
3 files changed, 42 insertions, 17 deletions
diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb
index abc49aee9..44c2e5c75 100644
--- a/app/lib/bangtags.rb
+++ b/app/lib/bangtags.rb
@@ -762,19 +762,19 @@ class Bangtags
             unit = cmd[2].present? ? cmd[2].downcase : 'minutes'
           end
           defederate_after = case unit
-                         when 'm', 'min', 'mins', 'minute', 'minutes'
-                           i.minutes
-                         when 'h', 'hr', 'hrs', 'hour', 'hours'
-                           i.hours
-                         when 'd', 'dy', 'dys', 'day', 'days'
-                           i.days
-                         when 'w', 'wk', 'wks', 'week', 'weeks'
-                           i.weeks
-                         when 'mn', 'mns', 'month', 'months'
-                           i.months
-                         when 'y', 'yr', 'yrs', 'year', 'years'
-                           i.years
-                         end
+                             when 'm', 'min', 'mins', 'minute', 'minutes'
+                               i.minutes
+                             when 'h', 'hr', 'hrs', 'hour', 'hours'
+                               i.hours
+                             when 'd', 'dy', 'dys', 'day', 'days'
+                               i.days
+                             when 'w', 'wk', 'wks', 'week', 'weeks'
+                               i.weeks
+                             when 'mn', 'mns', 'month', 'months'
+                               i.months
+                             when 'y', 'yr', 'yrs', 'year', 'years'
+                               i.years
+                             end
           if s == :thread
             @parent_status.conversation.statuses.where(account_id: @account.id).find_each do |s|
               s.defederate_after = defederate_after
diff --git a/app/models/status.rb b/app/models/status.rb
index 6ab33c9b4..5954e7868 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -285,15 +285,25 @@ class Status < ApplicationRecord
   end
 
   def delete_after=(value)
+    @no_clobber_expirations = true
+
+    if value.to_i == 0
+      DestructingStatus.where(status_id: id).destroy_all
+      return
+    end
+
     if defederate_after && defederate_after < (Time.now.utc + 5.minutes + value)
       value = 5.minutes + value
     end
 
+    delete_after = Time.now.utc + value
     if destructing_status.nil?
-      DestructingStatus.create!(status_id: id, delete_after: Time.now.utc + value)
+      DestructingStatus.create!(status_id: id, delete_after: delete_after)
     else
-      destructing_status.update(delete_after: Time.now.utc + value)
+      destructing_status.update(delete_after: delete_after)
     end
+
+    delete_after
   end
 
   def defederate_after
@@ -301,13 +311,27 @@ class Status < ApplicationRecord
   end
 
   def defederate_after=(value)
+    @no_clobber_expirations = true
+
+    if value.to_i == 0
+      DefederatingStatus.where(status_id: id).destroy_all
+      return
+    end
+
     return unless delete_after.nil? || delete_after >= (Time.now.utc + 5.minutes + value)
 
+    defederate_after = Time.now.utc + value
     if defederating_status.nil?
-      DefederatingStatus.create!(status_id: id, defederate_after: Time.now.utc + value)
+      DefederatingStatus.create!(status_id: id, defederate_after: defederate_after)
     else
-      defederating_status.update(defederate_after: Time.now.utc + value)
+      defederating_status.update(defederate_after: defederate_after)
     end
+
+    defederate_after
+  end
+
+  def no_clobber_expirations?
+    @no_clobber_expirations || false
   end
 
   def mark_for_mass_destruction!
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index baf45eda6..2a065f58b 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -279,6 +279,7 @@ class PostStatusService < BaseService
   end
 
   def set_expirations
+    return if @status.no_clobber_expirations?
     @status.delete_after = @delete_after if @delete_after && @status.delete_after.nil?
     @status.defederate_after = @defederate_after if @defederate_after && @status.defederate_after.nil?
   end