favourite.rb 692 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # frozen_string_literal: true
  2. class Favourite < ApplicationRecord
  3. include Paginable
  4. include Streamable
  5. belongs_to :account, inverse_of: :favourites
  6. belongs_to :status, inverse_of: :favourites, touch: true
  7. has_one :notification, as: :activity, dependent: :destroy
  8. validates :status_id, uniqueness: { scope: :account_id }
  9. def verb
  10. :favorite
  11. end
  12. def title
  13. "#{account.acct} favourited a status by #{status.account.acct}"
  14. end
  15. delegate :object_type, to: :target
  16. def thread
  17. status
  18. end
  19. def target
  20. thread
  21. end
  22. def hidden?
  23. status.private_visibility?
  24. end
  25. before_validation do
  26. self.status = status.reblog if status.reblog?
  27. end
  28. end