From 8c966627bc92aeb3dba3c0e00d13524dc36c55de Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 12 Aug 2021 10:41:58 -0700 Subject: [PATCH] Migrate GroupSessionDecryptionStore to TypeScript --- src/matrix/storage/idb/Transaction.js | 2 +- ...tore.js => GroupSessionDecryptionStore.ts} | 23 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) rename src/matrix/storage/idb/stores/{GroupSessionDecryptionStore.js => GroupSessionDecryptionStore.ts} (61%) diff --git a/src/matrix/storage/idb/Transaction.js b/src/matrix/storage/idb/Transaction.js index 092bbb05..8b19af37 100644 --- a/src/matrix/storage/idb/Transaction.js +++ b/src/matrix/storage/idb/Transaction.js @@ -31,7 +31,7 @@ import {DeviceIdentityStore} from "./stores/DeviceIdentityStore.js"; import {OlmSessionStore} from "./stores/OlmSessionStore.js"; import {InboundGroupSessionStore} from "./stores/InboundGroupSessionStore.js"; import {OutboundGroupSessionStore} from "./stores/OutboundGroupSessionStore"; -import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore.js"; +import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore"; import {OperationStore} from "./stores/OperationStore.js"; import {AccountDataStore} from "./stores/AccountDataStore.js"; diff --git a/src/matrix/storage/idb/stores/GroupSessionDecryptionStore.js b/src/matrix/storage/idb/stores/GroupSessionDecryptionStore.ts similarity index 61% rename from src/matrix/storage/idb/stores/GroupSessionDecryptionStore.js rename to src/matrix/storage/idb/stores/GroupSessionDecryptionStore.ts index da47639d..a55bf66b 100644 --- a/src/matrix/storage/idb/stores/GroupSessionDecryptionStore.js +++ b/src/matrix/storage/idb/stores/GroupSessionDecryptionStore.ts @@ -15,30 +15,39 @@ limitations under the License. */ import {MIN_UNICODE, MAX_UNICODE} from "./common"; +import {Store} from "../Store"; -function encodeKey(roomId, sessionId, messageIndex) { +function encodeKey(roomId: string, sessionId: string, messageIndex: number | string): string { return `${roomId}|${sessionId}|${messageIndex}`; } +interface GroupSessionDecryption { + eventId: string; + timestamp: number; + key: string; +} + export class GroupSessionDecryptionStore { - constructor(store) { + private _store: Store; + + constructor(store: Store) { this._store = store; } - get(roomId, sessionId, messageIndex) { + get(roomId: string, sessionId: string, messageIndex: number): Promise { return this._store.get(encodeKey(roomId, sessionId, messageIndex)); } - set(roomId, sessionId, messageIndex, decryption) { + set(roomId: string, sessionId: string, messageIndex: number, decryption: GroupSessionDecryption): Promise { decryption.key = encodeKey(roomId, sessionId, messageIndex); - this._store.put(decryption); + return this._store.put(decryption); } - 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); } }