2024-07-31 03:50:13 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class GroupedNotificationsPresenter < ActiveModelSerializers::Model
|
2024-08-06 05:09:35 -07:00
|
|
|
def initialize(grouped_notifications, options = {})
|
2024-07-31 03:50:13 -07:00
|
|
|
super()
|
|
|
|
|
|
|
|
@grouped_notifications = grouped_notifications
|
2024-08-06 05:09:35 -07:00
|
|
|
@options = options
|
2024-07-31 03:50:13 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def notification_groups
|
|
|
|
@grouped_notifications
|
|
|
|
end
|
|
|
|
|
|
|
|
def statuses
|
|
|
|
@grouped_notifications.filter_map(&:target_status).uniq(&:id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def accounts
|
2024-08-06 05:09:35 -07:00
|
|
|
@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'
|
2024-07-31 03:50:13 -07:00
|
|
|
end
|
|
|
|
end
|