2024-06-03 17:35:59 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class REST::NotificationGroupSerializer < ActiveModel::Serializer
|
2024-07-18 23:36:09 +09:00
|
|
|
# Please update app/javascript/api_types/notification.ts when making changes to the attributes
|
2024-06-14 19:33:06 +09:00
|
|
|
attributes :group_key, :notifications_count, :type, :most_recent_notification_id
|
2024-06-03 17:35:59 +09:00
|
|
|
|
|
|
|
attribute :page_min_id, if: :paginated?
|
|
|
|
attribute :page_max_id, if: :paginated?
|
|
|
|
attribute :latest_page_notification_at, if: :paginated?
|
|
|
|
|
2024-07-31 19:50:13 +09:00
|
|
|
attribute :sample_account_ids
|
|
|
|
attribute :status_id, if: :status_type?
|
2024-06-03 17:35:59 +09:00
|
|
|
belongs_to :report, if: :report_type?, serializer: REST::ReportSerializer
|
|
|
|
belongs_to :account_relationship_severance_event, key: :event, if: :relationship_severance_event?, serializer: REST::AccountRelationshipSeveranceEventSerializer
|
2024-06-06 23:12:06 +09:00
|
|
|
belongs_to :account_warning, key: :moderation_warning, if: :moderation_warning_event?, serializer: REST::AccountWarningSerializer
|
2024-06-03 17:35:59 +09:00
|
|
|
|
2024-07-31 19:50:13 +09:00
|
|
|
def sample_account_ids
|
|
|
|
object.sample_accounts.pluck(:id).map(&:to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
def status_id
|
|
|
|
object.target_status&.id&.to_s
|
|
|
|
end
|
|
|
|
|
2024-06-03 17:35:59 +09:00
|
|
|
def status_type?
|
|
|
|
[:favourite, :reblog, :status, :mention, :poll, :update].include?(object.type)
|
|
|
|
end
|
|
|
|
|
|
|
|
def report_type?
|
|
|
|
object.type == :'admin.report'
|
|
|
|
end
|
|
|
|
|
|
|
|
def relationship_severance_event?
|
|
|
|
object.type == :severed_relationships
|
|
|
|
end
|
|
|
|
|
2024-06-06 23:12:06 +09:00
|
|
|
def moderation_warning_event?
|
|
|
|
object.type == :moderation_warning
|
|
|
|
end
|
|
|
|
|
2024-06-03 17:35:59 +09:00
|
|
|
def page_min_id
|
2024-09-02 18:56:00 +09:00
|
|
|
object.pagination_data[:min_id].to_s
|
2024-06-03 17:35:59 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def page_max_id
|
2024-09-02 18:56:00 +09:00
|
|
|
object.most_recent_notification_id.to_s
|
2024-06-03 17:35:59 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def latest_page_notification_at
|
2024-09-02 18:56:00 +09:00
|
|
|
object.pagination_data[:latest_notification_at]
|
2024-06-03 17:35:59 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def paginated?
|
2024-09-02 18:56:00 +09:00
|
|
|
object.pagination_data.present?
|
2024-06-03 17:35:59 +09:00
|
|
|
end
|
|
|
|
end
|