diff --git a/src/matrix/storage/idb/stores/OlmSessionStore.js b/src/matrix/storage/idb/stores/OlmSessionStore.js index c94b3bfd..4648f09c 100644 --- a/src/matrix/storage/idb/stores/OlmSessionStore.js +++ b/src/matrix/storage/idb/stores/OlmSessionStore.js @@ -18,11 +18,31 @@ function encodeKey(senderKey, sessionId) { return `${senderKey}|${sessionId}`; } +function decodeKey(key) { + const [senderKey, sessionId] = key.split("|"); + return {senderKey, sessionId}; +} + export class OlmSessionStore { constructor(store) { this._store = store; } + async getSessionIds(senderKey) { + const sessionIds = []; + const range = IDBKeyRange.lowerBound(encodeKey(senderKey, "")); + await this._store.iterateKeys(range, key => { + const decodedKey = decodeKey(key); + // prevent running into the next room + if (decodedKey.senderKey === senderKey) { + sessionIds.push(decodedKey.sessionId); + return false; // fetch more + } + return true; // done + }); + return sessionIds; + } + getAll(senderKey) { const range = IDBKeyRange.lowerBound(encodeKey(senderKey, "")); return this._store.selectWhile(range, session => {