Changeset View
Changeset View
Standalone View
Standalone View
lib/types/messages/create-thread.js
// @flow | // @flow | ||||
import type { ThreadInfo, ThreadType } from '../thread-types.js'; | import t, { type TInterface } from 'tcomb'; | ||||
import { values } from '../../utils/objects.js'; | |||||
import { | |||||
tID, | |||||
tNumber, | |||||
tShape, | |||||
tNumEnum, | |||||
} from '../../utils/validation-utils.js'; | |||||
import { messageTypes } from '../message-types-enum.js'; | |||||
import { | |||||
threadTypes, | |||||
type ThreadInfo, | |||||
type ThreadType, | |||||
} from '../thread-types.js'; | |||||
import type { RelativeUserInfo } from '../user-types.js'; | import type { RelativeUserInfo } from '../user-types.js'; | ||||
export type CreateThreadMessageData = { | export type CreateThreadMessageData = { | ||||
type: 1, | type: 1, | ||||
threadID: string, | threadID: string, | ||||
creatorID: string, | creatorID: string, | ||||
time: number, | time: number, | ||||
initialThreadState: { | initialThreadState: { | ||||
type: ThreadType, | type: ThreadType, | ||||
name: ?string, | name: ?string, | ||||
parentThreadID: ?string, | parentThreadID: ?string, | ||||
color: string, | color: string, | ||||
memberIDs: string[], | memberIDs: string[], | ||||
}, | }, | ||||
}; | }; | ||||
export type RawCreateThreadMessageInfo = { | export type RawCreateThreadMessageInfo = { | ||||
...CreateThreadMessageData, | ...CreateThreadMessageData, | ||||
id: string, | id: string, | ||||
}; | }; | ||||
export const rawCreateThreadMessageInfoValidator: TInterface<RawCreateThreadMessageInfo> = | |||||
tShape<RawCreateThreadMessageInfo>({ | |||||
type: tNumber(messageTypes.CREATE_THREAD), | |||||
threadID: tID, | |||||
creatorID: t.String, | |||||
time: t.Number, | |||||
initialThreadState: tShape({ | |||||
type: tNumEnum(values(threadTypes)), | |||||
name: t.maybe(t.String), | |||||
parentThreadID: t.maybe(tID), | |||||
color: t.String, | |||||
memberIDs: t.list(t.String), | |||||
}), | |||||
id: tID, | |||||
}); | |||||
export type CreateThreadMessageInfo = { | export type CreateThreadMessageInfo = { | ||||
type: 1, | type: 1, | ||||
id: string, | id: string, | ||||
threadID: string, | threadID: string, | ||||
creator: RelativeUserInfo, | creator: RelativeUserInfo, | ||||
time: number, | time: number, | ||||
initialThreadState: { | initialThreadState: { | ||||
type: ThreadType, | type: ThreadType, | ||||
name: ?string, | name: ?string, | ||||
parentThreadInfo: ?ThreadInfo, | parentThreadInfo: ?ThreadInfo, | ||||
color: string, | color: string, | ||||
otherMembers: RelativeUserInfo[], | otherMembers: RelativeUserInfo[], | ||||
}, | }, | ||||
}; | }; |