This commit is contained in:
Bruno Windels 2020-11-06 16:56:12 +01:00
parent 5d12aef6db
commit d0d1f68a9c

View File

@ -43,15 +43,27 @@ export class Encryption {
} }
} }
async ensureOutboundSession(roomId, encryptionParams, txn) { async ensureOutboundSession(roomId, encryptionParams) {
let session = new this._olm.OutboundGroupSession(); let session = new this._olm.OutboundGroupSession();
try { try {
let sessionEntry = await txn.outboundGroupSessions.get(roomId); const txn = this._storage.readWriteTxn([
const roomKeyMessage = this._readOrCreateSession(session, sessionEntry, roomId, encryptionParams, txn); this._storage.storeNames.inboundGroupSessions,
if (roomKeyMessage) { this._storage.storeNames.outboundGroupSessions,
this._writeSession(sessionEntry, session, roomId, txn); ]);
return roomKeyMessage; 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 { } finally {
session.free(); session.free();
} }