This repository has been archived by the owner on Feb 10, 2024. It is now read-only.
/
RoomStateEventEntity.ts
73 lines (67 loc) · 2.34 KB
/
RoomStateEventEntity.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2022. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.
import { createRoomEventEntity, RoomEventEntity } from "./RoomEventEntity";
import { MatrixType } from "../../../../../types/core/MatrixType";
import { isReadonlyJsonObject, ReadonlyJsonObject } from "../../../../../../core/Json";
import { isString } from "../../../../../../core/types/String";
import { isNumber } from "../../../../../../core/types/Number";
import { isRegularObject } from "../../../../../../core/types/RegularObject";
import { hasNoOtherKeys } from "../../../../../../core/types/OtherKeys";
/**
* Base type for room state events saved in the repository.
*/
export interface RoomStateEventEntity extends RoomEventEntity {
readonly id : string;
readonly type : MatrixType | string;
readonly content : ReadonlyJsonObject;
readonly originServerTs : number;
readonly senderId : string;
readonly roomId : string;
readonly stateKey : string;
}
export function createRoomStateEventEntity (
id : string,
type : MatrixType | string,
content : ReadonlyJsonObject,
originServerTs : number,
senderId : string,
roomId : string,
stateKey : string,
): RoomStateEventEntity {
return <RoomStateEventEntity> createRoomEventEntity(
id,
type,
content,
originServerTs,
senderId,
roomId,
stateKey
);
}
export function isRoomStateEvent (value: any): value is RoomStateEventEntity {
return (
isRegularObject(value)
&& hasNoOtherKeys(value, [
'id',
'type',
'originServerTs',
'senderId',
'roomId',
'content',
'stateKey'
])
&& isString(value?.id)
&& isString(value?.type)
&& isNumber(value?.originServerTs)
&& isString(value?.senderId)
&& isString(value?.roomId)
&& isReadonlyJsonObject(value?.content)
&& isString(value?.stateKey)
);
}
export function stringifyRoomStateEvent (value: RoomStateEventEntity): string {
return `RoomStateEvent(${value})`;
}
export function parseRoomStateEvent (value: any): RoomStateEventEntity | undefined {
if ( isRoomStateEvent(value) ) return value;
return undefined;
}