From f7f9129b8b55ef8e8493e9b989d59cb4b70f6cb0 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Sun, 15 Sep 2019 12:23:26 +0200 Subject: [PATCH] show send errors in UI --- src/domain/session/room/RoomViewModel.js | 11 ++++++++++- src/ui/web/session/room/MessageComposer.js | 5 +++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index 23875e20..09de2b8b 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -66,7 +66,16 @@ export default class RoomViewModel extends EventEmitter { sendMessage(message) { if (message) { - this._room.sendEvent("m.room.message", {msgtype: "m.text", body: message}); + try { + 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.emit("change", "error"); + return false; + } + return true; } + return false; } } diff --git a/src/ui/web/session/room/MessageComposer.js b/src/ui/web/session/room/MessageComposer.js index a4fb3715..79e2fd5e 100644 --- a/src/ui/web/session/room/MessageComposer.js +++ b/src/ui/web/session/room/MessageComposer.js @@ -16,8 +16,9 @@ export default class MessageComposer extends TemplateView { _onKeyDown(event) { if (event.key === "Enter") { - this.viewModel.sendMessage(this._input.value); - this._input.value = ""; + if (this.viewModel.sendMessage(this._input.value)) { + this._input.value = ""; + } } } }