diff --git a/src/renderer/src/components/messages/MessageList.vue b/src/renderer/src/components/messages/MessageList.vue index 298a664..cc5845b 100644 --- a/src/renderer/src/components/messages/MessageList.vue +++ b/src/renderer/src/components/messages/MessageList.vue @@ -16,6 +16,10 @@ const selectMode = ref(false) const folderName = computed(() => foldersStore.activeFolder?.name ?? '') const hasSelected = computed(() => messagesStore.selectedIds.size > 0) +const activeUnread = computed(() => { + if (!accountsStore.activeAccountId || !foldersStore.activeFolderId) return 0 + return foldersStore.getFolderUnread(accountsStore.activeAccountId, foldersStore.activeFolderId) +}) const allVisibleSelected = computed(() => messagesStore.filteredMessages.length > 0 && messagesStore.filteredMessages.every((m) => messagesStore.selectedIds.has(m.id)) @@ -136,13 +140,13 @@ async function handleSwipeAction(action: SwipeAction, messageId: string): Promis

{{ folderName }}

diff --git a/src/renderer/src/stores/folders.store.ts b/src/renderer/src/stores/folders.store.ts index 3abd6af..8f0afe0 100644 --- a/src/renderer/src/stores/folders.store.ts +++ b/src/renderer/src/stores/folders.store.ts @@ -13,6 +13,10 @@ export const useFoldersStore = defineStore('folders', () => { const activeFolderId = ref(null) const loading = ref(false) + // Плоский счётчик непрочитанных: ключ `${accountId}:${folderId}` + // Хранится отдельно от дерева — гарантированно реактивен + const unreadCounts = ref>({}) + const folders = computed(() => { if (!accountsStore.activeAccountId) return [] return foldersByAccount.value[accountsStore.activeAccountId] ?? [] @@ -27,6 +31,7 @@ export const useFoldersStore = defineStore('folders', () => { try { const result = await invoke('folders:list', { accountId }) foldersByAccount.value[accountId] = result.folders + initUnreadCounts(accountId, result.folders) // Auto-select inbox const inbox = findFolderByRole(result.folders, SpecialFolderRole.Inbox) @@ -44,10 +49,21 @@ export const useFoldersStore = defineStore('folders', () => { activeFolderId.value = folderId } + function initUnreadCounts(accountId: string, folders: Folder[]): void { + for (const f of folders) { + unreadCounts.value[`${accountId}:${f.id}`] = f.unreadCount + if (f.children.length > 0) initUnreadCounts(accountId, f.children) + } + } + function updateFolderUnread(accountId: string, folderId: string, delta: number): void { - const tree = foldersByAccount.value[accountId] - if (!tree) return - patchUnreadInTree(tree, folderId, delta) + const key = `${accountId}:${folderId}` + const current = unreadCounts.value[key] ?? 0 + unreadCounts.value[key] = Math.max(0, current + delta) + } + + function getFolderUnread(accountId: string, folderId: string): number { + return unreadCounts.value[`${accountId}:${folderId}`] ?? 0 } // Auto-load folders when active account changes @@ -74,28 +90,17 @@ export const useFoldersStore = defineStore('folders', () => { return { foldersByAccount, folders, + unreadCounts, activeFolderId, activeFolder, loading, loadFolders, setActiveFolder, - updateFolderUnread + updateFolderUnread, + getFolderUnread } }) -// Заменяет элемент массива целиком — гарантированно триггерит Vue-реактивность -function patchUnreadInTree(folders: Folder[], folderId: string, delta: number): boolean { - for (let i = 0; i < folders.length; i++) { - if (folders[i].id === folderId) { - folders[i] = { ...folders[i], unreadCount: Math.max(0, folders[i].unreadCount + delta) } - return true - } - if (folders[i].children.length > 0 && patchUnreadInTree(folders[i].children, folderId, delta)) { - return true - } - } - return false -} function findFolderById(folders: Folder[], id: string | null): Folder | null { if (!id) return null