Merge remote-tracking branch 'origin/kb_development' into kb_migration
This commit is contained in:
commit
0071b15fa3
18 changed files with 455 additions and 2 deletions
|
@ -19,6 +19,7 @@ module AccountAssociations
|
|||
has_many :notifications, inverse_of: :account, dependent: :destroy
|
||||
has_many :conversations, class_name: 'AccountConversation', dependent: :destroy, inverse_of: :account
|
||||
has_many :scheduled_statuses, inverse_of: :account, dependent: :destroy
|
||||
has_many :scheduled_expiration_statuses, inverse_of: :account, dependent: :destroy
|
||||
|
||||
# Pinned statuses
|
||||
has_many :status_pins, inverse_of: :account, dependent: :destroy
|
||||
|
|
36
app/models/scheduled_expiration_status.rb
Normal file
36
app/models/scheduled_expiration_status.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: scheduled_expiration_statuses
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# status_id :bigint(8) not null
|
||||
# scheduled_at :datetime
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class ScheduledExpirationStatus < ApplicationRecord
|
||||
include Paginable
|
||||
|
||||
TOTAL_LIMIT = 300
|
||||
DAILY_LIMIT = 25
|
||||
|
||||
belongs_to :account, inverse_of: :scheduled_expiration_statuses
|
||||
belongs_to :status, inverse_of: :scheduled_expiration_status
|
||||
|
||||
validate :validate_total_limit
|
||||
validate :validate_daily_limit
|
||||
|
||||
private
|
||||
|
||||
def validate_total_limit
|
||||
errors.add(:base, I18n.t('scheduled_expiration_statuses.over_total_limit', limit: TOTAL_LIMIT)) if account.scheduled_expiration_statuses.count >= TOTAL_LIMIT
|
||||
end
|
||||
|
||||
def validate_daily_limit
|
||||
errors.add(:base, I18n.t('scheduled_expiration_statuses.over_daily_limit', limit: DAILY_LIMIT)) if account.scheduled_expiration_statuses.where('scheduled_at::date = ?::date', scheduled_at).count >= DAILY_LIMIT
|
||||
end
|
||||
end
|
|
@ -81,6 +81,7 @@ class Status < ApplicationRecord
|
|||
has_one :status_stat, inverse_of: :status
|
||||
has_one :poll, inverse_of: :status, dependent: :destroy
|
||||
has_one :trend, class_name: 'StatusTrend', inverse_of: :status
|
||||
has_one :scheduled_expiration_status, inverse_of: :status, dependent: :destroy
|
||||
|
||||
validates :uri, uniqueness: true, presence: true, unless: :local?
|
||||
validates :text, presence: true, unless: -> { with_media? || reblog? }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue