mark_all_as_seen.rb 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class OnlineNotification::MarkAllAsSeen < BaseMutation
  4. description 'Marks notifications for active user as seen'
  5. argument :online_notification_ids, [GraphQL::Types::ID], required: true, loads: Gql::Types::OnlineNotificationType, description: 'Unique identifiers ofnotifications which should be deleted.'
  6. field :online_notifications, [Gql::Types::OnlineNotificationType], null: true, description: 'The seen notifications.'
  7. def authorized?(online_notifications:)
  8. online_notifications.all? do |elem|
  9. Pundit.authorize(context.current_user, elem, :update?)
  10. end
  11. end
  12. def resolve(online_notifications:)
  13. return {} if online_notifications.none?
  14. # Only trigger subscription once after all are updated.
  15. ::OnlineNotification.without_callback(:commit, :after, :trigger_subscriptions) do
  16. online_notifications.each do |elem|
  17. elem.seen = true
  18. elem.save!
  19. end
  20. end
  21. online_notifications.last.trigger_subscriptions
  22. { online_notifications: online_notifications }
  23. end
  24. end
  25. end