From 0f2b7a1ce9111ff29acc46f788dbfb874b5ac21a Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 23 Aug 2022 21:58:35 +0530 Subject: [PATCH] Navigate to UI when sync fails --- src/domain/session/SessionViewModel.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/domain/session/SessionViewModel.js b/src/domain/session/SessionViewModel.js index a67df3a7..3bbcc08a 100644 --- a/src/domain/session/SessionViewModel.js +++ b/src/domain/session/SessionViewModel.js @@ -28,6 +28,7 @@ import {CreateRoomViewModel} from "./CreateRoomViewModel.js"; import {ViewModel} from "../ViewModel"; import {RoomViewModelObservable} from "./RoomViewModelObservable.js"; import {RightPanelViewModel} from "./rightpanel/RightPanelViewModel.js"; +import {SyncStatus} from "../../matrix/Sync.js"; export class SessionViewModel extends ViewModel { constructor(options) { @@ -45,6 +46,7 @@ export class SessionViewModel extends ViewModel { this._gridViewModel = null; this._createRoomViewModel = null; this._setupNavigation(); + this._setupForcedLogoutOnAccessTokenInvalidation(); } _setupNavigation() { @@ -93,6 +95,18 @@ export class SessionViewModel extends ViewModel { this._updateRightPanel(); } + _setupForcedLogoutOnAccessTokenInvalidation() { + this._client.sync.status.subscribe(status => { + if (status === SyncStatus.Stopped) { + const error = this._client.sync.error; + if (error.errcode === "M_UNKNOWN_TOKEN") { + // Access token is no longer valid, so force the user to log out + this.navigation.push("forced-logout", this.id); + } + } + }); + } + get id() { return this._client.sessionId; }