You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.0 KiB

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: lists
  5. #
  6. # id :bigint(8) not null, primary key
  7. # account_id :bigint(8) not null
  8. # title :string default(""), not null
  9. # created_at :datetime not null
  10. # updated_at :datetime not null
  11. # replies_policy :integer default("list"), not null
  12. #
  13. class List < ApplicationRecord
  14. include Paginable
  15. PER_ACCOUNT_LIMIT = 50
  16. enum replies_policy: [:list, :followed, :none], _prefix: :show
  17. belongs_to :account, optional: true
  18. has_many :list_accounts, inverse_of: :list, dependent: :destroy
  19. has_many :accounts, through: :list_accounts
  20. validates :title, presence: true
  21. validates_each :account_id, on: :create do |record, _attr, value|
  22. record.errors.add(:base, I18n.t('lists.errors.limit')) if List.where(account_id: value).count >= PER_ACCOUNT_LIMIT
  23. end
  24. before_destroy :clean_feed_manager
  25. private
  26. def clean_feed_manager
  27. FeedManager.instance.clean_feeds!(:list, [id])
  28. end
  29. end