diff --git a/src/main.ts b/src/main.ts index 5728111d0ab0ec9faf1c0f269d88d19cde97931c..fcc3410bcb68432b8a63524504e444be5e651dfc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -56,7 +56,7 @@ function allowsChild(parent, child) { const { type } = child; switch (parent?.type) { case undefined: - return type === "start" || type === "account-setup" || type === "timeline"; + return type === "start" || type === "account-setup" || type === "timeline" || type === "minimize"; default: return false; } diff --git a/src/ui/views/AccountSetupView.ts b/src/ui/views/AccountSetupView.ts index e1c4674e059262f97bff759348693f74812ee92c..4057fd92f839d90e51b79f8de7f2fef73156d275 100644 --- a/src/ui/views/AccountSetupView.ts +++ b/src/ui/views/AccountSetupView.ts @@ -36,7 +36,7 @@ class PolicyAgreementView extends TemplateView<AccountSetupViewModel> { t.div({ className: "PolicyAgreementView_btn-collection" }, [ t.button({ onClick: () => vm.completeRegistration(), className: "PolicyAgreementView_next", }, "Accept and continue to chat"), - t.button({ onClick: () => (window as any).sendMinimizeToParent(), className: "button-action PolicyAgreementView_cancel", }, "Cancel"), + t.button({ onClick: () => vm.minimize(), className: "button-action PolicyAgreementView_cancel", }, "Cancel"), ]), ]); } diff --git a/src/viewmodels/AccountSetupViewModel.ts b/src/viewmodels/AccountSetupViewModel.ts index 9e46c51e921a14caf1e9f51f5f3c28865bd19989..aa76de7c559ec0b3f8e324cd4b4b49a4b99541e1 100644 --- a/src/viewmodels/AccountSetupViewModel.ts +++ b/src/viewmodels/AccountSetupViewModel.ts @@ -97,6 +97,11 @@ export class AccountSetupViewModel extends ViewModel { } } + minimize(): void { + (window as any).sendMinimizeToParent(); + this.navigation.push("minimize"); + } + private get _homeserver(): string { return this._config.homeserver; } diff --git a/src/viewmodels/ChatterboxViewModel.ts b/src/viewmodels/ChatterboxViewModel.ts index f348d3d264a5ce481f54ee306c2499842e2cf2d8..9a786988b67bb06c015cee8fcd6a0ce8c6802db2 100644 --- a/src/viewmodels/ChatterboxViewModel.ts +++ b/src/viewmodels/ChatterboxViewModel.ts @@ -13,13 +13,11 @@ function createCustomTileClassForEntry(ownUserId: string) { export class ChatterboxViewModel extends ViewModel { private _roomViewModel?: typeof RoomViewModel; private _loginPromise: Promise<void>; - private _minimize: () => void; constructor(options) { super(options); this._client = options.client; this._loginPromise = options.loginPromise; - this._minimize = options.minimize; } async load() { @@ -102,7 +100,7 @@ export class ChatterboxViewModel extends ViewModel { minimize() { (window as any).sendMinimizeToParent(); - this._minimize(); + this.navigation.push("minimize"); } get timelineViewModel() { diff --git a/src/viewmodels/RootViewModel.ts b/src/viewmodels/RootViewModel.ts index ae2f3463e9fb31fbda513a7012dab6a13f7fd4de..43387c833e29da7c05127e5b809e7e2800bf5041 100644 --- a/src/viewmodels/RootViewModel.ts +++ b/src/viewmodels/RootViewModel.ts @@ -23,21 +23,27 @@ export class RootViewModel extends ViewModel { this._config = config; this._client = new Client(this.platform); this._setupNavigation(); - this._messageFromParent.on("maximize", () => this._showTimeline(Promise.resolve())); + this._messageFromParent.on("maximize", () => this.start()); // Chatterbox can be minimized via the start button on the parent page! - this._messageFromParent.on("minimize", () => this.minimizeChatterbox()); + this._messageFromParent.on("minimize", () => this.navigation.push("minimize")); } private _setupNavigation() { this.navigation.observe("account-setup").subscribe(() => this._showAccountSetup()); this.navigation.observe("timeline").subscribe((loginPromise) => this._showTimeline(loginPromise)); + this.navigation.observe("minimize").subscribe(() => this.minimizeChatterbox()); } async start() { const sessionAlreadyExists = await this.attemptStartWithExistingSession(); if (sessionAlreadyExists) { - this._watchNotificationCount(); + if (!this._isWatchingNotificationCount) { + this._watchNotificationCount(); + } if (this._startMinimized) { + // when CB is maximized, this function is run again + // don't start in minimized state then + this._startMinimized = false; return; } this.navigation.push("timeline"); @@ -55,7 +61,6 @@ export class RootViewModel extends ViewModel { config: this._config, state: this._state, loginPromise, - minimize: () => this.minimizeChatterbox() }) )); await this._chatterBoxViewModel.load(); @@ -122,6 +127,7 @@ export class RootViewModel extends ViewModel { minimizeChatterbox() { this._chatterBoxViewModel = this.disposeTracked(this._chatterBoxViewModel); + this._accountSetupViewModel = this.disposeTracked(this._chatterBoxViewModel); this._activeSection = ""; this.emitChange("chatterboxViewModel"); }