diff --git a/src/matrix/storage/idb/stores/AccountDataStore.ts b/src/matrix/storage/idb/stores/AccountDataStore.ts index 1a7e3e68..f32f8aee 100644 --- a/src/matrix/storage/idb/stores/AccountDataStore.ts +++ b/src/matrix/storage/idb/stores/AccountDataStore.ts @@ -14,10 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. */ import {Store} from "../Store" +import {Content} from "../../types"; interface AccountDataEntry { type: string - content: { [key : string] : any } + content: Content } export class AccountDataStore { diff --git a/src/matrix/storage/idb/stores/PendingEventStore.ts b/src/matrix/storage/idb/stores/PendingEventStore.ts index 62f115b0..3bd1e793 100644 --- a/src/matrix/storage/idb/stores/PendingEventStore.ts +++ b/src/matrix/storage/idb/stores/PendingEventStore.ts @@ -17,12 +17,13 @@ limitations under the License. import { encodeUint32, decodeUint32 } from "../utils"; import {KeyLimits} from "../../common"; import {Store} from "../Store" +import {Content} from "../../types"; interface PendingEntry { roomId: string queueIndex: number eventType: string - content: any + content: Content relatexTxnId: string | null relatedEventId: string | null txnId?: string diff --git a/src/matrix/storage/idb/stores/RoomStateStore.ts b/src/matrix/storage/idb/stores/RoomStateStore.ts index 5d624c66..a206c1ea 100644 --- a/src/matrix/storage/idb/stores/RoomStateStore.ts +++ b/src/matrix/storage/idb/stores/RoomStateStore.ts @@ -17,6 +17,7 @@ limitations under the License. import {MAX_UNICODE} from "./common"; import {Store} from "../Store"; +import {StateEvent} from "../../types"; function encodeKey(roomId: string, eventType: string, stateKey: string) { return `${roomId}|${eventType}|${stateKey}`; @@ -24,7 +25,7 @@ function encodeKey(roomId: string, eventType: string, stateKey: string) { export interface RoomStateEntry { roomId: string, - event: any + event: StateEvent key: string } @@ -40,7 +41,7 @@ export class RoomStateStore { return this._roomStateStore.get(key); } - set(roomId: string, event: any): Promise { + set(roomId: string, event: StateEvent): Promise { const key = encodeKey(roomId, event.type, event.state_key); const entry = {roomId, event, key}; return this._roomStateStore.put(entry); diff --git a/src/matrix/storage/idb/stores/TimelineEventStore.ts b/src/matrix/storage/idb/stores/TimelineEventStore.ts index d05fa6cb..d62974d3 100644 --- a/src/matrix/storage/idb/stores/TimelineEventStore.ts +++ b/src/matrix/storage/idb/stores/TimelineEventStore.ts @@ -19,19 +19,7 @@ import { StorageError } from "../../common"; import { encodeUint32 } from "../utils"; import {KeyLimits} from "../../common"; import {Store} from "../Store"; - -type Content = { [key: string]: any } - -interface RoomEvent { - content: Content - type: string - event_id: string - sender: string - origin_server_ts: number - unsigned?: Content -} - -type StateEvent = RoomEvent & { prev_content?: Content, state_key: string } +import {RoomEvent, StateEvent} from "../../types"; interface Annotation { count: number @@ -43,7 +31,7 @@ interface StorageEntry { roomId: string fragmentId: number eventIndex: number - event: Event | StateEvent + event: RoomEvent | StateEvent displayName?: string avatarUrl?: string annotations?: { [key : string]: Annotation } diff --git a/src/matrix/storage/types.ts b/src/matrix/storage/types.ts new file mode 100644 index 00000000..142baeb1 --- /dev/null +++ b/src/matrix/storage/types.ts @@ -0,0 +1,28 @@ +/* +Copyright 2021 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +export type Content = { [key: string]: any } + +export interface RoomEvent { + content: Content + type: string + event_id: string + sender: string + origin_server_ts: number + unsigned?: Content +} + +export type StateEvent = RoomEvent & { prev_content?: Content, state_key: string }