online_notifications_count.rb 637 B

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Subscriptions
  3. class OnlineNotificationsCount < BaseSubscription
  4. description 'Updates unseen notifications count'
  5. subscription_scope :current_user_id
  6. field :unseen_count, Integer, null: false, description: 'Count of unseen notifications for the user'
  7. def subscribe
  8. response
  9. end
  10. def update
  11. response
  12. end
  13. private
  14. def scope
  15. OnlineNotification.where(user: context.current_user)
  16. end
  17. def response
  18. {
  19. unseen_count: scope.where(seen: false).count,
  20. }
  21. end
  22. end
  23. end