[WiP] Add presenter and serializer to make use of shallow serializers

This commit is contained in:
Claire 2024-07-30 14:27:24 +02:00
parent 662ef2b85b
commit 43c9f0b5f2
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,34 @@
# frozen_string_literal: true
class GroupedNotificationsPresenter < ActiveModelSerializers::Model
def initialize(grouped_notifications)
super()
@grouped_notifications = grouped_notifications
end
def notification_groups
@grouped_notifications
end
def statuses
@grouped_notifications.filter_map(&:target_status)
end
def accounts
@grouped_notifications.flat_map do |group|
accounts = group.sample_accounts.dup
case group.type
when :favourite, :reblog, :status, :mention, :poll, :update
accounts << group.target_status&.account
when :'admin.report'
accounts << group.report&.target_account
when :moderation_warning
accounts << group.account_warning&.target_account
end
accounts.compact
end.uniq(&:id)
end
end

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
class REST::DedupNotificationGroupSerializer < ActiveModel::Serializer
has_many :accounts, serializer: REST::Shallow::AccountSerializer
has_many :statuses, serializer: REST::Shallow::StatusSerializer
has_many :notification_groups, serializer: REST::Shallow::NotificationGroupSerializer
end