You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Make encryption asynchronous
We're going to need to send out a load of messages to distribute the megolm keys; as a first step, deal with the asynchronicity this will require.
This commit is contained in:
@@ -822,10 +822,18 @@ function _sendEvent(client, room, event, callback) {
|
||||
// so that we can handle synchronous and asynchronous exceptions with the
|
||||
// same code path.
|
||||
return q().then(function() {
|
||||
var encryptionPromise = null;
|
||||
if (client._crypto) {
|
||||
client._crypto.encryptEventIfNeeded(event, room);
|
||||
encryptionPromise = client._crypto.encryptEventIfNeeded(event, room);
|
||||
}
|
||||
|
||||
if (encryptionPromise) {
|
||||
_updatePendingEventStatus(room, event, EventStatus.ENCRYPTING);
|
||||
encryptionPromise = encryptionPromise.then(function() {
|
||||
_updatePendingEventStatus(room, event, EventStatus.SENDING);
|
||||
});
|
||||
}
|
||||
return encryptionPromise;
|
||||
}).then(function() {
|
||||
var promise;
|
||||
// this event may be queued
|
||||
if (client.scheduler) {
|
||||
@@ -857,10 +865,14 @@ function _sendEvent(client, room, event, callback) {
|
||||
// the request failed to send.
|
||||
console.error("Error sending event", err.stack || err);
|
||||
|
||||
_updatePendingEventStatus(room, event, EventStatus.NOT_SENT);
|
||||
try {
|
||||
_updatePendingEventStatus(room, event, EventStatus.NOT_SENT);
|
||||
|
||||
if (callback) {
|
||||
callback(err);
|
||||
if (callback) {
|
||||
callback(err);
|
||||
}
|
||||
} catch (err2) {
|
||||
console.error("Exception in error handler!", err2.stack || err);
|
||||
}
|
||||
throw err;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user