aboutsummaryrefslogtreecommitdiff
path: root/src/type/messageTypes.ts
blob: 0bc76ee90b241284c75f0e70c45d5fdb4fc43330 (plain)
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
export const enum MessageType {
        MESSAGE = "MESSAGE",
        CHNAME = "CHNAME",
        HELLO = "HELLO",
        DATA = "DATA",
}
export enum SystemMessageCode {
        REQ,
        RES,
        ERR,
}
export type HistoryFetchResult = {
        count: number;
        items: Array<ChatMessage>;
};
export type ErrorResult = {
        text: string;
};
export type TimestampSendRequest = {
        ts: number;
};
export type SystemMessage = {
        code: SystemMessageCode;
        data: HistoryFetchResult | ErrorResult | TimestampSendRequest;
};
export type ChatMessage = {
        fromUserId: string;
        toUserId: string;
        content: string;
        timeMillis: number;
};
export type HelloMessage = {
        fromUserId: string;
        timeMillis: number;
};
export type DataMessage = {};
export type Message = {
        type: MessageType;
        // data: SystemMessage | ChatMessage | HelloMessage
        fromUserId: string;
        toUserId: string;
        content: string;
        timeMillis: number;
};
// Type gymnastics to provide dynamic ESLint support
export const acceptedLangs = ["en_US", "zh_TW", "el_GR", "ar_SA"] as const;
export type LangType = (typeof acceptedLangs)[number];