From 9b4b303b01be1fca441203832a77aca924873895 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 11 Aug 2021 14:33:08 -0700 Subject: [PATCH] Add type annotations to RoomStateStore. Not sure how to type events, since they're so malleable. --- .../storage/idb/stores/RoomStateStore.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/matrix/storage/idb/stores/RoomStateStore.ts b/src/matrix/storage/idb/stores/RoomStateStore.ts index db54458f..ee7866a4 100644 --- a/src/matrix/storage/idb/stores/RoomStateStore.ts +++ b/src/matrix/storage/idb/stores/RoomStateStore.ts @@ -16,31 +16,40 @@ limitations under the License. */ import {MAX_UNICODE} from "./common"; +import {Store} from "../Store"; -function encodeKey(roomId, eventType, stateKey) { +function encodeKey(roomId: string, eventType: string, stateKey: string) { return `${roomId}|${eventType}|${stateKey}`; } +interface RoomStateEntry { + roomId: string, + event: any + key: string +} + export class RoomStateStore { - constructor(idbStore) { + private _roomStateStore: Store + + constructor(idbStore: Store) { this._roomStateStore = idbStore; } - get(roomId, type, stateKey) { + get(roomId: string, type: string, stateKey: string): Promise { const key = encodeKey(roomId, type, stateKey); return this._roomStateStore.get(key); } - set(roomId, event) { + set(roomId: string, event: any): Promise { const key = encodeKey(roomId, event.type, event.state_key); const entry = {roomId, event, key}; return this._roomStateStore.put(entry); } - removeAllForRoom(roomId) { + removeAllForRoom(roomId: string): Promise { // exclude both keys as they are theoretical min and max, // but we should't have a match for just the room id, or room id with max const range = this._roomStateStore.IDBKeyRange.bound(roomId, `${roomId}|${MAX_UNICODE}`, true, true); - this._roomStateStore.delete(range); + return this._roomStateStore.delete(range); } }