From bef02d238f9f4526b8ee792d037de270c618fda9 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 31 Aug 2021 15:12:09 -0700 Subject: [PATCH] Split keys out of stored data types --- .../idb/stores/GroupSessionDecryptionStore.ts | 13 ++++++------ .../storage/idb/stores/OperationStore.ts | 21 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/matrix/storage/idb/stores/GroupSessionDecryptionStore.ts b/src/matrix/storage/idb/stores/GroupSessionDecryptionStore.ts index 2b38c1fb..b6636f13 100644 --- a/src/matrix/storage/idb/stores/GroupSessionDecryptionStore.ts +++ b/src/matrix/storage/idb/stores/GroupSessionDecryptionStore.ts @@ -24,13 +24,14 @@ function encodeKey(roomId: string, sessionId: string, messageIndex: number | str interface GroupSessionDecryption { eventId: string; timestamp: number; - key: string; } -export class GroupSessionDecryptionStore { - private _store: Store; +type GroupSessionEntry = GroupSessionDecryption & { key: string } - constructor(store: Store) { +export class GroupSessionDecryptionStore { + private _store: Store; + + constructor(store: Store) { this._store = store; } @@ -39,8 +40,8 @@ export class GroupSessionDecryptionStore { } set(roomId: string, sessionId: string, messageIndex: number, decryption: GroupSessionDecryption): void { - decryption.key = encodeKey(roomId, sessionId, messageIndex); - this._store.put(decryption); + (decryption as GroupSessionEntry).key = encodeKey(roomId, sessionId, messageIndex); + this._store.put(decryption as GroupSessionEntry); } removeAllForRoom(roomId: string): Promise { diff --git a/src/matrix/storage/idb/stores/OperationStore.ts b/src/matrix/storage/idb/stores/OperationStore.ts index 080d3e66..cccd8e2d 100644 --- a/src/matrix/storage/idb/stores/OperationStore.ts +++ b/src/matrix/storage/idb/stores/OperationStore.ts @@ -20,15 +20,18 @@ export function encodeScopeTypeKey(scope: string, type: string): string { return `${scope}|${type}`; } -interface Operation { +interface BaseOperation { id: string; - type: string; scope: string; userIds: string[]; - scopeTypeKey: string; - roomKeyMessage: RoomKeyMessage; } +type OperationType = { type: "share_room_key"; roomKeyMessage: RoomKeyMessage; } + +type Operation = BaseOperation & OperationType + +type OperationEntry = Operation & { scopeTypeKey: string; } + interface RoomKeyMessage { room_id: string; session_id: string; @@ -38,9 +41,9 @@ interface RoomKeyMessage { } export class OperationStore { - private _store: Store; + private _store: Store; - constructor(store: Store) { + constructor(store: Store) { this._store = store; } @@ -62,12 +65,12 @@ export class OperationStore { } add(operation: Operation): void { - operation.scopeTypeKey = encodeScopeTypeKey(operation.scope, operation.type); - this._store.add(operation); + (operation as OperationEntry).scopeTypeKey = encodeScopeTypeKey(operation.scope, operation.type); + this._store.add(operation as OperationEntry); } update(operation: Operation): void { - this._store.put(operation); + this._store.put(operation as OperationEntry); } remove(id: string): Promise {