Navigate to UI when sync fails

This commit is contained in:
RMidhunSuresh 2022-08-23 21:58:35 +05:30
parent 216c5da386
commit 0f2b7a1ce9

View File

@ -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;
}