From 3862f48c34a00691a12c6002abd88b088cf7c13e Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Tue, 23 Jul 2019 16:48:08 -0500 Subject: add self-destructing roars & `live`/`lifespan` bangtags --- app/models/account.rb | 1 + app/models/destructing_status.rb | 20 ++++++++++++++++++++ app/models/status.rb | 13 +++++++++++++ app/models/user.rb | 5 +++++ 4 files changed, 39 insertions(+) create mode 100644 app/models/destructing_status.rb (limited to 'app/models') diff --git a/app/models/account.rb b/app/models/account.rb index 1955b7aee..068b5e7a0 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -133,6 +133,7 @@ class Account < ApplicationRecord :defaults_to_local_only?, :always_local_only?, :max_public_history, + :roar_lifespan, :hides_public_profile?, :hides_public_outbox?, diff --git a/app/models/destructing_status.rb b/app/models/destructing_status.rb new file mode 100644 index 000000000..349e276cb --- /dev/null +++ b/app/models/destructing_status.rb @@ -0,0 +1,20 @@ +# == Schema Information +# +# Table name: destructing_statuses +# +# id :bigint(8) not null, primary key +# status_id :bigint(8) +# delete_after :datetime +# + +class DestructingStatus < ApplicationRecord + belongs_to :status, inverse_of: :destructing_status + + validate :validate_future_date + + private + + def validate_future_date + errors.add(:delete_after, I18n.t('destructing_statuses.too_soon')) if delete_after.present? && delete_after < Time.now.utc + PostStatusService::MIN_DESTRUCT_OFFSET + end +end diff --git a/app/models/status.rb b/app/models/status.rb index ec492293f..946958758 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -79,6 +79,7 @@ class Status < ApplicationRecord has_one :stream_entry, as: :activity, inverse_of: :status has_one :status_stat, inverse_of: :status has_one :poll, inverse_of: :status, dependent: :destroy + has_one :destructing_status, inverse_of: :status, dependent: :destroy validates :uri, uniqueness: true, presence: true, unless: :local? validates :text, presence: true, unless: -> { with_media? || reblog? } @@ -266,6 +267,18 @@ class Status < ApplicationRecord @chat_tags = tags.only_chat end + def delete_after + destructing_status&.delete_after + end + + def delete_after=(value) + if destructing_status.nil? + DestructingStatus.create!(status_id: id, delete_after: Time.now.utc + value) + else + destructing_status.delete_after = Time.now.utc + value + end + end + def mark_for_mass_destruction! @marked_for_mass_destruction = true end diff --git a/app/models/user.rb b/app/models/user.rb index 1d06a43f8..2f01c2e5a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -125,6 +125,7 @@ class User < ApplicationRecord :hide_public_profile, :hide_public_outbox, :max_public_history, + :roar_lifespan, :auto_play_gif, :default_sensitive, @@ -299,6 +300,10 @@ class User < ApplicationRecord @_max_public_history ||= (settings.max_public_history || 6) end + def roar_lifespan + @_roar_lifespan ||= (settings.roar_lifespan || 0) + end + def defaults_to_local_only? @defaults_to_local_only ||= (settings.default_local || false) end -- cgit