/
text.js
47 lines (40 loc) · 1.16 KB
/
text.js
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
// @flow
import t, { type TInterface } from 'tcomb';
import { tID, tNumber, tShape, tUserID } from '../../utils/validation-utils.js';
import { messageTypes } from '../message-types-enum.js';
import type { RelativeUserInfo } from '../user-types.js';
type TextSharedBase = {
+type: 0,
+localID?: string, // for optimistic creations. included by new clients
+threadID: string,
+creatorID: string,
+time: number,
+text: string,
};
export type TextMessageData = {
...TextSharedBase,
+sidebarCreation?: boolean,
};
export type RawTextMessageInfo = {
...TextSharedBase,
+id?: string, // null if local copy without ID yet
};
export const rawTextMessageInfoValidator: TInterface<RawTextMessageInfo> =
tShape<RawTextMessageInfo>({
type: tNumber(messageTypes.TEXT),
localID: t.maybe(t.String),
threadID: tID,
creatorID: tUserID,
time: t.Number,
text: t.String,
id: t.maybe(tID),
});
export type TextMessageInfo = {
+type: 0,
+id?: string, // null if local copy without ID yet
+localID?: string, // for optimistic creations
+threadID: string,
+creator: RelativeUserInfo,
+time: number, // millisecond timestamp
+text: string,
};