notification_group_serializer.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # frozen_string_literal: true
  2. class REST::NotificationGroupSerializer < ActiveModel::Serializer
  3. # Please update app/javascript/api_types/notification.ts when making changes to the attributes
  4. attributes :group_key, :notifications_count, :type, :most_recent_notification_id
  5. attribute :page_min_id, if: :paginated?
  6. attribute :page_max_id, if: :paginated?
  7. attribute :latest_page_notification_at, if: :paginated?
  8. attribute :sample_account_ids
  9. attribute :status_id, if: :status_type?
  10. belongs_to :report, if: :report_type?, serializer: REST::ReportSerializer
  11. belongs_to :account_relationship_severance_event, key: :event, if: :relationship_severance_event?, serializer: REST::AccountRelationshipSeveranceEventSerializer
  12. belongs_to :account_warning, key: :moderation_warning, if: :moderation_warning_event?, serializer: REST::AccountWarningSerializer
  13. belongs_to :generated_annual_report, key: :annual_report, if: :annual_report_event?, serializer: REST::AnnualReportEventSerializer
  14. def sample_account_ids
  15. object.sample_accounts.pluck(:id).map(&:to_s)
  16. end
  17. def status_id
  18. object.target_status&.id&.to_s
  19. end
  20. def status_type?
  21. [:favourite, :reblog, :status, :mention, :poll, :update].include?(object.type)
  22. end
  23. def report_type?
  24. object.type == :'admin.report'
  25. end
  26. def relationship_severance_event?
  27. object.type == :severed_relationships
  28. end
  29. def moderation_warning_event?
  30. object.type == :moderation_warning
  31. end
  32. def annual_report_event?
  33. object.type == :annual_report
  34. end
  35. def page_min_id
  36. object.pagination_data[:min_id].to_s
  37. end
  38. def page_max_id
  39. object.most_recent_notification_id.to_s
  40. end
  41. def latest_page_notification_at
  42. object.pagination_data[:latest_notification_at]
  43. end
  44. def paginated?
  45. object.pagination_data.present?
  46. end
  47. end