From c830f503256d8afd244a75e18fca3e5c76944815 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 30 Mar 2020 21:33:04 +0200 Subject: [PATCH] catch errors while persisting a new message --- src/domain/session/room/RoomViewModel.js | 11 ++++++++--- src/matrix/room/room.js | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index cb6e6119..19a58944 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -11,6 +11,7 @@ export default class RoomViewModel extends EventEmitter { this._timelineVM = null; this._onRoomChange = this._onRoomChange.bind(this); this._timelineError = null; + this._sendError = null; this._closeCallback = closeCallback; } @@ -57,6 +58,9 @@ export default class RoomViewModel extends EventEmitter { if (this._timelineError) { return `Something went wrong loading the timeline: ${this._timelineError.message}`; } + if (this._sendError) { + return `Something went wrong sending your message: ${this._sendError.message}`; + } return ""; } @@ -64,13 +68,14 @@ export default class RoomViewModel extends EventEmitter { return avatarInitials(this._room.name); } - sendMessage(message) { + async sendMessage(message) { if (message) { try { - this._room.sendEvent("m.room.message", {msgtype: "m.text", body: message}); + await this._room.sendEvent("m.room.message", {msgtype: "m.text", body: message}); } catch (err) { console.error(`room.sendMessage(): ${err.message}:\n${err.stack}`); - this._timelineError = err; + this._sendError = err; + this._timelineError = null; this.emit("change", "error"); return false; } diff --git a/src/matrix/room/room.js b/src/matrix/room/room.js index 605535a6..721eefe9 100644 --- a/src/matrix/room/room.js +++ b/src/matrix/room/room.js @@ -56,7 +56,7 @@ export default class Room extends EventEmitter { } sendEvent(eventType, content) { - this._sendQueue.enqueueEvent(eventType, content); + return this._sendQueue.enqueueEvent(eventType, content); }