From c43ccb860ba603bd8f79a2c41a93c3b80e5e60d7 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 2 Jan 2018 13:31:57 +0000 Subject: [PATCH] Always migrate inbound group sessions --- src/crypto/OlmDevice.js | 51 ++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/crypto/OlmDevice.js b/src/crypto/OlmDevice.js index 3d0640740..634d96144 100644 --- a/src/crypto/OlmDevice.js +++ b/src/crypto/OlmDevice.js @@ -223,37 +223,30 @@ OlmDevice.prototype._migrateFromSessionStore = async function() { let numIbSessions = 0; await this._cryptoStore.doTxn( 'readwrite', [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], (txn) => { - this._cryptoStore.countEndToEndInboundGroupSessions(txn, (count) => { - if (count) { - console.log( - "Cryto store already has inbound group sessions: "+ - "not migrating", + // We always migrate inbound group sessions, even if we already have some + // in the new store. They should be be safe to migrate. + for (const s of ibGroupSessions) { + try { + this._cryptoStore.addEndToEndInboundGroupSession( + s.senderKey, s.sessionId, + JSON.parse( + this._sessionStore.getEndToEndInboundGroupSession( + s.senderKey, s.sessionId, + ), + ), txn, + ); + } catch (e) { + console.warn( + "Failed to import session " + s.senderKey + "/" + + s.sessionId + ": " + e.stack || e, ); - return; } - for (const s of ibGroupSessions) { - try { - this._cryptoStore.addEndToEndInboundGroupSession( - s.senderKey, s.sessionId, - JSON.parse( - this._sessionStore.getEndToEndInboundGroupSession( - s.senderKey, s.sessionId, - ), - ), txn, - ); - } catch (e) { - console.warn( - "Failed to import session " + s.senderKey + "/" + - s.sessionId + ": " + e.stack || e, - ); - } - ++numIbSessions; - } - console.log( - "Migrating " + numIbSessions + - " inbound group sessions from session store", - ); - }); + ++numIbSessions; + } + console.log( + "Migrating " + numIbSessions + + " inbound group sessions from session store", + ); }, ); this._sessionStore.removeAllEndToEndInboundGroupSessions();