diff --git a/src/renderer/src/stores/folders.store.ts b/src/renderer/src/stores/folders.store.ts index cb957fb..3abd6af 100644 --- a/src/renderer/src/stores/folders.store.ts +++ b/src/renderer/src/stores/folders.store.ts @@ -47,8 +47,7 @@ export const useFoldersStore = defineStore('folders', () => { function updateFolderUnread(accountId: string, folderId: string, delta: number): void { const tree = foldersByAccount.value[accountId] if (!tree) return - const folder = findFolderById(tree, folderId) - if (folder) folder.unreadCount = Math.max(0, folder.unreadCount + delta) + patchUnreadInTree(tree, folderId, delta) } // Auto-load folders when active account changes @@ -84,6 +83,20 @@ export const useFoldersStore = defineStore('folders', () => { } }) +// Заменяет элемент массива целиком — гарантированно триггерит 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 for (const f of folders) { diff --git a/src/renderer/src/stores/messages.store.ts b/src/renderer/src/stores/messages.store.ts index ddbe806..4172031 100644 --- a/src/renderer/src/stores/messages.store.ts +++ b/src/renderer/src/stores/messages.store.ts @@ -120,6 +120,7 @@ export const useMessagesStore = defineStore('messages', () => { flags: { seen: true } }) msg.flags.seen = true + foldersStore.updateFolderUnread(accountsStore.activeAccountId, foldersStore.activeFolderId, -1) } return }