implement store changes for olm encryption

This commit is contained in:
Bruno Windels 2020-09-03 15:33:03 +02:00
parent 792f0cf9a0
commit dde8c66196

View File

@ -18,11 +18,31 @@ function encodeKey(senderKey, sessionId) {
return `${senderKey}|${sessionId}`; return `${senderKey}|${sessionId}`;
} }
function decodeKey(key) {
const [senderKey, sessionId] = key.split("|");
return {senderKey, sessionId};
}
export class OlmSessionStore { export class OlmSessionStore {
constructor(store) { constructor(store) {
this._store = 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) { getAll(senderKey) {
const range = IDBKeyRange.lowerBound(encodeKey(senderKey, "")); const range = IDBKeyRange.lowerBound(encodeKey(senderKey, ""));
return this._store.selectWhile(range, session => { return this._store.selectWhile(range, session => {