Пересчитывать unread из флагов писем после загрузки папки
Серверный folder.unreadCount может быть устаревшим. Если все письма помещаются в одну страницу (total <= page), считаем непрочитанные напрямую из flags.seen загруженных сообщений — это точный счётчик. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c1a49cc627
commit
580e5ba87f
2 changed files with 11 additions and 0 deletions
|
|
@ -62,6 +62,10 @@ export const useFoldersStore = defineStore('folders', () => {
|
|||
unreadCounts.value[key] = Math.max(0, current + delta)
|
||||
}
|
||||
|
||||
function setFolderUnread(accountId: string, folderId: string, count: number): void {
|
||||
unreadCounts.value[`${accountId}:${folderId}`] = Math.max(0, count)
|
||||
}
|
||||
|
||||
function getFolderUnread(accountId: string, folderId: string): number {
|
||||
return unreadCounts.value[`${accountId}:${folderId}`] ?? 0
|
||||
}
|
||||
|
|
@ -97,6 +101,7 @@ export const useFoldersStore = defineStore('folders', () => {
|
|||
loadFolders,
|
||||
setActiveFolder,
|
||||
updateFolderUnread,
|
||||
setFolderUnread,
|
||||
getFolderUnread
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -63,6 +63,12 @@ export const useMessagesStore = defineStore('messages', () => {
|
|||
|
||||
if (offset === 0) {
|
||||
messages.value = result.messages
|
||||
// Если все письма загружены в одну страницу — пересчитываем
|
||||
// unread точно из флагов, а не из (возможно устаревшего) серверного счётчика
|
||||
if (result.messages.length >= result.total) {
|
||||
const exactUnread = result.messages.filter((m) => !m.flags.seen).length
|
||||
foldersStore.setFolderUnread(accountId, folderId, exactUnread)
|
||||
}
|
||||
// Предзагрузка тел первых 10 писем в фоне
|
||||
setTimeout(() => prefetchBodies(accountId, folderId, 10), 600)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue