grouped_notifications_presenter.rb 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # frozen_string_literal: true
  2. class GroupedNotificationsPresenter < ActiveModelSerializers::Model
  3. def initialize(grouped_notifications, options = {})
  4. super()
  5. @grouped_notifications = grouped_notifications
  6. @options = options
  7. end
  8. def notification_groups
  9. @grouped_notifications
  10. end
  11. def statuses
  12. @grouped_notifications.filter_map(&:target_status).uniq(&:id)
  13. end
  14. def accounts
  15. @accounts ||= begin
  16. if partial_avatars?
  17. @grouped_notifications.map { |group| group.sample_accounts.first }.uniq(&:id)
  18. else
  19. @grouped_notifications.flat_map(&:sample_accounts).uniq(&:id)
  20. end
  21. end
  22. end
  23. def partial_accounts
  24. @partial_accounts ||= begin
  25. if partial_avatars?
  26. @grouped_notifications.flat_map { |group| group.sample_accounts[1...] }.uniq(&:id).filter { |account| accounts.exclude?(account) }
  27. else
  28. []
  29. end
  30. end
  31. end
  32. private
  33. def partial_avatars?
  34. @options[:expand_accounts] == 'partial_avatars'
  35. end
  36. end