From 71444b638bd3786df7df556fd2e1b0f4be7ffeee Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 22 Aug 2018 14:45:36 +0200 Subject: [PATCH] don't block on setting up room crypto this will load members in case of LL and could take quite some time The two async actions performed by onCryptoEvent is saving the crypto config to the roomlist store and fetching the room members to track. Both are guarded against double calls so not awaiting this should be fine. --- src/crypto/RoomList.js | 3 +++ src/sync.js | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/crypto/RoomList.js b/src/crypto/RoomList.js index 5bb437fb7..eb5b469c6 100644 --- a/src/crypto/RoomList.js +++ b/src/crypto/RoomList.js @@ -71,6 +71,9 @@ export default class RoomList { } async setRoomEncryption(roomId, roomInfo) { + // important that this happens before calling into the store + // as it prevents the Crypto::setRoomEncryption for calling + // this twice for consecutive m.room.encryption events this._roomEncryption[roomId] = roomInfo; await this._cryptoStore.doTxn( 'readwrite', [IndexedDBCryptoStore.STORE_ROOMS], (txn) => { diff --git a/src/sync.js b/src/sync.js index 4aa2d2482..d8dffe6b3 100644 --- a/src/sync.js +++ b/src/sync.js @@ -1085,15 +1085,16 @@ SyncApi.prototype._processSyncResponse = async function( self._processEventsForNotifs(room, timelineEvents); - async function processRoomEvent(e) { + function processRoomEvent(e) { client.emit("event", e); if (e.isState() && e.getType() == "m.room.encryption" && self.opts.crypto) { - await self.opts.crypto.onCryptoEvent(e); + self.opts.crypto.onCryptoEvent(e); } } - await Promise.mapSeries(stateEvents, processRoomEvent); - await Promise.mapSeries(timelineEvents, processRoomEvent); + stateEvents.forEach(processRoomEvent); + timelineEvents.forEach(processRoomEvent); + ephemeralEvents.forEach(function(e) { client.emit("event", e); });