bookmark.rb 885 B

1234567891011121314151617181920212223242526272829303132333435
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: bookmarks
  5. #
  6. # id :bigint(8) not null, primary key
  7. # account_id :bigint(8) not null
  8. # status_id :bigint(8) not null
  9. # created_at :datetime not null
  10. # updated_at :datetime not null
  11. #
  12. class Bookmark < ApplicationRecord
  13. include Paginable
  14. update_index('statuses', :status) if Chewy.enabled?
  15. belongs_to :account, inverse_of: :bookmarks
  16. belongs_to :status, inverse_of: :bookmarks
  17. validates :status_id, uniqueness: { scope: :account_id }
  18. before_validation do
  19. self.status = status.reblog if status&.reblog?
  20. end
  21. after_destroy :invalidate_cleanup_info
  22. def invalidate_cleanup_info
  23. return unless status&.account_id == account_id && account.local?
  24. account.statuses_cleanup_policy&.invalidate_last_inspected(status, :unbookmark)
  25. end
  26. end