useOnlineNotificationCount.ts 889 B

1234567891011121314151617181920212223242526272829
  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. }