Загружать счётчики непрочитанных для всех папок при старте

Метод listFolders теперь вызывает IMAP STATUS для каждой папки
и заполняет unreadCount/totalCount реальными данными с сервера,
чтобы бейджи в сайдбаре отображались корректно без предварительного
посещения каждой папки.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
vodyanoysh 2026-03-31 23:22:27 +07:00
parent 8c92c7e1fc
commit e8a0d7242c

View file

@ -69,9 +69,28 @@ export class ImapProvider implements IEmailProvider {
// listTree() returns { root: true, folders: ImapMailbox[] } // listTree() returns { root: true, folders: ImapMailbox[] }
const tree = await this.client.listTree() as { folders?: ImapMailbox[] } const tree = await this.client.listTree() as { folders?: ImapMailbox[] }
const folders = this.convertMailboxArray(tree.folders ?? []) const folders = this.convertMailboxArray(tree.folders ?? [])
await this.populateUnreadCounts(folders)
return { folders } return { folders }
} }
private async populateUnreadCounts(folders: Folder[]): Promise<void> {
for (const folder of folders) {
try {
const status = await this.client.status(folder.id, { unseen: true, messages: true }) as
{ unseen?: number; messages?: number } | null
if (status) {
folder.unreadCount = status.unseen ?? 0
folder.totalCount = status.messages ?? 0
}
} catch {
// Некоторые папки (виртуальные, [Gmail]) могут не поддерживать STATUS
}
if (folder.children.length > 0) {
await this.populateUnreadCounts(folder.children)
}
}
}
async listMessages(options: MessageListOptions): Promise<MessageListResult> { async listMessages(options: MessageListOptions): Promise<MessageListResult> {
const lock = await this.client.getMailboxLock(options.folderId) const lock = await this.client.getMailboxLock(options.folderId)
try { try {