notification_serializer.rb 591 B

123456789101112131415161718192021
  1. # frozen_string_literal: true
  2. class REST::NotificationSerializer < ActiveModel::Serializer
  3. attributes :id, :type, :created_at
  4. belongs_to :from_account, key: :account, serializer: REST::AccountSerializer
  5. belongs_to :target_status, key: :status, if: :status_type?, serializer: REST::StatusSerializer
  6. belongs_to :report, if: :report_type?, serializer: REST::ReportSerializer
  7. def id
  8. object.id.to_s
  9. end
  10. def status_type?
  11. [:favourite, :reblog, :status, :mention, :poll, :update].include?(object.type)
  12. end
  13. def report_type?
  14. object.type == :'admin.report'
  15. end
  16. end