Skip to content

Commit

Permalink
Refactor WebMobileFacade to delegate to MailView more
Browse files Browse the repository at this point in the history
We do not need to parse or manipulate URLs directly since MailView
can use MailViewModel.
  • Loading branch information
charlag committed Dec 4, 2024
1 parent 37d86f5 commit 7939185
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/calendar-app/calendarLocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ class CalendarLocator {
const { createNativeInterfaces, createDesktopInterfaces } = await import("../common/native/main/NativeInterfaceFactory.js")
const { OpenCalendarHandler } = await import("../common/native/main/OpenCalendarHandler.js")
const openCalendarHandler = new OpenCalendarHandler(this.logins)
this.webMobileFacade = new WebMobileFacade(this.connectivityModel, this.mailboxModel, CALENDAR_PREFIX)
this.webMobileFacade = new WebMobileFacade(this.connectivityModel, CALENDAR_PREFIX)
this.nativeInterfaces = createNativeInterfaces(
this.webMobileFacade,
new WebDesktopFacade(this.logins, async () => this.native),
Expand Down
16 changes: 1 addition & 15 deletions src/common/native/main/WebMobileFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ export class WebMobileFacade implements MobileFacade {

private isAppVisible: stream<boolean> = stream(false)

constructor(
private readonly connectivityModel: WebsocketConnectivityModel,
private readonly mailboxModel: MailboxModel,
private readonly baseViewPrefix: string,
private readonly mailBackNewRoute?: (currentRoute: string) => Promise<string | null>,
) {}
constructor(private readonly connectivityModel: WebsocketConnectivityModel, private readonly baseViewPrefix: string) {}

public getIsAppVisible(): stream<boolean> {
return this.isAppVisible
Expand Down Expand Up @@ -84,15 +79,6 @@ export class WebMobileFacade implements MobileFacade {
// go back to mail or calendar from other paths
m.route.set(this.baseViewPrefix)
return true
} else if (viewSlider && viewSlider.isFirstBackgroundColumnFocused()) {
if (currentRoute.startsWith(MAIL_PREFIX) && this.mailBackNewRoute) {
const newRoute = await this.mailBackNewRoute(currentRoute)
if (newRoute) {
m.route.set(newRoute)
return true
}
}
return false
} else {
return false
}
Expand Down
13 changes: 11 additions & 2 deletions src/mail-app/mail/view/MailView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ViewSlider } from "../../../common/gui/nav/ViewSlider.js"
import { ColumnType, ViewColumn } from "../../../common/gui/base/ViewColumn"
import { lang } from "../../../common/misc/LanguageViewModel"
import { Dialog } from "../../../common/gui/base/Dialog"
import { FeatureType, Keys, MailSetKind } from "../../../common/api/common/TutanotaConstants"
import { FeatureType, getMailFolderType, Keys, MailSetKind } from "../../../common/api/common/TutanotaConstants"
import { AppHeaderAttrs, Header } from "../../../common/gui/Header.js"
import type { Mail, MailBox, MailFolder } from "../../../common/api/entities/tutanota/TypeRefs.js"
import { noOp, ofClass } from "@tutao/tutanota-utils"
Expand Down Expand Up @@ -407,8 +407,17 @@ export class MailView extends BaseTopLevelView implements TopLevelView<MailViewA
if (listModel && listModel.state.inMultiselect) {
listModel.selectNone()
return true
} else if (this.viewSlider.isFirstBackgroundColumnFocused()) {
const folder = this.mailViewModel.getFolder()
if (folder == null || getMailFolderType(folder) !== MailSetKind.INBOX) {
this.mailViewModel.switchToFolder(MailSetKind.INBOX)
return true
} else {
return false
}
} else {
return false
}
return false
}

private renderHeaderRightView(): Children {
Expand Down
19 changes: 1 addition & 18 deletions src/mail-app/mailLocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,24 +797,7 @@ class MailLocator {
const { OpenCalendarHandler } = await import("../common/native/main/OpenCalendarHandler.js")
const openCalendarHandler = new OpenCalendarHandler(this.logins)

this.webMobileFacade = new WebMobileFacade(this.connectivityModel, this.mailboxModel, MAIL_PREFIX, async (currentRoute: string) => {
// If the first background column is focused in mail view (showing a folder), move to inbox.
// If in inbox already, quit
const parts = currentRoute.split("/").filter((part) => part !== "")

if (parts.length > 1) {
const selectedMailListId = parts[1]
const [mailboxDetail] = await this.mailboxModel.getMailboxDetails()
const folders = await this.mailModel.getMailboxFoldersForId(assertNotNull(mailboxDetail.mailbox.folders)._id)
const inboxFolderId = getElementId(assertSystemFolderOfType(folders, MailSetKind.INBOX))

if (inboxFolderId !== selectedMailListId) {
return MAIL_PREFIX + "/" + inboxFolderId
}
}

return null
})
this.webMobileFacade = new WebMobileFacade(this.connectivityModel, MAIL_PREFIX)

this.nativeInterfaces = createNativeInterfaces(
this.webMobileFacade,
Expand Down

0 comments on commit 7939185

Please sign in to comment.