diff --git a/src/client.js b/src/client.js index 80d39ac27..95ffb77a3 100644 --- a/src/client.js +++ b/src/client.js @@ -186,7 +186,7 @@ function MatrixClient(opts) { // List of what rooms have encryption enabled: separate from crypto because // we still want to know what rooms are encrypted even if crypto is disabled: // we don't want to start sening unencrypted events to them. - this._roomList = new RoomList(this._cryptoStore); + this._roomList = new RoomList(this._cryptoStore, this._sessionStore); } utils.inherits(MatrixClient, EventEmitter); utils.extend(MatrixClient.prototype, MatrixBaseApis.prototype); diff --git a/src/crypto/RoomList.js b/src/crypto/RoomList.js index a0858b83a..613791f95 100644 --- a/src/crypto/RoomList.js +++ b/src/crypto/RoomList.js @@ -39,11 +39,13 @@ export default class RoomList { await this._cryptoStore.doTxn( 'readwrite', [IndexedDBCryptoStore.STORE_ROOMS], (txn) => { this._cryptoStore.getEndToEndRooms(txn, (result) => { - if (result === null) { + if (result === null || Object.keys(result).length === 0) { // migrate rom session store, if there's data there const sessionStoreRooms = this._sessionStore.getAllEndToEndRooms(); if (sessionStoreRooms !== null) { - this._cryptoStore.storeEndToEndRooms(sessionStoreRooms, txn); + for (const roomId of Object.keys(sessionStoreRooms)) { + this._cryptoStore.storeEndToEndRoom(roomId, sessionStoreRooms[roomId], txn); + } } this._roomEncryption = sessionStoreRooms; removeSessionStoreRooms = true; diff --git a/src/store/session/webstorage.js b/src/store/session/webstorage.js index ddab80a3d..9459697d4 100644 --- a/src/store/session/webstorage.js +++ b/src/store/session/webstorage.js @@ -178,9 +178,6 @@ WebStorageSessionStore.prototype = { * @return {object} roomId -> object with the end-to-end info for the room. */ getAllEndToEndRooms: function() { - return getJsonItem(this.store, keyEndToEndRoom(roomId)); - - const roomKeys = getKeysWithPrefix(this.store, keyEndToEndRoom('')); const results = {}; for (const k of roomKeys) {