Updating ConversationsView wiring and the nav badge next.

This commit is contained in:
2026-09-29 16:22:37 +03:30
parent 032eb70524
commit d4972891f1
3 changed files with 374 additions and 64 deletions
+20 -1
View File
@@ -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(() => {
>
<UiIcon name="chat" :size="collapsed ? 20 : 18" />
<span>گفتگو</span>
<span v-if="chatBadge" class="nav-badge">{{ toFaDigits(chatBadge) }}</span>
</RouterLink>
<RouterLink
@@ -853,6 +871,7 @@ onUnmounted(() => {
>
<UiIcon name="chat" :size="18" />
<span>گفتگو</span>
<span v-if="chatBadge" class="nav-badge">{{ toFaDigits(chatBadge) }}</span>
</RouterLink>
<button
class="nav-item nav-fold-btn"