diff --git a/src/matrix/storage/idb/Transaction.js b/src/matrix/storage/idb/Transaction.js index cc2cde4d..8b85b795 100644 --- a/src/matrix/storage/idb/Transaction.js +++ b/src/matrix/storage/idb/Transaction.js @@ -29,7 +29,7 @@ import {PendingEventStore} from "./stores/PendingEventStore"; import {UserIdentityStore} from "./stores/UserIdentityStore"; import {DeviceIdentityStore} from "./stores/DeviceIdentityStore"; import {OlmSessionStore} from "./stores/OlmSessionStore"; -import {InboundGroupSessionStore} from "./stores/InboundGroupSessionStore.js"; +import {InboundGroupSessionStore} from "./stores/InboundGroupSessionStore"; import {OutboundGroupSessionStore} from "./stores/OutboundGroupSessionStore"; import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore"; import {OperationStore} from "./stores/OperationStore"; diff --git a/src/matrix/storage/idb/stores/InboundGroupSessionStore.js b/src/matrix/storage/idb/stores/InboundGroupSessionStore.ts similarity index 60% rename from src/matrix/storage/idb/stores/InboundGroupSessionStore.js rename to src/matrix/storage/idb/stores/InboundGroupSessionStore.ts index 488f2510..c1ebfc63 100644 --- a/src/matrix/storage/idb/stores/InboundGroupSessionStore.js +++ b/src/matrix/storage/idb/stores/InboundGroupSessionStore.ts @@ -15,36 +15,49 @@ limitations under the License. */ import {MIN_UNICODE, MAX_UNICODE} from "./common"; +import {Store} from "../Store"; -function encodeKey(roomId, senderKey, sessionId) { +interface InboundGroupSession { + roomId: string; + senderKey: string; + sessionId: string; + session?: string; + claimedKeys?: { [algorithm : string] : string }; + eventIds?: string[]; + key: string; +} + +function encodeKey(roomId: string, senderKey: string, sessionId: string): string { return `${roomId}|${senderKey}|${sessionId}`; } export class InboundGroupSessionStore { - constructor(store) { + private _store: Store; + + constructor(store: Store) { this._store = store; } - async has(roomId, senderKey, sessionId) { + async has(roomId: string, senderKey: string, sessionId: string): Promise { const key = encodeKey(roomId, senderKey, sessionId); const fetchedKey = await this._store.getKey(key); return key === fetchedKey; } - get(roomId, senderKey, sessionId) { + get(roomId: string, senderKey: string, sessionId: string): Promise { return this._store.get(encodeKey(roomId, senderKey, sessionId)); } - set(session) { + set(session: InboundGroupSession): Promise { session.key = encodeKey(session.roomId, session.senderKey, session.sessionId); - this._store.put(session); + return this._store.put(session); } - removeAllForRoom(roomId) { + removeAllForRoom(roomId: string): Promise { const range = this._store.IDBKeyRange.bound( encodeKey(roomId, MIN_UNICODE, MIN_UNICODE), encodeKey(roomId, MAX_UNICODE, MAX_UNICODE) ); - this._store.delete(range); + return this._store.delete(range); } }