mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-22 23:20:44 +01:00
[WiP] Add presenter and serializer to make use of shallow serializers
This commit is contained in:
parent
662ef2b85b
commit
43c9f0b5f2
2 changed files with 41 additions and 0 deletions
34
app/presenters/grouped_notifications_presenter.rb
Normal file
34
app/presenters/grouped_notifications_presenter.rb
Normal 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
|
|
@ -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
|
Loading…
Reference in a new issue