useOnlineNotificationCount.ts 890 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { ref } from 'vue'
  3. import { useOnlineNotificationsCountSubscription } from '#shared/entities/online-notification/graphql/subscriptions/onlineNotificationsCount.api.ts'
  4. import { SubscriptionHandler } from '#shared/server/apollo/handler/index.ts'
  5. import { useSessionStore } from '#shared/stores/session.ts'
  6. export const useOnlineNotificationCount = () => {
  7. const unseenCount = ref(0)
  8. const { userId } = useSessionStore()
  9. const notificationsCountSubscription = new SubscriptionHandler(
  10. useOnlineNotificationsCountSubscription({ userId }),
  11. )
  12. notificationsCountSubscription.onResult((result) => {
  13. const { data } = result
  14. if (!data) return
  15. unseenCount.value = data.onlineNotificationsCount.unseenCount
  16. })
  17. return {
  18. notificationsCountSubscription,
  19. unseenCount,
  20. }
  21. }