From d0d1f68a9cbc3f3700cc1ff0a47a37521cf6fedd Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 6 Nov 2020 16:56:12 +0100 Subject: [PATCH] WIP --- src/matrix/e2ee/megolm/Encryption.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/matrix/e2ee/megolm/Encryption.js b/src/matrix/e2ee/megolm/Encryption.js index a1257199..fea9cd29 100644 --- a/src/matrix/e2ee/megolm/Encryption.js +++ b/src/matrix/e2ee/megolm/Encryption.js @@ -43,15 +43,27 @@ export class Encryption { } } - async ensureOutboundSession(roomId, encryptionParams, txn) { + async ensureOutboundSession(roomId, encryptionParams) { let session = new this._olm.OutboundGroupSession(); try { - let sessionEntry = await txn.outboundGroupSessions.get(roomId); - const roomKeyMessage = this._readOrCreateSession(session, sessionEntry, roomId, encryptionParams, txn); - if (roomKeyMessage) { - this._writeSession(sessionEntry, session, roomId, txn); - return roomKeyMessage; + const txn = this._storage.readWriteTxn([ + this._storage.storeNames.inboundGroupSessions, + this._storage.storeNames.outboundGroupSessions, + ]); + let roomKeyMessage; + try { + let sessionEntry = await txn.outboundGroupSessions.get(roomId); + roomKeyMessage = this._readOrCreateSession(session, sessionEntry, roomId, encryptionParams, txn); + if (roomKeyMessage) { + this._writeSession(sessionEntry, session, roomId, txn); + return roomKeyMessage; + } + } catch (err) { + txn.abort(); + throw err; } + await txn.complete(); + return roomKeyMessage; } finally { session.free(); }