diff options
author | pluralcafe-docker <git@plural.cafe> | 2019-01-12 04:24:01 +0000 |
---|---|---|
committer | pluralcafe-docker <git@plural.cafe> | 2019-01-12 04:24:01 +0000 |
commit | a6e0ff72f552dc172c18f5a10bbca071b067ab51 (patch) | |
tree | f845d5a7e328c3babfde43066325262c1dbdbed0 /app/models/scheduled_status.rb | |
parent | 74134e490c49d8a7d88cc69720e22cd88cee9233 (diff) | |
parent | 2cfa55185a5fc7d93a160a4e9a4730aae6725b0f (diff) |
Merge branch 'glitch' into production
Diffstat (limited to 'app/models/scheduled_status.rb')
-rw-r--r-- | app/models/scheduled_status.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/models/scheduled_status.rb b/app/models/scheduled_status.rb new file mode 100644 index 000000000..27f0cbd28 --- /dev/null +++ b/app/models/scheduled_status.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: scheduled_statuses +# +# id :bigint(8) not null, primary key +# account_id :bigint(8) +# scheduled_at :datetime +# params :jsonb +# + +class ScheduledStatus < ApplicationRecord + include Paginable + + TOTAL_LIMIT = 300 + DAILY_LIMIT = 25 + + belongs_to :account, inverse_of: :scheduled_statuses + has_many :media_attachments, inverse_of: :scheduled_status, dependent: :nullify + + validate :validate_future_date + validate :validate_total_limit + validate :validate_daily_limit + + private + + def validate_future_date + errors.add(:scheduled_at, I18n.t('scheduled_statuses.too_soon')) if scheduled_at.present? && scheduled_at <= Time.now.utc + PostStatusService::MIN_SCHEDULE_OFFSET + end + + def validate_total_limit + errors.add(:base, I18n.t('scheduled_statuses.over_total_limit', limit: TOTAL_LIMIT)) if account.scheduled_statuses.count >= TOTAL_LIMIT + end + + def validate_daily_limit + errors.add(:base, I18n.t('scheduled_statuses.over_daily_limit', limit: DAILY_LIMIT)) if account.scheduled_statuses.where('scheduled_at::date = ?::date', scheduled_at).count >= DAILY_LIMIT + end +end |