mirror of
https://github.com/mastodon/mastodon.git
synced 2025-02-06 15:05:07 +00:00
efc85e39a0
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
41 lines
1.2 KiB
Ruby
41 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: scheduled_statuses
|
|
#
|
|
# id :bigint(8) not null, primary key
|
|
# params :jsonb
|
|
# scheduled_at :datetime
|
|
# account_id :bigint(8) not null
|
|
#
|
|
|
|
class ScheduledStatus < ApplicationRecord
|
|
include Paginable
|
|
|
|
TOTAL_LIMIT = 300
|
|
DAILY_LIMIT = 25
|
|
MINIMUM_OFFSET = 5.minutes.freeze
|
|
|
|
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 + MINIMUM_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
|