Исправить обновление счётчика непрочитанных
- updateFolderUnread теперь заменяет элемент массива через спред
(folders[i] = { ...folders[i], unreadCount: X }) вместо мутации
свойства — гарантированно триггерит Vue-реактивность
- Добавлен вызов updateFolderUnread в кешированный путь selectMessage
(ранее открытие prefetch-сообщения не уменьшало счётчик)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
62f38673b0
commit
df5e7f430b
2 changed files with 16 additions and 2 deletions
|
|
@ -47,8 +47,7 @@ export const useFoldersStore = defineStore('folders', () => {
|
||||||
function updateFolderUnread(accountId: string, folderId: string, delta: number): void {
|
function updateFolderUnread(accountId: string, folderId: string, delta: number): void {
|
||||||
const tree = foldersByAccount.value[accountId]
|
const tree = foldersByAccount.value[accountId]
|
||||||
if (!tree) return
|
if (!tree) return
|
||||||
const folder = findFolderById(tree, folderId)
|
patchUnreadInTree(tree, folderId, delta)
|
||||||
if (folder) folder.unreadCount = Math.max(0, folder.unreadCount + delta)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-load folders when active account changes
|
// 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 {
|
function findFolderById(folders: Folder[], id: string | null): Folder | null {
|
||||||
if (!id) return null
|
if (!id) return null
|
||||||
for (const f of folders) {
|
for (const f of folders) {
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,7 @@ export const useMessagesStore = defineStore('messages', () => {
|
||||||
flags: { seen: true }
|
flags: { seen: true }
|
||||||
})
|
})
|
||||||
msg.flags.seen = true
|
msg.flags.seen = true
|
||||||
|
foldersStore.updateFolderUnread(accountsStore.activeAccountId, foldersStore.activeFolderId, -1)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue