mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
implement store changes for olm encryption
This commit is contained in:
parent
792f0cf9a0
commit
dde8c66196
@ -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 => {
|
||||||
|
Loading…
Reference in New Issue
Block a user