diff --git a/lib/shared/dm-ops/create-thread-spec.js b/lib/shared/dm-ops/create-thread-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/dm-ops/create-thread-spec.js @@ -0,0 +1,14 @@ +// @flow + +import type { DMOperationSpec } from './dm-op-spec.js'; +import type { DMCreateThreadOperation } from '../../types/dm-ops.js'; + +export const createThreadSpec: DMOperationSpec = + Object.freeze({ + processDMOperation: async () => { + return { + rawMessageInfos: [], + updateInfos: [], + }; + }, + }); diff --git a/lib/shared/dm-ops/dm-op-spec.js b/lib/shared/dm-ops/dm-op-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/dm-ops/dm-op-spec.js @@ -0,0 +1,17 @@ +// @flow + +import type { DMOperation, DMOperationResult } from '../../types/dm-ops.js'; +import type { RawMessageInfo } from '../../types/message-types.js'; + +export type ProcessDMOperationUtilities = { + // Needed to fetch sidebar source messages + +fetchMessage: (messageID: string) => Promise, +}; + +export type DMOperationSpec = { + +processDMOperation: ( + dmOp: DMOp, + viewerID: string, + utilities: ProcessDMOperationUtilities, + ) => Promise, +}; diff --git a/lib/shared/dm-ops/dm-op-specs.js b/lib/shared/dm-ops/dm-op-specs.js new file mode 100644 --- /dev/null +++ b/lib/shared/dm-ops/dm-op-specs.js @@ -0,0 +1,13 @@ +// @flow + +import { createThreadSpec } from './create-thread-spec.js'; +import type { DMOperationSpec } from './dm-op-spec.js'; +import { sendTextMessageSpec } from './send-text-message-spec.js'; +import { type DMOperationType, dmOperationTypes } from '../../types/dm-ops.js'; + +export const dmOpSpecs: { + +[DMOperationType]: DMOperationSpec, +} = Object.freeze({ + [dmOperationTypes.CREATE_THREAD]: createThreadSpec, + [dmOperationTypes.SEND_TEXT_MESSAGE]: sendTextMessageSpec, +}); diff --git a/lib/shared/dm-ops/send-text-message-spec.js b/lib/shared/dm-ops/send-text-message-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/dm-ops/send-text-message-spec.js @@ -0,0 +1,14 @@ +// @flow + +import type { DMOperationSpec } from './dm-op-spec.js'; +import type { DMSendTextMessageOperation } from '../../types/dm-ops.js'; + +export const sendTextMessageSpec: DMOperationSpec = + Object.freeze({ + processDMOperation: async () => { + return { + rawMessageInfos: [], + updateInfos: [], + }; + }, + }); diff --git a/lib/types/dm-ops.js b/lib/types/dm-ops.js new file mode 100644 --- /dev/null +++ b/lib/types/dm-ops.js @@ -0,0 +1,63 @@ +// @flow + +import type { TInterface } from 'tcomb'; +import t from 'tcomb'; + +import type { RawMessageInfo } from './message-types.js'; +import { type ThickThreadType, thickThreadTypes } from './thread-types-enum.js'; +import type { ClientUpdateInfo } from './update-types.js'; +import { values } from '../utils/objects.js'; +import { tShape, tString, tUserID } from '../utils/validation-utils.js'; + +export const dmOperationTypes = Object.freeze({ + CREATE_THREAD: 'create_thread', + SEND_TEXT_MESSAGE: 'send_text_message', +}); +export type DMOperationType = $Values; + +export type DMCreateThreadOperation = { + +type: 'create_thread', + +threadID: string, + +creatorID: string, + +time: number, + +threadType: ThickThreadType, + +parentThreadID?: ?string, + +memberIDs: $ReadOnlyArray, + +sourceMessageID?: ?string, +}; +export const dmCreateThreadOperationValidator: TInterface = + tShape({ + type: tString(dmOperationTypes.CREATE_THREAD), + threadID: t.String, + creatorID: tUserID, + time: t.Number, + threadType: t.enums.of(values(thickThreadTypes)), + parentThreadID: t.maybe(t.String), + memberIDs: t.list(tUserID), + sourceMessageID: t.maybe(t.String), + }); + +export type DMSendTextMessageOperation = { + +type: 'send_text_message', + +threadID: string, + +creatorID: string, + +time: number, + +messageID: string, + +text: string, +}; +export const dmSendTextMessageOperationValidator: TInterface = + tShape({ + type: tString(dmOperationTypes.SEND_TEXT_MESSAGE), + threadID: t.String, + creatorID: tUserID, + time: t.Number, + messageID: t.String, + text: t.String, + }); + +export type DMOperation = DMCreateThreadOperation | DMSendTextMessageOperation; + +export type DMOperationResult = { + rawMessageInfos: Array, + updateInfos: Array, +};