Skip to content

Commit

Permalink
use MailSetEntry ListId in process imported mails
Browse files Browse the repository at this point in the history
  • Loading branch information
kibibytium committed Feb 3, 2025
1 parent dbb3cc8 commit ad17613
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/mail-app/mail/view/MailViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Mail,
MailBox,
MailFolder,
MailFolderTypeRef,
MailSetEntry,
MailSetEntryTypeRef,
MailTypeRef,
Expand All @@ -24,7 +25,7 @@ import {
debounce,
first,
groupBy,
isNotEmpty,
isEmpty,
lastThrow,
lazyMemoized,
mapWith,
Expand Down Expand Up @@ -530,30 +531,30 @@ export class MailViewModel {

private async processImportedMails(update: EntityUpdateData) {
const importMailState = await this.entityClient.load(ImportMailStateTypeRef, [update.instanceListId, update.instanceId])
const importedFolder = await this.entityClient.load(MailFolderTypeRef, importMailState.targetFolder)
const listModelOfImport = this.listModelForFolder(elementIdPart(importMailState.targetFolder))

let status = parseInt(importMailState.status) as ImportStatus
if (status === ImportStatus.Finished || status === ImportStatus.Canceled) {
let importedMailEntries = await this.entityClient.loadAll(ImportedMailTypeRef, importMailState.importedMails)
if (importedMailEntries.length === 0) return Promise.resolve()
if (isEmpty(importedMailEntries)) return Promise.resolve()

let mailSetEntryIds = importedMailEntries.map((importedMail) => elementIdPart(importedMail.mailSetEntry))
const mailSetEntryListId = listIdPart(importedMailEntries[0].mailSetEntry)
const importedMailSetEntries = await this.entityClient.loadMultiple(MailSetEntryTypeRef, mailSetEntryListId, mailSetEntryIds)
if (isNotEmpty(importedMailSetEntries)) {
// put mails into cache before list model will download them one by one
await this.preloadMails(importedMailSetEntries)

await promiseMap(importedMailSetEntries, (importedMailSetEntry) => {
return listModelOfImport.handleEntityUpdate({
instanceListId: listIdPart(importedMailSetEntry._id),
instanceId: elementIdPart(importedMailSetEntry._id),
operation: OperationType.CREATE,
type: MailSetEntryTypeRef.type,
application: MailSetEntryTypeRef.app,
})
if (isEmpty(importedMailSetEntries)) return Promise.resolve()

// put mails into cache before list model will download them one by one
await this.preloadMails(importedMailSetEntries)
await promiseMap(importedMailSetEntries, (importedMailSetEntry) => {
return listModelOfImport.handleEntityUpdate({
instanceId: elementIdPart(importedMailSetEntry._id),
instanceListId: importedFolder.entries,
operation: OperationType.CREATE,
type: MailSetEntryTypeRef.type,
application: MailSetEntryTypeRef.app,
})
}
})
}
}

Expand Down

0 comments on commit ad17613

Please sign in to comment.