Merge pull request #41 from bwindels/bwindels/catchsenderror

Catch errors while persisting a new message
This commit is contained in:
Bruno Windels 2020-03-30 19:33:53 +00:00 committed by GitHub
commit 3a6a2e1e99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -11,6 +11,7 @@ export default class RoomViewModel extends EventEmitter {
this._timelineVM = null; this._timelineVM = null;
this._onRoomChange = this._onRoomChange.bind(this); this._onRoomChange = this._onRoomChange.bind(this);
this._timelineError = null; this._timelineError = null;
this._sendError = null;
this._closeCallback = closeCallback; this._closeCallback = closeCallback;
} }
@ -57,6 +58,9 @@ export default class RoomViewModel extends EventEmitter {
if (this._timelineError) { if (this._timelineError) {
return `Something went wrong loading the timeline: ${this._timelineError.message}`; return `Something went wrong loading the timeline: ${this._timelineError.message}`;
} }
if (this._sendError) {
return `Something went wrong sending your message: ${this._sendError.message}`;
}
return ""; return "";
} }
@ -64,13 +68,14 @@ export default class RoomViewModel extends EventEmitter {
return avatarInitials(this._room.name); return avatarInitials(this._room.name);
} }
sendMessage(message) { async sendMessage(message) {
if (message) { if (message) {
try { 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) { } catch (err) {
console.error(`room.sendMessage(): ${err.message}:\n${err.stack}`); console.error(`room.sendMessage(): ${err.message}:\n${err.stack}`);
this._timelineError = err; this._sendError = err;
this._timelineError = null;
this.emit("change", "error"); this.emit("change", "error");
return false; return false;
} }

View file

@ -56,7 +56,7 @@ export default class Room extends EventEmitter {
} }
sendEvent(eventType, content) { sendEvent(eventType, content) {
this._sendQueue.enqueueEvent(eventType, content); return this._sendQueue.enqueueEvent(eventType, content);
} }