Загружать счётчики непрочитанных для всех папок при старте
Метод listFolders теперь вызывает IMAP STATUS для каждой папки и заполняет unreadCount/totalCount реальными данными с сервера, чтобы бейджи в сайдбаре отображались корректно без предварительного посещения каждой папки. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8c92c7e1fc
commit
e8a0d7242c
1 changed files with 19 additions and 0 deletions
|
|
@ -69,9 +69,28 @@ export class ImapProvider implements IEmailProvider {
|
|||
// listTree() returns { root: true, folders: ImapMailbox[] }
|
||||
const tree = await this.client.listTree() as { folders?: ImapMailbox[] }
|
||||
const folders = this.convertMailboxArray(tree.folders ?? [])
|
||||
await this.populateUnreadCounts(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> {
|
||||
const lock = await this.client.getMailboxLock(options.folderId)
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in a new issue