From 63810186582bcbf94ff4426e6cc7414dfd8cbdfc Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Tue, 16 Mar 2021 13:52:05 -0400 Subject: [PATCH] add jsdoc and implementation for memory crypto store --- src/crypto/store/indexeddb-crypto-store.js | 15 +++++++++++++-- src/crypto/store/memory-crypto-store.js | 12 ++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/crypto/store/indexeddb-crypto-store.js b/src/crypto/store/indexeddb-crypto-store.js index 3fe53a6d7..4cfe36128 100644 --- a/src/crypto/store/indexeddb-crypto-store.js +++ b/src/crypto/store/indexeddb-crypto-store.js @@ -582,14 +582,25 @@ export class IndexedDBCryptoStore { return this._backend.markSessionsNeedingBackup(sessions, txn); } - /* FIXME: jsdoc + /** + * Add a shared-history group session for a room. + * @param {string} roomId The room that the key belongs to + * @param {string} senderKey The sender's curve 25519 key + * @param {string} sessionId The ID of the session + * @param {*} txn An active transaction. See doTxn(). (optional) */ addSharedHistoryInboundGroupSession(roomId, senderKey, sessionId, txn) { - return this._backend.addSharedHistoryInboundGroupSession( + this._backend.addSharedHistoryInboundGroupSession( roomId, senderKey, sessionId, txn, ); } + /** + * Get the shared-history group session for a room. + * @param {string} roomId The room that the key belongs to + * @param {*} txn An active transaction. See doTxn(). (optional) + * @returns {Promise} Resolves to an array of [senderKey, sessionId] + */ getSharedHistoryInboundGroupSessions(roomId, txn) { return this._backend.getSharedHistoryInboundGroupSessions(roomId, txn); } diff --git a/src/crypto/store/memory-crypto-store.js b/src/crypto/store/memory-crypto-store.js index 5170fb2c3..ac4e7be0b 100644 --- a/src/crypto/store/memory-crypto-store.js +++ b/src/crypto/store/memory-crypto-store.js @@ -51,6 +51,8 @@ export class MemoryCryptoStore { this._rooms = {}; // Set of {senderCurve25519Key+'/'+sessionId} this._sessionsNeedingBackup = {}; + // roomId -> array of [senderKey, sessionId] + this._sharedHistoryInboundGroupSessions = {}; } /** @@ -467,6 +469,16 @@ export class MemoryCryptoStore { return Promise.resolve(); } + addSharedHistoryInboundGroupSession(roomId, senderKey, sessionId) { + const sessions = this._sharedHistoryInboundGroupSessions[roomId] || []; + sessions.push([senderKey, sessionId]); + this._sharedHistoryInboundGroupSessions[roomId] = sessions; + } + + getSharedHistoryInboundGroupSessions(roomId) { + return Promise.resolve(this._sharedHistoryInboundGroupSessions[roomId] || []); + } + // Session key backups doTxn(mode, stores, func) {