display sync errors in status bar

This commit is contained in:
Bruno Windels 2020-05-07 00:05:21 +02:00
parent 52e2d3203e
commit b65da9b8a9
2 changed files with 12 additions and 7 deletions

View file

@ -8,22 +8,23 @@ const SessionStatus = createEnum(
"Connecting", "Connecting",
"FirstSync", "FirstSync",
"Sending", "Sending",
"Syncing" "Syncing",
"SyncError"
); );
export class SessionStatusViewModel extends ViewModel { export class SessionStatusViewModel extends ViewModel {
constructor(options) { constructor(options) {
super(options); super(options);
const {syncStatus, reconnector} = options; const {sync, reconnector} = options;
this._syncStatus = syncStatus; this._sync = sync;
this._reconnector = reconnector; this._reconnector = reconnector;
this._status = this._calculateState(reconnector.connectionStatus.get(), syncStatus.get()); this._status = this._calculateState(reconnector.connectionStatus.get(), sync.status.get());
} }
start() { start() {
const update = () => this._updateStatus(); const update = () => this._updateStatus();
this.track(this._syncStatus.subscribe(update)); this.track(this._sync.status.subscribe(update));
this.track(this._reconnector.connectionStatus.subscribe(update)); this.track(this._reconnector.connectionStatus.subscribe(update));
} }
@ -41,6 +42,8 @@ export class SessionStatusViewModel extends ViewModel {
return this.i18n`Trying to reconnect now…`; return this.i18n`Trying to reconnect now…`;
case SessionStatus.FirstSync: case SessionStatus.FirstSync:
return this.i18n`Catching up with your conversations…`; return this.i18n`Catching up with your conversations…`;
case SessionStatus.SyncError:
return this.i18n`Sync failed because of ${this._sync.error}`;
} }
return ""; return "";
} }
@ -58,7 +61,7 @@ export class SessionStatusViewModel extends ViewModel {
_updateStatus() { _updateStatus() {
const newStatus = this._calculateState( const newStatus = this._calculateState(
this._reconnector.connectionStatus.get(), this._reconnector.connectionStatus.get(),
this._syncStatus.get() this._sync.status.get()
); );
if (newStatus !== this._status) { if (newStatus !== this._status) {
if (newStatus === SessionStatus.Disconnected) { if (newStatus === SessionStatus.Disconnected) {
@ -89,6 +92,8 @@ export class SessionStatusViewModel extends ViewModel {
case SyncStatus.InitialSync: case SyncStatus.InitialSync:
case SyncStatus.CatchupSync: case SyncStatus.CatchupSync:
return SessionStatus.FirstSync; return SessionStatus.FirstSync;
case SyncStatus.Stopped:
return SessionStatus.SyncError;
} }
} /* else if (session.pendingMessageCount) { } /* else if (session.pendingMessageCount) {
return SessionStatus.Sending; return SessionStatus.Sending;

View file

@ -9,7 +9,7 @@ export class SessionViewModel extends ViewModel {
const {sessionContainer} = options; const {sessionContainer} = options;
this._session = sessionContainer.session; this._session = sessionContainer.session;
this._sessionStatusViewModel = this.track(new SessionStatusViewModel(this.childOptions({ this._sessionStatusViewModel = this.track(new SessionStatusViewModel(this.childOptions({
syncStatus: sessionContainer.sync.status, sync: sessionContainer.sync,
reconnector: sessionContainer.reconnector reconnector: sessionContainer.reconnector
}))); })));
this._currentRoomViewModel = null; this._currentRoomViewModel = null;