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.

44 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. class Notification < ApplicationRecord
  3. include Paginable
  4. belongs_to :account
  5. belongs_to :activity, polymorphic: true
  6. belongs_to :mention, foreign_type: 'Mention', foreign_key: 'activity_id'
  7. belongs_to :status, foreign_type: 'Status', foreign_key: 'activity_id'
  8. belongs_to :follow, foreign_type: 'Follow', foreign_key: 'activity_id'
  9. belongs_to :favourite, foreign_type: 'Favourite', foreign_key: 'activity_id'
  10. STATUS_INCLUDES = [:account, :media_attachments, mentions: :account, reblog: [:account, mentions: :account]].freeze
  11. scope :with_includes, -> { includes(status: STATUS_INCLUDES, mention: [status: STATUS_INCLUDES], favourite: [:account, status: STATUS_INCLUDES], follow: :account) }
  12. def type
  13. case activity_type
  14. when 'Status'
  15. :reblog
  16. else
  17. activity_type.downcase.to_sym
  18. end
  19. end
  20. def from_account
  21. case type
  22. when :mention
  23. activity.status.account
  24. when :follow, :favourite, :reblog
  25. activity.account
  26. end
  27. end
  28. def target_status
  29. case type
  30. when :reblog
  31. activity.reblog
  32. when :favourite, :mention
  33. activity.status
  34. end
  35. end
  36. end