diff options
author | multiple creatures <dev@multiple-creature.party> | 2020-01-15 16:42:43 -0600 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2020-01-15 16:42:43 -0600 |
commit | d8b87ec487463f548363cc861d0000b2016dd899 (patch) | |
tree | e1fccffa7616147836db57477b4a9e52c5fe42d1 /app/models | |
parent | f49ff8fccc26cd8a157f50c2c30a1a30e33f30ee (diff) |
handle passing `0` to `lifespan` & `defed_in` bangtags to unset the auto-destruct/auto-defederate flag for a post
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/status.rb | 32 |
1 files changed, 28 insertions, 4 deletions
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! |