catch errors while persisting a new message
This commit is contained in:
parent
53f2a5801e
commit
c830f50325
2 changed files with 9 additions and 4 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue