Extract events to their own file
This commit is contained in:
parent
1f368dcec1
commit
c8f4cb5046
5 changed files with 37 additions and 18 deletions
|
@ -14,10 +14,11 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
import {Store} from "../Store"
|
import {Store} from "../Store"
|
||||||
|
import {Content} from "../../types";
|
||||||
|
|
||||||
interface AccountDataEntry {
|
interface AccountDataEntry {
|
||||||
type: string
|
type: string
|
||||||
content: { [key : string] : any }
|
content: Content
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AccountDataStore {
|
export class AccountDataStore {
|
||||||
|
|
|
@ -17,12 +17,13 @@ limitations under the License.
|
||||||
import { encodeUint32, decodeUint32 } from "../utils";
|
import { encodeUint32, decodeUint32 } from "../utils";
|
||||||
import {KeyLimits} from "../../common";
|
import {KeyLimits} from "../../common";
|
||||||
import {Store} from "../Store"
|
import {Store} from "../Store"
|
||||||
|
import {Content} from "../../types";
|
||||||
|
|
||||||
interface PendingEntry {
|
interface PendingEntry {
|
||||||
roomId: string
|
roomId: string
|
||||||
queueIndex: number
|
queueIndex: number
|
||||||
eventType: string
|
eventType: string
|
||||||
content: any
|
content: Content
|
||||||
relatexTxnId: string | null
|
relatexTxnId: string | null
|
||||||
relatedEventId: string | null
|
relatedEventId: string | null
|
||||||
txnId?: string
|
txnId?: string
|
||||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
|
|
||||||
import {MAX_UNICODE} from "./common";
|
import {MAX_UNICODE} from "./common";
|
||||||
import {Store} from "../Store";
|
import {Store} from "../Store";
|
||||||
|
import {StateEvent} from "../../types";
|
||||||
|
|
||||||
function encodeKey(roomId: string, eventType: string, stateKey: string) {
|
function encodeKey(roomId: string, eventType: string, stateKey: string) {
|
||||||
return `${roomId}|${eventType}|${stateKey}`;
|
return `${roomId}|${eventType}|${stateKey}`;
|
||||||
|
@ -24,7 +25,7 @@ function encodeKey(roomId: string, eventType: string, stateKey: string) {
|
||||||
|
|
||||||
export interface RoomStateEntry {
|
export interface RoomStateEntry {
|
||||||
roomId: string,
|
roomId: string,
|
||||||
event: any
|
event: StateEvent
|
||||||
key: string
|
key: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ export class RoomStateStore {
|
||||||
return this._roomStateStore.get(key);
|
return this._roomStateStore.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
set(roomId: string, event: any): Promise<IDBValidKey> {
|
set(roomId: string, event: StateEvent): Promise<IDBValidKey> {
|
||||||
const key = encodeKey(roomId, event.type, event.state_key);
|
const key = encodeKey(roomId, event.type, event.state_key);
|
||||||
const entry = {roomId, event, key};
|
const entry = {roomId, event, key};
|
||||||
return this._roomStateStore.put(entry);
|
return this._roomStateStore.put(entry);
|
||||||
|
|
|
@ -19,19 +19,7 @@ import { StorageError } from "../../common";
|
||||||
import { encodeUint32 } from "../utils";
|
import { encodeUint32 } from "../utils";
|
||||||
import {KeyLimits} from "../../common";
|
import {KeyLimits} from "../../common";
|
||||||
import {Store} from "../Store";
|
import {Store} from "../Store";
|
||||||
|
import {RoomEvent, StateEvent} from "../../types";
|
||||||
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 }
|
|
||||||
|
|
||||||
interface Annotation {
|
interface Annotation {
|
||||||
count: number
|
count: number
|
||||||
|
@ -43,7 +31,7 @@ interface StorageEntry {
|
||||||
roomId: string
|
roomId: string
|
||||||
fragmentId: number
|
fragmentId: number
|
||||||
eventIndex: number
|
eventIndex: number
|
||||||
event: Event | StateEvent
|
event: RoomEvent | StateEvent
|
||||||
displayName?: string
|
displayName?: string
|
||||||
avatarUrl?: string
|
avatarUrl?: string
|
||||||
annotations?: { [key : string]: Annotation }
|
annotations?: { [key : string]: Annotation }
|
||||||
|
|
28
src/matrix/storage/types.ts
Normal file
28
src/matrix/storage/types.ts
Normal file
|
@ -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 }
|
Reference in a new issue