From 53cb3ca79ba0dcc3159cc8ea3bb7ca28f34f45a8 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 16 Mar 2020 12:23:13 +0000 Subject: [PATCH] return the additional promise to simplify the rejection chain Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/client.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/client.js b/src/client.js index 22b1079b4..2da3c05a7 100644 --- a/src/client.js +++ b/src/client.js @@ -287,13 +287,14 @@ export function MatrixClient(opts) { _updatePendingEventStatus(room, eventToSend, EventStatus.SENDING); } - const promise = _sendEventHttpRequest(self, eventToSend); + let promise = _sendEventHttpRequest(self, eventToSend); if (room) { // ensure we update pending event before the next scheduler run so that any listeners to event id // updates on the synchronous event emitter get a chance to run first. - promise.then(res => { + promise = promise.then(res => { room.updatePendingEvent(eventToSend, EventStatus.SENT, res.event_id); - }, () => {}); // handle rejection to stop it being thrown + return res; + }); } return promise; }); @@ -2431,9 +2432,10 @@ function _sendEvent(client, room, event, callback) { if (!promise) { promise = _sendEventHttpRequest(client, event); if (room) { - promise.then(res => { + promise = promise.then(res => { room.updatePendingEvent(event, EventStatus.SENT, res.event_id); - }, () => {}); // handle rejection to stop it being thrown + return res; + }); } } return promise;