Add option to request partial accounts in grouped notifications API (#31299)
This commit is contained in:
parent
5d890ebc57
commit
438dac99d6
4 changed files with 88 additions and 9 deletions
|
@ -1,10 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class GroupedNotificationsPresenter < ActiveModelSerializers::Model
|
||||
def initialize(grouped_notifications)
|
||||
def initialize(grouped_notifications, options = {})
|
||||
super()
|
||||
|
||||
@grouped_notifications = grouped_notifications
|
||||
@options = options
|
||||
end
|
||||
|
||||
def notification_groups
|
||||
|
@ -16,6 +17,28 @@ class GroupedNotificationsPresenter < ActiveModelSerializers::Model
|
|||
end
|
||||
|
||||
def accounts
|
||||
@grouped_notifications.flat_map(&:sample_accounts).uniq(&:id)
|
||||
@accounts ||= begin
|
||||
if partial_avatars?
|
||||
@grouped_notifications.map { |group| group.sample_accounts.first }.uniq(&:id)
|
||||
else
|
||||
@grouped_notifications.flat_map(&:sample_accounts).uniq(&:id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def partial_accounts
|
||||
@partial_accounts ||= begin
|
||||
if partial_avatars?
|
||||
@grouped_notifications.flat_map { |group| group.sample_accounts[1...] }.uniq(&:id).filter { |account| accounts.exclude?(account) }
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def partial_avatars?
|
||||
@options[:expand_accounts] == 'partial_avatars'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue