2024-06-03 18:35:59 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class REST::NotificationGroupSerializer < ActiveModel::Serializer
|
2024-06-14 20:33:06 +10:00
|
|
|
attributes :group_key, :notifications_count, :type, :most_recent_notification_id
|
2024-06-03 18:35:59 +10:00
|
|
|
|
|
|
|
attribute :page_min_id, if: :paginated?
|
|
|
|
attribute :page_max_id, if: :paginated?
|
|
|
|
attribute :latest_page_notification_at, if: :paginated?
|
|
|
|
|
|
|
|
has_many :sample_accounts, serializer: REST::AccountSerializer
|
|
|
|
belongs_to :target_status, key: :status, if: :status_type?, serializer: REST::StatusSerializer
|
|
|
|
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-07 00:12:06 +10:00
|
|
|
belongs_to :account_warning, key: :moderation_warning, if: :moderation_warning_event?, serializer: REST::AccountWarningSerializer
|
2024-06-03 18:35:59 +10: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-07 00:12:06 +10:00
|
|
|
def moderation_warning_event?
|
|
|
|
object.type == :moderation_warning
|
|
|
|
end
|
|
|
|
|
2024-06-03 18:35:59 +10:00
|
|
|
def page_min_id
|
|
|
|
range = instance_options[:group_metadata][object.group_key]
|
|
|
|
range.present? ? range[:min_id].to_s : object.notification.id.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def page_max_id
|
|
|
|
range = instance_options[:group_metadata][object.group_key]
|
|
|
|
range.present? ? range[:max_id].to_s : object.notification.id.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def latest_page_notification_at
|
|
|
|
range = instance_options[:group_metadata][object.group_key]
|
|
|
|
range.present? ? range[:latest_notification_at] : object.notification.created_at
|
|
|
|
end
|
|
|
|
|
|
|
|
def paginated?
|
2024-06-14 00:10:34 +10:00
|
|
|
!instance_options[:group_metadata].nil?
|
2024-06-03 18:35:59 +10:00
|
|
|
end
|
|
|
|
end
|