Page MenuHomePhabricator

D13121.id43550.diff
No OneTemporary

D13121.id43550.diff

diff --git a/lib/shared/dm-ops/add-members-spec.js b/lib/shared/dm-ops/add-members-spec.js
--- a/lib/shared/dm-ops/add-members-spec.js
+++ b/lib/shared/dm-ops/add-members-spec.js
@@ -11,6 +11,7 @@
import type { DMAddMembersOperation } from '../../types/dm-ops.js';
import { messageTypes } from '../../types/message-types-enum.js';
import { type RawMessageInfo } from '../../types/message-types.js';
+import type { AddMembersMessageData } from '../../types/messages/add-members.js';
import {
minimallyEncodeMemberInfo,
type ThickRawThreadInfo,
@@ -20,6 +21,7 @@
import { updateTypes } from '../../types/update-types-enum.js';
import type { ClientUpdateInfo } from '../../types/update-types.js';
import { values } from '../../utils/objects.js';
+import { rawMessageInfoFromMessageData } from '../message-utils.js';
import { roleIsDefaultRole, userIsMember } from '../thread-utils.js';
export type AddMembersResult = {
@@ -28,20 +30,32 @@
threadInfo: ?ThickRawThreadInfo,
};
+function createAddNewMembersMessageDatasFromDMOperation(
+ dmOperation: DMAddMembersOperation,
+): $ReadOnlyArray<AddMembersMessageData> {
+ const { editorID, time, addedUserIDs, threadID } = dmOperation;
+ return [
+ {
+ type: messageTypes.ADD_MEMBERS,
+ threadID,
+ creatorID: editorID,
+ time,
+ addedUserIDs: [...addedUserIDs],
+ },
+ ];
+}
+
function createAddNewMembersResults(
dmOperation: DMAddMembersOperation,
viewerID: string,
utilities: ProcessDMOperationUtilities,
): AddMembersResult {
const { editorID, time, messageID, addedUserIDs, threadID } = dmOperation;
- const addMembersMessage = {
- type: messageTypes.ADD_MEMBERS,
- id: messageID,
- threadID,
- creatorID: editorID,
- time,
- addedUserIDs: [...addedUserIDs],
- };
+ const messageDatas =
+ createAddNewMembersMessageDatasFromDMOperation(dmOperation);
+ const rawMessageInfos = messageDatas.map(messageData =>
+ rawMessageInfoFromMessageData(messageData, messageID),
+ );
const currentThreadInfo = utilities.threadInfos[threadID];
if (!currentThreadInfo.thick) {
@@ -86,13 +100,16 @@
];
return {
- rawMessageInfos: [addMembersMessage],
+ rawMessageInfos,
updateInfos,
threadInfo: resultThreadInfo,
};
}
const addMembersSpec: DMOperationSpec<DMAddMembersOperation> = Object.freeze({
+ messageDataFromDMOperation: async (dmOperation: DMAddMembersOperation) => {
+ return createAddNewMembersMessageDatasFromDMOperation(dmOperation);
+ },
processDMOperation: async (
dmOperation: DMAddMembersOperation,
viewerID: string,
@@ -123,4 +140,8 @@
},
});
-export { addMembersSpec, createAddNewMembersResults };
+export {
+ addMembersSpec,
+ createAddNewMembersResults,
+ createAddNewMembersMessageDatasFromDMOperation,
+};
diff --git a/lib/shared/dm-ops/add-viewer-to-thread-members-spec.js b/lib/shared/dm-ops/add-viewer-to-thread-members-spec.js
--- a/lib/shared/dm-ops/add-viewer-to-thread-members-spec.js
+++ b/lib/shared/dm-ops/add-viewer-to-thread-members-spec.js
@@ -8,22 +8,36 @@
import type { DMAddViewerToThreadMembersOperation } from '../../types/dm-ops.js';
import { messageTypes } from '../../types/message-types-enum.js';
import { messageTruncationStatus } from '../../types/message-types.js';
+import type { AddMembersMessageData } from '../../types/messages/add-members.js';
import { updateTypes } from '../../types/update-types-enum.js';
+import { rawMessageInfoFromMessageData } from '../message-utils.js';
+
+function createAddViewerToThreadMembersMessageDataFromDMOp(
+ dmOperation: DMAddViewerToThreadMembersOperation,
+): $ReadOnlyArray<AddMembersMessageData> {
+ const { editorID, time, addedUserIDs, existingThreadDetails } = dmOperation;
+ return [
+ {
+ type: messageTypes.ADD_MEMBERS,
+ threadID: existingThreadDetails.threadID,
+ creatorID: editorID,
+ time,
+ addedUserIDs: [...addedUserIDs],
+ },
+ ];
+}
function createAddViewerToThreadMembersResults(
dmOperation: DMAddViewerToThreadMembersOperation,
viewerID: string,
): AddMembersResult {
- const { editorID, time, messageID, addedUserIDs, existingThreadDetails } =
- dmOperation;
- const addMembersMessage = {
- type: messageTypes.ADD_MEMBERS,
- id: messageID,
- threadID: existingThreadDetails.threadID,
- creatorID: editorID,
- time,
- addedUserIDs: [...addedUserIDs],
- };
+ const { time, messageID, addedUserIDs, existingThreadDetails } = dmOperation;
+ const messageDatas =
+ createAddViewerToThreadMembersMessageDataFromDMOp(dmOperation);
+
+ const rawMessageInfos = messageDatas.map(messageData =>
+ rawMessageInfoFromMessageData(messageData, messageID),
+ );
const resultThreadInfo = createThickRawThreadInfo(
{
@@ -38,7 +52,7 @@
id: uuid.v4(),
time,
threadInfo: resultThreadInfo,
- rawMessageInfos: [addMembersMessage],
+ rawMessageInfos,
truncationStatus: messageTruncationStatus.EXHAUSTIVE,
rawEntryInfos: [],
},
@@ -52,6 +66,11 @@
const addViewerToThreadMembersSpec: DMOperationSpec<DMAddViewerToThreadMembersOperation> =
Object.freeze({
+ messageDataFromDMOperation: async (
+ dmOperation: DMAddViewerToThreadMembersOperation,
+ ) => {
+ return createAddViewerToThreadMembersMessageDataFromDMOp(dmOperation);
+ },
processDMOperation: async (
dmOperation: DMAddViewerToThreadMembersOperation,
viewerID: string,
@@ -77,4 +96,8 @@
},
});
-export { addViewerToThreadMembersSpec, createAddViewerToThreadMembersResults };
+export {
+ addViewerToThreadMembersSpec,
+ createAddViewerToThreadMembersResults,
+ createAddViewerToThreadMembersMessageDataFromDMOp,
+};
diff --git a/lib/shared/dm-ops/change-thread-settings-and-add-viewer-spec.js b/lib/shared/dm-ops/change-thread-settings-and-add-viewer-spec.js
--- a/lib/shared/dm-ops/change-thread-settings-and-add-viewer-spec.js
+++ b/lib/shared/dm-ops/change-thread-settings-and-add-viewer-spec.js
@@ -3,13 +3,18 @@
import {
addViewerToThreadMembersSpec,
createAddViewerToThreadMembersResults,
+ createAddViewerToThreadMembersMessageDataFromDMOp,
} from './add-viewer-to-thread-members-spec.js';
-import { processChangeSettingsOperation } from './change-thread-settings-spec.js';
+import {
+ processChangeSettingsOperation,
+ processThreadSettingsChanges,
+} from './change-thread-settings-spec.js';
import type {
DMOperationSpec,
ProcessDMOperationUtilities,
} from './dm-op-spec.js';
import type { DMChangeThreadSettingsAndAddViewerOperation } from '../../types/dm-ops.js';
+import type { MessageData } from '../../types/message-types.js';
function createAddViewerAndMembersOperation(
dmOperation: DMChangeThreadSettingsAndAddViewerOperation,
@@ -43,6 +48,25 @@
const changeThreadSettingsAndAddViewerSpec: DMOperationSpec<DMChangeThreadSettingsAndAddViewerOperation> =
Object.freeze({
+ messageDataFromDMOperation: async (
+ dmOperation: DMChangeThreadSettingsAndAddViewerOperation,
+ ) => {
+ const messageDatas: Array<MessageData> = [];
+ const addNewMembersOperation =
+ createAddViewerAndMembersOperation(dmOperation);
+ if (addNewMembersOperation) {
+ const addNewMembersMessageData =
+ createAddViewerToThreadMembersMessageDataFromDMOp(
+ addNewMembersOperation,
+ );
+ messageDatas.push(...addNewMembersMessageData);
+ }
+
+ const changeSettingsMessageData =
+ processThreadSettingsChanges(dmOperation);
+ messageDatas.push(...changeSettingsMessageData);
+ return messageDatas;
+ },
processDMOperation: async (
dmOperation: DMChangeThreadSettingsAndAddViewerOperation,
viewerID: string,
diff --git a/lib/shared/dm-ops/change-thread-settings-spec.js b/lib/shared/dm-ops/change-thread-settings-spec.js
--- a/lib/shared/dm-ops/change-thread-settings-spec.js
+++ b/lib/shared/dm-ops/change-thread-settings-spec.js
@@ -6,6 +6,7 @@
import {
type AddMembersResult,
createAddNewMembersResults,
+ createAddNewMembersMessageDatasFromDMOperation,
} from './add-members-spec.js';
import type {
DMOperationSpec,
@@ -16,18 +17,17 @@
DMChangeThreadSettingsOperation,
DMOperationResult,
} from '../../types/dm-ops.js';
+import type { MessageData, RawMessageInfo } from '../../types/message-types';
import { messageTypes } from '../../types/message-types-enum.js';
-import type { RawMessageInfo } from '../../types/message-types.js';
+import type { ChangeSettingsMessageData } from '../../types/messages/change-settings.js';
import type { RawThreadInfo } from '../../types/minimally-encoded-thread-permissions-types.js';
import type { LegacyRawThreadInfo } from '../../types/thread-types.js';
import { updateTypes } from '../../types/update-types-enum.js';
import type { ClientUpdateInfo } from '../../types/update-types.js';
-import { values } from '../../utils/objects.js';
+import { rawMessageInfoFromMessageData } from '../message-utils.js';
-function processAddMembersOperation(
+function createAddMembersOperation(
dmOperation: DMChangeThreadSettingsOperation,
- viewerID: string,
- utilities: ProcessDMOperationUtilities,
) {
const { editorID, time, messageIDsPrefix, changes, threadID } = dmOperation;
const newMemberIDs =
@@ -37,7 +37,7 @@
if (!changes.newMemberIDs || changes.newMemberIDs.length === 0) {
return null;
}
- const operation = {
+ return {
type: 'add_members',
editorID,
time,
@@ -45,9 +45,75 @@
addedUserIDs: newMemberIDs,
threadID,
};
+}
+
+function processAddMembersOperation(
+ dmOperation: DMChangeThreadSettingsOperation,
+ viewerID: string,
+ utilities: ProcessDMOperationUtilities,
+) {
+ const operation = createAddMembersOperation(dmOperation);
+ if (!operation) {
+ return null;
+ }
return createAddNewMembersResults(operation, viewerID, utilities);
}
+function getThreadIDFromChangeThreadSettingsDMOp(
+ dmOperation:
+ | DMChangeThreadSettingsOperation
+ | DMChangeThreadSettingsAndAddViewerOperation,
+): string {
+ return dmOperation.type === 'change_thread_settings'
+ ? dmOperation.threadID
+ : dmOperation.existingThreadDetails.threadID;
+}
+
+function processThreadSettingsChanges(
+ dmOperation:
+ | DMChangeThreadSettingsOperation
+ | DMChangeThreadSettingsAndAddViewerOperation,
+): $ReadOnlyArray<ChangeSettingsMessageData> {
+ const { changes, editorID, time } = dmOperation;
+ const { name, description, color, avatar } = changes;
+ const threadID = getThreadIDFromChangeThreadSettingsDMOp(dmOperation);
+
+ const changedFields: {
+ [string]: string | number,
+ } = {};
+
+ if (name !== undefined && name !== null) {
+ changedFields.name = name;
+ }
+
+ if (description !== undefined && description !== null) {
+ changedFields.description = description;
+ }
+
+ if (color) {
+ changedFields.color = color;
+ }
+
+ if (avatar) {
+ changedFields.avatar = JSON.stringify(avatar);
+ }
+
+ const messageDatas: Array<ChangeSettingsMessageData> = [];
+ for (const fieldName of Object.keys(changedFields)) {
+ const newValue = changedFields[fieldName];
+ messageDatas.push({
+ type: messageTypes.CHANGE_SETTINGS,
+ threadID,
+ creatorID: editorID,
+ time,
+ field: fieldName,
+ value: newValue,
+ });
+ }
+
+ return messageDatas;
+}
+
function processChangeSettingsOperation(
dmOperation:
| DMChangeThreadSettingsOperation
@@ -56,12 +122,9 @@
utilities: ProcessDMOperationUtilities,
addMembersResult: ?AddMembersResult,
): DMOperationResult {
- const { editorID, time, changes, messageIDsPrefix } = dmOperation;
+ const { time, changes, messageIDsPrefix } = dmOperation;
const { name, description, color, avatar } = changes;
- const threadID =
- dmOperation.type === 'change_thread_settings'
- ? dmOperation.threadID
- : dmOperation.existingThreadDetails.threadID;
+ const threadID = getThreadIDFromChangeThreadSettingsDMOp(dmOperation);
let threadInfoToUpdate: ?(RawThreadInfo | LegacyRawThreadInfo) =
utilities.threadInfos[threadID];
@@ -77,11 +140,9 @@
}
invariant(threadInfoToUpdate?.thick, 'Thread should be thick');
-
- const changedFields: { [string]: string | number } = {};
+ const messageDatas = processThreadSettingsChanges(dmOperation);
if (name !== undefined && name !== null) {
- changedFields.name = name;
threadInfoToUpdate = {
...threadInfoToUpdate,
name,
@@ -89,7 +150,6 @@
}
if (description !== undefined && description !== null) {
- changedFields.description = description;
threadInfoToUpdate = {
...threadInfoToUpdate,
description,
@@ -97,7 +157,6 @@
}
if (color) {
- changedFields.color = color;
threadInfoToUpdate = {
...threadInfoToUpdate,
color,
@@ -105,27 +164,22 @@
}
if (avatar) {
- changedFields.avatar = JSON.stringify(avatar);
threadInfoToUpdate = {
...threadInfoToUpdate,
avatar,
};
}
- for (const fieldName in changedFields) {
- const newValue = changedFields[fieldName];
- rawMessageInfos.push({
- type: messageTypes.CHANGE_SETTINGS,
- threadID,
- creatorID: editorID,
- time,
- field: fieldName,
- value: newValue,
- id: `${messageIDsPrefix}/${fieldName}`,
- });
- }
+ rawMessageInfos.push(
+ ...messageDatas.map(messageData =>
+ rawMessageInfoFromMessageData(
+ messageData,
+ `${messageIDsPrefix}/${messageData.field}`,
+ ),
+ ),
+ );
- if (values(changedFields).length > 0) {
+ if (messageDatas.length > 0) {
updateInfos.push({
type: updateTypes.UPDATE_THREAD,
id: uuid.v4(),
@@ -142,6 +196,24 @@
const changeThreadSettingsSpec: DMOperationSpec<DMChangeThreadSettingsOperation> =
Object.freeze({
+ messageDataFromDMOperation: async (
+ dmOperation: DMChangeThreadSettingsOperation,
+ ) => {
+ const messageDatas: Array<MessageData> = [];
+ const addNewMembersOperation = createAddMembersOperation(dmOperation);
+ if (addNewMembersOperation) {
+ const addNewMembersMessageData =
+ createAddNewMembersMessageDatasFromDMOperation(
+ addNewMembersOperation,
+ );
+ messageDatas.push(...addNewMembersMessageData);
+ }
+
+ const changeSettingsMessageData =
+ processThreadSettingsChanges(dmOperation);
+ messageDatas.push(...changeSettingsMessageData);
+ return messageDatas;
+ },
processDMOperation: async (
dmOperation: DMChangeThreadSettingsOperation,
viewerID: string,
@@ -178,4 +250,8 @@
},
});
-export { changeThreadSettingsSpec, processChangeSettingsOperation };
+export {
+ changeThreadSettingsSpec,
+ processChangeSettingsOperation,
+ processThreadSettingsChanges,
+};
diff --git a/lib/shared/dm-ops/create-sidebar-spec.js b/lib/shared/dm-ops/create-sidebar-spec.js
--- a/lib/shared/dm-ops/create-sidebar-spec.js
+++ b/lib/shared/dm-ops/create-sidebar-spec.js
@@ -15,10 +15,79 @@
} from '../../types/message-types.js';
import { threadTypes } from '../../types/thread-types-enum.js';
import { updateTypes } from '../../types/update-types-enum.js';
-import { isInvalidSidebarSource } from '../message-utils.js';
+import { generatePendingThreadColor } from '../color-utils.js';
+import {
+ isInvalidSidebarSource,
+ rawMessageInfoFromMessageData,
+} from '../message-utils.js';
+
+async function createMessageDatasFromDMOperation(
+ dmOperation: DMCreateSidebarOperation,
+ utilities: ProcessDMOperationUtilities,
+ threadColor?: string,
+) {
+ const {
+ threadID,
+ creatorID,
+ time,
+ parentThreadID,
+ memberIDs,
+ sourceMessageID,
+ } = dmOperation;
+
+ const allMemberIDs = [creatorID, ...memberIDs];
+ const color = threadColor ?? generatePendingThreadColor(allMemberIDs);
+ const sourceMessage = await utilities.fetchMessage(sourceMessageID);
+
+ if (!sourceMessage) {
+ throw new Error(
+ `could not find sourceMessage ${sourceMessageID}... probably ` +
+ 'joined thick thread ${parentThreadID} after its creation',
+ );
+ }
+ if (isInvalidSidebarSource(sourceMessage)) {
+ throw new Error(
+ `sourceMessage ${sourceMessageID} is an invalid sidebar source`,
+ );
+ }
+
+ const sidebarSourceMessageData = {
+ type: messageTypes.SIDEBAR_SOURCE,
+ threadID,
+ creatorID,
+ time,
+ sourceMessage: sourceMessage,
+ };
+
+ const createSidebarMessageData = {
+ type: messageTypes.CREATE_SIDEBAR,
+ threadID,
+ creatorID,
+ time: time + 1,
+ sourceMessageAuthorID: sourceMessage.creatorID,
+ initialThreadState: {
+ parentThreadID,
+ color,
+ memberIDs: allMemberIDs,
+ },
+ };
+
+ return {
+ sidebarSourceMessageData,
+ createSidebarMessageData,
+ };
+}
const createSidebarSpec: DMOperationSpec<DMCreateSidebarOperation> =
Object.freeze({
+ messageDataFromDMOperation: async (
+ dmOperation: DMCreateSidebarOperation,
+ utilities: ProcessDMOperationUtilities,
+ ) => {
+ const { sidebarSourceMessageData, createSidebarMessageData } =
+ await createMessageDatasFromDMOperation(dmOperation, utilities);
+ return [sidebarSourceMessageData, createSidebarMessageData];
+ },
processDMOperation: async (
dmOperation: DMCreateSidebarOperation,
viewerID: string,
@@ -52,41 +121,25 @@
viewerID,
);
- const sourceMessage = await utilities.fetchMessage(sourceMessageID);
- if (!sourceMessage) {
- throw new Error(
- `could not find sourceMessage ${sourceMessageID}... probably ` +
- 'joined thick thread ${parentThreadID} after its creation',
- );
- }
- if (isInvalidSidebarSource(sourceMessage)) {
- throw new Error(
- `sourceMessage ${sourceMessageID} is an invalid sidebar source`,
+ const { sidebarSourceMessageData, createSidebarMessageData } =
+ await createMessageDatasFromDMOperation(
+ dmOperation,
+ utilities,
+ rawThreadInfo.color,
);
- }
+
+ const sidebarSourceMessageInfo = rawMessageInfoFromMessageData(
+ sidebarSourceMessageData,
+ newSidebarSourceMessageID,
+ );
+ const createSidebarMessageInfo = rawMessageInfoFromMessageData(
+ createSidebarMessageData,
+ newCreateSidebarMessageID,
+ );
const rawMessageInfos: Array<RawMessageInfo> = [
- {
- type: messageTypes.SIDEBAR_SOURCE,
- id: newSidebarSourceMessageID,
- threadID,
- creatorID,
- time,
- sourceMessage,
- },
- {
- type: messageTypes.CREATE_SIDEBAR,
- id: newCreateSidebarMessageID,
- threadID,
- creatorID,
- time: time + 1,
- sourceMessageAuthorID: sourceMessage.creatorID,
- initialThreadState: {
- parentThreadID,
- color: rawThreadInfo.color,
- memberIDs: allMemberIDs,
- },
- },
+ sidebarSourceMessageInfo,
+ createSidebarMessageInfo,
];
const threadJoinUpdateInfo = {
diff --git a/lib/shared/dm-ops/create-thread-spec.js b/lib/shared/dm-ops/create-thread-spec.js
--- a/lib/shared/dm-ops/create-thread-spec.js
+++ b/lib/shared/dm-ops/create-thread-spec.js
@@ -14,10 +14,7 @@
DMCreateThreadOperation,
} from '../../types/dm-ops.js';
import { messageTypes } from '../../types/message-types-enum.js';
-import {
- type RawMessageInfo,
- messageTruncationStatus,
-} from '../../types/message-types.js';
+import { messageTruncationStatus } from '../../types/message-types.js';
import {
type ThickRawThreadInfo,
type RoleInfo,
@@ -31,6 +28,7 @@
import type { ThickMemberInfo } from '../../types/thread-types.js';
import { updateTypes } from '../../types/update-types-enum.js';
import { generatePendingThreadColor } from '../color-utils.js';
+import { rawMessageInfoFromMessageData } from '../message-utils.js';
function createRoleAndPermissionForThickThreads(
threadType: ThickThreadType,
@@ -126,8 +124,35 @@
return newThread;
}
+function createMessageDatasFromDMOperation(
+ dmOperation: DMCreateThreadOperation,
+ threadColor?: string,
+) {
+ const { threadID, creatorID, time, threadType, memberIDs } = dmOperation;
+ const allMemberIDs = [creatorID, ...memberIDs];
+ const color = threadColor ?? generatePendingThreadColor(allMemberIDs);
+ return [
+ {
+ type: messageTypes.CREATE_THREAD,
+ threadID,
+ creatorID,
+ time,
+ initialThreadState: {
+ type: threadType,
+ color,
+ memberIDs: allMemberIDs,
+ },
+ },
+ ];
+}
+
const createThreadSpec: DMOperationSpec<DMCreateThreadOperation> =
Object.freeze({
+ messageDataFromDMOperation: async (
+ dmOperation: DMCreateThreadOperation,
+ ) => {
+ return createMessageDatasFromDMOperation(dmOperation);
+ },
processDMOperation: async (
dmOperation: DMCreateThreadOperation,
viewerID: string,
@@ -155,20 +180,13 @@
viewerID,
);
- const rawMessageInfos: Array<RawMessageInfo> = [
- {
- type: messageTypes.CREATE_THREAD,
- id: newMessageID,
- threadID,
- creatorID,
- time,
- initialThreadState: {
- type: threadType,
- color: rawThreadInfo.color,
- memberIDs: allMemberIDs,
- },
- },
- ];
+ const messageDatas = createMessageDatasFromDMOperation(
+ dmOperation,
+ rawThreadInfo.color,
+ );
+ const rawMessageInfos = messageDatas.map(messageData =>
+ rawMessageInfoFromMessageData(messageData, newMessageID),
+ );
const threadJoinUpdateInfo = {
type: updateTypes.JOIN_THREAD,
diff --git a/lib/shared/dm-ops/dm-op-spec.js b/lib/shared/dm-ops/dm-op-spec.js
--- a/lib/shared/dm-ops/dm-op-spec.js
+++ b/lib/shared/dm-ops/dm-op-spec.js
@@ -1,7 +1,7 @@
// @flow
import type { DMOperation, DMOperationResult } from '../../types/dm-ops.js';
-import type { RawMessageInfo } from '../../types/message-types.js';
+import type { RawMessageInfo, MessageData } from '../../types/message-types.js';
import type { RawThreadInfos } from '../../types/thread-types.js';
export type ProcessDMOperationUtilities = {
@@ -11,6 +11,10 @@
};
export type DMOperationSpec<DMOp: DMOperation> = {
+ +messageDataFromDMOperation?: (
+ dmOp: DMOp,
+ utilities: ProcessDMOperationUtilities,
+ ) => Promise<$ReadOnlyArray<MessageData>>,
+processDMOperation: (
dmOp: DMOp,
viewerID: string,
diff --git a/lib/shared/dm-ops/join-thread-spec.js b/lib/shared/dm-ops/join-thread-spec.js
--- a/lib/shared/dm-ops/join-thread-spec.js
+++ b/lib/shared/dm-ops/join-thread-spec.js
@@ -23,9 +23,25 @@
import { updateTypes } from '../../types/update-types-enum.js';
import type { ClientUpdateInfo } from '../../types/update-types.js';
import { values } from '../../utils/objects.js';
+import { rawMessageInfoFromMessageData } from '../message-utils.js';
import { roleIsDefaultRole, userIsMember } from '../thread-utils.js';
+function createMessageDatasFromDMOperation(dmOperation: DMJoinThreadOperation) {
+ const { joinerID, time, existingThreadDetails } = dmOperation;
+ return [
+ {
+ type: messageTypes.JOIN_THREAD,
+ threadID: existingThreadDetails.threadID,
+ creatorID: joinerID,
+ time,
+ },
+ ];
+}
+
const joinThreadSpec: DMOperationSpec<DMJoinThreadOperation> = Object.freeze({
+ messageDataFromDMOperation: async (dmOperation: DMJoinThreadOperation) => {
+ return createMessageDatasFromDMOperation(dmOperation);
+ },
processDMOperation: async (
dmOperation: DMJoinThreadOperation,
viewerID: string,
@@ -36,17 +52,14 @@
const currentThreadInfo =
utilities.threadInfos[existingThreadDetails.threadID];
- const joinThreadMessage = {
- type: messageTypes.JOIN_THREAD,
- id: messageID,
- threadID: existingThreadDetails.threadID,
- creatorID: joinerID,
- time,
- };
+ const messageDatas = createMessageDatasFromDMOperation(dmOperation);
+ const joinThreadMessageInfos = messageDatas.map(messageData =>
+ rawMessageInfoFromMessageData(messageData, messageID),
+ );
if (userIsMember(currentThreadInfo, joinerID)) {
return {
- rawMessageInfos: [joinThreadMessage],
+ rawMessageInfos: joinThreadMessageInfos,
updateInfos: [],
};
}
@@ -66,14 +79,14 @@
id: uuid.v4(),
time,
threadInfo: newThreadInfo,
- rawMessageInfos: [joinThreadMessage],
+ rawMessageInfos: joinThreadMessageInfos,
truncationStatus: messageTruncationStatus.EXHAUSTIVE,
rawEntryInfos: [],
});
} else {
invariant(currentThreadInfo.thick, 'Thread should be thick');
- rawMessageInfos.push(joinThreadMessage);
+ rawMessageInfos.push(...joinThreadMessageInfos);
const defaultRoleID = values(currentThreadInfo.roles).find(role =>
roleIsDefaultRole(role),
)?.id;
diff --git a/lib/shared/dm-ops/leave-thread-spec.js b/lib/shared/dm-ops/leave-thread-spec.js
--- a/lib/shared/dm-ops/leave-thread-spec.js
+++ b/lib/shared/dm-ops/leave-thread-spec.js
@@ -12,9 +12,27 @@
import { threadTypes } from '../../types/thread-types-enum.js';
import { updateTypes } from '../../types/update-types-enum.js';
import type { ClientUpdateInfo } from '../../types/update-types.js';
+import { rawMessageInfoFromMessageData } from '../message-utils.js';
import { userIsMember } from '../thread-utils.js';
+function createMessageDatasFromDMOperation(
+ dmOperation: DMLeaveThreadOperation,
+) {
+ const { editorID, time, threadID } = dmOperation;
+ return [
+ {
+ type: messageTypes.LEAVE_THREAD,
+ threadID,
+ creatorID: editorID,
+ time,
+ },
+ ];
+}
+
const leaveThreadSpec: DMOperationSpec<DMLeaveThreadOperation> = Object.freeze({
+ messageDataFromDMOperation: async (dmOperation: DMLeaveThreadOperation) => {
+ return createMessageDatasFromDMOperation(dmOperation);
+ },
processDMOperation: async (
dmOperation: DMLeaveThreadOperation,
viewerID: string,
@@ -25,13 +43,10 @@
const threadInfo = utilities.threadInfos[threadID];
invariant(threadInfo.thick, 'Thread should be thick');
- const leaveThreadMessage = {
- type: messageTypes.LEAVE_THREAD,
- id: messageID,
- threadID,
- creatorID: editorID,
- time,
- };
+ const messageDatas = createMessageDatasFromDMOperation(dmOperation);
+ const rawMessageInfos = messageDatas.map(messageData =>
+ rawMessageInfoFromMessageData(messageData, messageID),
+ );
const updateInfos: Array<ClientUpdateInfo> = [];
if (
@@ -61,7 +76,7 @@
}
return {
- rawMessageInfos: [leaveThreadMessage],
+ rawMessageInfos,
updateInfos,
};
},
diff --git a/lib/shared/dm-ops/remove-members-spec.js b/lib/shared/dm-ops/remove-members-spec.js
--- a/lib/shared/dm-ops/remove-members-spec.js
+++ b/lib/shared/dm-ops/remove-members-spec.js
@@ -12,28 +12,44 @@
import { threadTypes } from '../../types/thread-types-enum.js';
import { updateTypes } from '../../types/update-types-enum.js';
import type { ClientUpdateInfo } from '../../types/update-types.js';
+import { rawMessageInfoFromMessageData } from '../message-utils.js';
+
+function createMessageDatasFromDMOperation(
+ dmOperation: DMRemoveMembersOperation,
+) {
+ const { editorID, time, threadID, removedUserIDs } = dmOperation;
+ return [
+ {
+ type: messageTypes.REMOVE_MEMBERS,
+ threadID,
+ time,
+ creatorID: editorID,
+ removedUserIDs: [...removedUserIDs],
+ },
+ ];
+}
const removeMembersSpec: DMOperationSpec<DMRemoveMembersOperation> =
Object.freeze({
+ messageDataFromDMOperation: async (
+ dmOperation: DMRemoveMembersOperation,
+ ) => {
+ return createMessageDatasFromDMOperation(dmOperation);
+ },
processDMOperation: async (
dmOperation: DMRemoveMembersOperation,
viewerID: string,
utilities: ProcessDMOperationUtilities,
) => {
- const { editorID, time, messageID, threadID, removedUserIDs } =
- dmOperation;
+ const { time, messageID, threadID, removedUserIDs } = dmOperation;
const threadInfo = utilities.threadInfos[threadID];
invariant(threadInfo.thick, 'Thread should be thick');
- const removeMembersMessage = {
- type: messageTypes.REMOVE_MEMBERS,
- id: messageID,
- threadID,
- time,
- creatorID: editorID,
- removedUserIDs: [...removedUserIDs],
- };
+ const messageDatas = createMessageDatasFromDMOperation(dmOperation);
+ const rawMessageInfos = messageDatas.map(messageData =>
+ rawMessageInfoFromMessageData(messageData, messageID),
+ );
const removedUserIDsSet = new Set(removedUserIDs);
const viewerIsRemoved = removedUserIDsSet.has(viewerID);
@@ -65,7 +81,7 @@
});
}
return {
- rawMessageInfos: [removeMembersMessage],
+ rawMessageInfos,
updateInfos,
};
},
diff --git a/lib/shared/dm-ops/send-edit-message-spec.js b/lib/shared/dm-ops/send-edit-message-spec.js
--- a/lib/shared/dm-ops/send-edit-message-spec.js
+++ b/lib/shared/dm-ops/send-edit-message-spec.js
@@ -6,24 +6,40 @@
} from './dm-op-spec.js';
import type { DMSendEditMessageOperation } from '../../types/dm-ops.js';
import { messageTypes } from '../../types/message-types-enum.js';
+import { rawMessageInfoFromMessageData } from '../message-utils.js';
+
+function createMessageDatasFromDMOperation(
+ dmOperation: DMSendEditMessageOperation,
+) {
+ const { threadID, creatorID, time, targetMessageID, text } = dmOperation;
+ return [
+ {
+ type: messageTypes.EDIT_MESSAGE,
+ threadID,
+ creatorID,
+ time,
+ targetMessageID,
+ text,
+ },
+ ];
+}
const sendEditMessageSpec: DMOperationSpec<DMSendEditMessageOperation> =
Object.freeze({
+ messageDataFromDMOperation: async (
+ dmOperation: DMSendEditMessageOperation,
+ ) => {
+ return createMessageDatasFromDMOperation(dmOperation);
+ },
processDMOperation: async (dmOperation: DMSendEditMessageOperation) => {
- const { threadID, creatorID, time, messageID, targetMessageID, text } =
- dmOperation;
- const editMessage = {
- type: messageTypes.EDIT_MESSAGE,
- id: messageID,
- threadID,
- creatorID,
- time,
- targetMessageID,
- text,
- };
+ const { messageID } = dmOperation;
+ const messageDatas = createMessageDatasFromDMOperation(dmOperation);
+ const rawMessageInfos = messageDatas.map(messageData =>
+ rawMessageInfoFromMessageData(messageData, messageID),
+ );
return {
- rawMessageInfos: [editMessage],
+ rawMessageInfos,
updateInfos: [],
};
},
diff --git a/lib/shared/dm-ops/send-reaction-message-spec.js b/lib/shared/dm-ops/send-reaction-message-spec.js
--- a/lib/shared/dm-ops/send-reaction-message-spec.js
+++ b/lib/shared/dm-ops/send-reaction-message-spec.js
@@ -6,32 +6,42 @@
} from './dm-op-spec.js';
import type { DMSendReactionMessageOperation } from '../../types/dm-ops.js';
import { messageTypes } from '../../types/message-types-enum.js';
+import { rawMessageInfoFromMessageData } from '../message-utils.js';
+
+function createMessageDatasFromDMOperation(
+ dmOperation: DMSendReactionMessageOperation,
+) {
+ const { threadID, creatorID, time, targetMessageID, reaction, action } =
+ dmOperation;
+ return [
+ {
+ type: messageTypes.REACTION,
+ threadID,
+ creatorID,
+ time,
+ targetMessageID,
+ reaction,
+ action,
+ },
+ ];
+}
const sendReactionMessageSpec: DMOperationSpec<DMSendReactionMessageOperation> =
Object.freeze({
+ messageDataFromDMOperation: async (
+ dmOperation: DMSendReactionMessageOperation,
+ ) => {
+ return createMessageDatasFromDMOperation(dmOperation);
+ },
processDMOperation: async (dmOperation: DMSendReactionMessageOperation) => {
- const {
- threadID,
- creatorID,
- time,
- messageID,
- targetMessageID,
- reaction,
- action,
- } = dmOperation;
- const reactionMessage = {
- type: messageTypes.REACTION,
- id: messageID,
- threadID,
- creatorID,
- time,
- targetMessageID,
- reaction,
- action,
- };
+ const { messageID } = dmOperation;
+ const messageDatas = createMessageDatasFromDMOperation(dmOperation);
+ const rawMessageInfos = messageDatas.map(messageData =>
+ rawMessageInfoFromMessageData(messageData, messageID),
+ );
return {
- rawMessageInfos: [reactionMessage],
+ rawMessageInfos,
updateInfos: [],
};
},
diff --git a/lib/shared/dm-ops/send-text-message-spec.js b/lib/shared/dm-ops/send-text-message-spec.js
--- a/lib/shared/dm-ops/send-text-message-spec.js
+++ b/lib/shared/dm-ops/send-text-message-spec.js
@@ -7,22 +7,39 @@
import type { DMSendTextMessageOperation } from '../../types/dm-ops.js';
import { messageTypes } from '../../types/message-types-enum.js';
import type { ClientUpdateInfo } from '../../types/update-types.js';
+import { rawMessageInfoFromMessageData } from '../message-utils.js';
+
+function createMessageDatasFromDMOperation(
+ dmOperation: DMSendTextMessageOperation,
+) {
+ const { threadID, creatorID, time, text } = dmOperation;
+ return [
+ {
+ type: messageTypes.TEXT,
+ threadID,
+ creatorID,
+ time,
+ text,
+ },
+ ];
+}
const sendTextMessageSpec: DMOperationSpec<DMSendTextMessageOperation> =
Object.freeze({
+ messageDataFromDMOperation: async (
+ dmOperation: DMSendTextMessageOperation,
+ ) => {
+ return createMessageDatasFromDMOperation(dmOperation);
+ },
processDMOperation: async (dmOperation: DMSendTextMessageOperation) => {
- const { threadID, creatorID, time, messageID, text } = dmOperation;
- const textMessage = {
- type: messageTypes.TEXT,
- id: messageID,
- threadID,
- creatorID,
- time,
- text,
- };
+ const { messageID } = dmOperation;
+ const messageDatas = createMessageDatasFromDMOperation(dmOperation);
+ const rawMessageInfos = messageDatas.map(messageData =>
+ rawMessageInfoFromMessageData(messageData, messageID),
+ );
const updateInfos: Array<ClientUpdateInfo> = [];
return {
- rawMessageInfos: [textMessage],
+ rawMessageInfos,
updateInfos,
};
},

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 9:05 PM (21 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2689085
Default Alt Text
D13121.id43550.diff (34 KB)

Event Timeline