diff --git a/src/domain/SessionLoadViewModel.js b/src/domain/SessionLoadViewModel.js index 0064108f..eec7c2fb 100644 --- a/src/domain/SessionLoadViewModel.js +++ b/src/domain/SessionLoadViewModel.js @@ -153,6 +153,11 @@ export class SessionLoadViewModel extends ViewModel { this.platform.saveFileAs(logExport.asBlob(), `hydrogen-logs-${this.platform.clock.now()}.json`); } + async logout() { + await this._sessionContainer.logout(); + this.navigation.push("session", true); + } + get accountSetupViewModel() { return this._accountSetupViewModel; } diff --git a/src/domain/session/settings/SettingsViewModel.js b/src/domain/session/settings/SettingsViewModel.js index 04d4d18d..eaffeb12 100644 --- a/src/domain/session/settings/SettingsViewModel.js +++ b/src/domain/session/settings/SettingsViewModel.js @@ -57,16 +57,11 @@ export class SettingsViewModel extends ViewModel { return this._sessionContainer.session; } - logout() { - return this.logger.run("logout", async log => { - this._isLoggingOut = true; - this.emitChange("isLoggingOut"); - try { - await this._session.logout(log); - } catch (err) {} - await this._sessionContainer.deleteSession(log); - this.navigation.push("session", true); - }); + async logout() { + this._isLoggingOut = true; + await this._sessionContainer.logout(); + this.emitChange("isLoggingOut"); + this.navigation.push("session", true); } setupDehydratedDevice(key) { diff --git a/src/matrix/Session.js b/src/matrix/Session.js index ede2ece9..90f383bb 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -107,6 +107,7 @@ export class Session { return this._sessionInfo.userId; } + /** @internal call SessionContainer.logout instead */ async logout(log = undefined) { await this._hsApi.logout({log}).response(); } diff --git a/src/matrix/SessionContainer.js b/src/matrix/SessionContainer.js index bc56905c..84d79bcb 100644 --- a/src/matrix/SessionContainer.js +++ b/src/matrix/SessionContainer.js @@ -367,6 +367,15 @@ export class SessionContainer { return !this._reconnector; } + logout() { + return this._platform.logger.run("logout", async log => { + try { + await this._session?.logout(log); + } catch (err) {} + await this.deleteSession(log); + }); + } + dispose() { if (this._reconnectSubscription) { this._reconnectSubscription(); diff --git a/src/platform/web/ui/login/SessionLoadStatusView.js b/src/platform/web/ui/login/SessionLoadStatusView.js index 24feed52..66ef5b27 100644 --- a/src/platform/web/ui/login/SessionLoadStatusView.js +++ b/src/platform/web/ui/login/SessionLoadStatusView.js @@ -28,11 +28,17 @@ export class SessionLoadStatusView extends TemplateView { onClick: () => vm.exportLogs() }, vm.i18n`Export logs`); }); + const logoutButtonIfFailed = t.if(vm => vm.hasError, (t, vm) => { + return t.button({ + onClick: () => vm.logout() + }, vm.i18n`Log out`); + }); return t.div({className: "SessionLoadStatusView"}, [ t.p({className: "status"}, [ spinner(t, {hidden: vm => !vm.loading}), t.p(vm => vm.loadLabel), - exportLogsButtonIfFailed + exportLogsButtonIfFailed, + logoutButtonIfFailed ]), t.ifView(vm => vm.accountSetupViewModel, vm => new AccountSetupView(vm.accountSetupViewModel)), ]);