notification_serializer.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # frozen_string_literal: true
  2. class REST::NotificationSerializer < ActiveModel::Serializer
  3. # Please update app/javascript/api_types/notification.ts when making changes to the attributes
  4. attributes :id, :type, :created_at, :group_key
  5. attribute :filtered, if: :filtered?
  6. belongs_to :from_account, key: :account, serializer: REST::AccountSerializer
  7. belongs_to :target_status, key: :status, if: :status_type?, serializer: REST::StatusSerializer
  8. belongs_to :report, if: :report_type?, serializer: REST::ReportSerializer
  9. belongs_to :account_relationship_severance_event, key: :event, if: :relationship_severance_event?, serializer: REST::AccountRelationshipSeveranceEventSerializer
  10. belongs_to :account_warning, key: :moderation_warning, if: :moderation_warning_event?, serializer: REST::AccountWarningSerializer
  11. def id
  12. object.id.to_s
  13. end
  14. def group_key
  15. object.group_key || "ungrouped-#{object.id}"
  16. end
  17. def status_type?
  18. [:favourite, :reblog, :status, :mention, :poll, :update].include?(object.type)
  19. end
  20. def report_type?
  21. object.type == :'admin.report'
  22. end
  23. def relationship_severance_event?
  24. object.type == :severed_relationships
  25. end
  26. def moderation_warning_event?
  27. object.type == :moderation_warning
  28. end
  29. delegate :filtered?, to: :object
  30. end