diff --git a/apps/web/src/layouts/AppLayout.vue b/apps/web/src/layouts/AppLayout.vue index 2bc3763..14e2950 100644 --- a/apps/web/src/layouts/AppLayout.vue +++ b/apps/web/src/layouts/AppLayout.vue @@ -16,10 +16,13 @@ import type { NotificationsListDto, } from '@mento/shared'; import { canManageSettings, canViewAllRecords } from '@/lib/roles'; +import { refreshUnreadTotal, useOrgChat } from '@/lib/useOrgChat'; const auth = useAuthStore(); const router = useRouter(); const route = useRoute(); +const { unreadTotal: chatUnreadTotal, ensureConnected: ensureChatConnected } = useOrgChat(); +const chatBadge = computed(() => chatUnreadTotal.value); const canSettings = computed(() => canManageSettings(auth.user?.role)); const showOwnRecordsBanner = computed( @@ -282,6 +285,16 @@ async function loadActivityBadge() { } } +async function loadChatBadge() { + if (!moduleAllowed('conversations')) return; + try { + await refreshUnreadTotal(); + await ensureChatConnected(); + } catch { + // keep previous + } +} + async function markRead(item: NotificationDto) { if (!item.readAt) { await api.patch(`/notifications/${item.id}/read`); @@ -361,7 +374,11 @@ onMounted(() => { } void refreshNotifs(); void loadActivityBadge(); - pollTimer = setInterval(() => void refreshNotifs(), 45000); + void loadChatBadge(); + pollTimer = setInterval(() => { + void refreshNotifs(); + void refreshUnreadTotal().catch(() => undefined); + }, 45000); mobileMq = window.matchMedia('(max-width: 900px)'); isMobileNav.value = mobileMq.matches; mobileMq.addEventListener('change', onMobileMqChange); @@ -503,6 +520,7 @@ onUnmounted(() => { > گفتگو + {{ toFaDigits(chatBadge) }} { > گفتگو + {{ toFaDigits(chatBadge) }}