Lazy load inboxRuleHandel to prevent null mailModel

Close #9094

Co-authored-by: ivk <ivk@tutao.de>
This commit is contained in:
wrd 2025-06-10 18:17:24 +02:00 committed by hrb-hub
parent a76562e5b8
commit 900bd4c16f
3 changed files with 10 additions and 9 deletions

View file

@ -90,7 +90,7 @@ export class MailModel {
private readonly logins: LoginController,
private readonly mailFacade: MailFacade,
private readonly connectivityModel: WebsocketConnectivityModel | null,
private readonly inboxRuleHandler: InboxRuleHandler | null,
private readonly inboxRuleHandler: () => InboxRuleHandler | null,
) {}
// only init listeners once
@ -175,7 +175,7 @@ export class MailModel {
// We only apply rules on server if we are the leader in case of incoming messages
return (
mailboxDetail &&
this.inboxRuleHandler?.findAndApplyMatchingRule(
this.inboxRuleHandler()?.findAndApplyMatchingRule(
mailboxDetail,
mail,
this.connectivityModel ? this.connectivityModel.isLeader() : false,
@ -205,10 +205,11 @@ export class MailModel {
}
async applyInboxRuleToMail(mail: Mail) {
if (this.inboxRuleHandler) {
const inboxRuleHandler = this.inboxRuleHandler()
if (inboxRuleHandler) {
const mailboxDetail = await this.getMailboxDetailsForMail(mail)
if (mailboxDetail) {
this.inboxRuleHandler.findAndApplyMatchingRule(mailboxDetail, mail, true, true)
inboxRuleHandler.findAndApplyMatchingRule(mailboxDetail, mail, true, true)
}
}
}

View file

@ -271,7 +271,7 @@ class MailLocator implements CommonLocator {
conversationViewModelFactory,
this.mailOpenedListener,
deviceConfig,
this.inboxRuleHanlder(),
this.inboxRuleHandler(),
router,
await this.redraw(),
)
@ -282,9 +282,9 @@ class MailLocator implements CommonLocator {
return new AffiliateViewModel()
})
inboxRuleHanlder(): InboxRuleHandler {
readonly inboxRuleHandler = lazyMemoized(() => {
return new InboxRuleHandler(this.mailFacade, this.logins, this.mailModel)
}
})
async searchViewModelFactory(): Promise<() => SearchViewModel> {
const { SearchViewModel } = await import("../mail-app/search/view/SearchViewModel.js")
@ -800,7 +800,7 @@ class MailLocator implements CommonLocator {
this.logins,
this.mailFacade,
this.connectivityModel,
this.inboxRuleHanlder(),
this.inboxRuleHandler,
)
this.operationProgressTracker = new OperationProgressTracker()
this.infoMessageHandler = new InfoMessageHandler((state: SearchIndexStateInfo) => {

View file

@ -53,7 +53,7 @@ o.spec("MailModelTest", function () {
logins,
mailFacade,
null,
null,
() => null,
)
// not pretty, but works
// model.mailboxDetails(mailboxDetails as MailboxDetail[])