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}`;
}
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 => {