Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3515657
D13417.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
43 KB
Referenced Files
None
Subscribers
None
D13417.diff
View Options
diff --git a/lib/push/send-hooks.react.js b/lib/push/send-hooks.react.js
--- a/lib/push/send-hooks.react.js
+++ b/lib/push/send-hooks.react.js
@@ -129,7 +129,8 @@
senderUserID,
senderDeviceDescriptor,
};
- const { messageDatas, rescindData, badgeUpdateData } = notifCreationData;
+ const { messageDatasWithMessageInfos, rescindData, badgeUpdateData } =
+ notifCreationData;
const pushNotifsPreparationInput = {
encryptedNotifUtilsAPI,
@@ -138,7 +139,7 @@
messageInfos: rawMessageInfos,
thickRawThreadInfos,
auxUserInfos,
- messageDatas,
+ messageDatasWithMessageInfos,
userInfos,
getENSNames,
getFCNames,
diff --git a/lib/push/send-utils.js b/lib/push/send-utils.js
--- a/lib/push/send-utils.js
+++ b/lib/push/send-utils.js
@@ -23,7 +23,6 @@
import { createWNSNotification } from './wns-notif-creators.js';
import { hasPermission } from '../permissions/minimally-encoded-thread-permissions.js';
import {
- rawMessageInfoFromMessageData,
createMessageInfo,
shimUnsupportedRawMessageInfos,
sortMessageInfoList,
@@ -48,7 +47,6 @@
import {
type MessageData,
type RawMessageInfo,
- messageDataLocalID,
} from '../types/message-types.js';
import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import type {
@@ -114,21 +112,26 @@
messageInfos: { +[id: string]: RawMessageInfo },
thickRawThreadInfos: ThickRawThreadInfos,
auxUserInfos: AuxUserInfos,
- messageDatas: ?$ReadOnlyArray<MessageData>,
+ messageDataWithMessageInfos: ?$ReadOnlyArray<{
+ +messageData: MessageData,
+ +rawMessageInfo: RawMessageInfo,
+ }>,
): Promise<{
+pushInfos: ?PushInfo,
+rescindInfos: ?PushInfo,
}> {
- if (!messageDatas || messageDatas.length === 0) {
+ if (!messageDataWithMessageInfos) {
return { pushInfos: null, rescindInfos: null };
}
const threadsToMessageIndices: Map<string, number[]> = new Map();
const newMessageInfos: RawMessageInfo[] = [];
+ const messageDatas: MessageData[] = [];
let nextNewMessageIndex = 0;
- for (let i = 0; i < messageDatas.length; i++) {
- const messageData = messageDatas[i];
+ for (const messageDataWithInfo of messageDataWithMessageInfos) {
+ const { messageData, rawMessageInfo } = messageDataWithInfo;
+
const threadID = messageData.threadID;
let messageIndices = threadsToMessageIndices.get(threadID);
@@ -139,12 +142,7 @@
const newMessageIndex = nextNewMessageIndex++;
messageIndices.push(newMessageIndex);
-
- const messageID = messageDataLocalID(messageData) ?? uuidv4();
- const rawMessageInfo = rawMessageInfoFromMessageData(
- messageData,
- messageID,
- );
+ messageDatas.push(messageData);
newMessageInfos.push(rawMessageInfo);
}
@@ -1046,7 +1044,10 @@
+messageInfos: { +[id: string]: RawMessageInfo },
+thickRawThreadInfos: ThickRawThreadInfos,
+auxUserInfos: AuxUserInfos,
- +messageDatas: ?$ReadOnlyArray<MessageData>,
+ +messageDatasWithMessageInfos: ?$ReadOnlyArray<{
+ +messageData: MessageData,
+ +rawMessageInfo: RawMessageInfo,
+ }>,
+userInfos: UserInfos,
+getENSNames: ?GetENSNames,
+getFCNames: ?GetFCNames,
@@ -1059,7 +1060,7 @@
encryptedNotifUtilsAPI,
senderDeviceDescriptor,
olmSessionCreator,
- messageDatas,
+ messageDatasWithMessageInfos,
messageInfos,
auxUserInfos,
thickRawThreadInfos,
@@ -1072,7 +1073,7 @@
messageInfos,
thickRawThreadInfos,
auxUserInfos,
- messageDatas,
+ messageDatasWithMessageInfos,
);
if (!pushInfos) {
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
@@ -10,6 +10,7 @@
} from './dm-op-spec.js';
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 } from '../../types/minimally-encoded-thread-permissions-types.js';
import { joinThreadSubscription } from '../../types/subscription-types.js';
@@ -19,37 +20,43 @@
import { rawMessageInfoFromMessageData } from '../message-utils.js';
import { roleIsDefaultRole, userIsMember } from '../thread-utils.js';
-function createAddNewMembersMessageDataFromDMOperation(
+function createAddNewMembersMessageDataWithInfoFromDMOperation(
dmOperation: DMAddMembersOperation,
-): AddMembersMessageData {
- const { editorID, time, addedUserIDs, threadID } = dmOperation;
- return {
+): {
+ +messageData: AddMembersMessageData,
+ +rawMessageInfo: RawMessageInfo,
+} {
+ const { editorID, time, addedUserIDs, threadID, messageID } = dmOperation;
+ const messageData = {
type: messageTypes.ADD_MEMBERS,
threadID,
creatorID: editorID,
time,
addedUserIDs: [...addedUserIDs],
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(messageData, messageID);
+ return { messageData, rawMessageInfo };
}
const addMembersSpec: DMOperationSpec<DMAddMembersOperation> = Object.freeze({
notificationsCreationData: async (dmOperation: DMAddMembersOperation) => {
- const messageData =
- createAddNewMembersMessageDataFromDMOperation(dmOperation);
- return { messageDatas: [messageData] };
+ return {
+ messageDatasWithMessageInfos: [
+ createAddNewMembersMessageDataWithInfoFromDMOperation(dmOperation),
+ ],
+ };
},
processDMOperation: async (
dmOperation: DMAddMembersOperation,
utilities: ProcessDMOperationUtilities,
) => {
- const { editorID, time, messageID, addedUserIDs, threadID } = dmOperation;
+ const { editorID, time, addedUserIDs, threadID } = dmOperation;
const { viewerID, threadInfos } = utilities;
- const messageData =
- createAddNewMembersMessageDataFromDMOperation(dmOperation);
- const rawMessageInfos = [
- rawMessageInfoFromMessageData(messageData, messageID),
- ];
+ const { rawMessageInfo } =
+ createAddNewMembersMessageDataWithInfoFromDMOperation(dmOperation);
+ const rawMessageInfos = [rawMessageInfo];
+
const currentThreadInfo = threadInfos[threadID];
if (!currentThreadInfo.thick) {
return {
@@ -142,4 +149,7 @@
supportsAutoRetry: true,
});
-export { addMembersSpec, createAddNewMembersMessageDataFromDMOperation };
+export {
+ addMembersSpec,
+ createAddNewMembersMessageDataWithInfoFromDMOperation,
+};
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
@@ -9,6 +9,7 @@
} from './dm-op-spec.js';
import type { DMAddViewerToThreadMembersOperation } from '../../types/dm-ops.js';
import { messageTypes } from '../../types/message-types-enum.js';
+import type { RawMessageInfo } from '../../types/message-types.js';
import { messageTruncationStatus } from '../../types/message-types.js';
import type { AddMembersMessageData } from '../../types/messages/add-members.js';
import { joinThreadSubscription } from '../../types/subscription-types.js';
@@ -16,17 +17,23 @@
import { rawMessageInfoFromMessageData } from '../message-utils.js';
import { userIsMember } from '../thread-utils.js';
-function createAddViewerToThreadMembersMessageDataFromDMOp(
+function createAddViewerToThreadMembersMessageDataWithInfoFromDMOp(
dmOperation: DMAddViewerToThreadMembersOperation,
-): AddMembersMessageData {
- const { editorID, time, addedUserIDs, existingThreadDetails } = dmOperation;
- return {
+): {
+ +messageData: AddMembersMessageData,
+ +rawMessageInfo: RawMessageInfo,
+} {
+ const { editorID, time, addedUserIDs, existingThreadDetails, messageID } =
+ dmOperation;
+ const messageData = {
type: messageTypes.ADD_MEMBERS,
threadID: existingThreadDetails.threadID,
creatorID: editorID,
time,
addedUserIDs: [...addedUserIDs],
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(messageData, messageID);
+ return { messageData, rawMessageInfo };
}
const addViewerToThreadMembersSpec: DMOperationSpec<DMAddViewerToThreadMembersOperation> =
@@ -34,9 +41,13 @@
notificationsCreationData: async (
dmOperation: DMAddViewerToThreadMembersOperation,
) => {
- const messageData =
- createAddViewerToThreadMembersMessageDataFromDMOp(dmOperation);
- return { messageDatas: [messageData] };
+ return {
+ messageDatasWithMessageInfos: [
+ createAddViewerToThreadMembersMessageDataWithInfoFromDMOp(
+ dmOperation,
+ ),
+ ],
+ };
},
processDMOperation: async (
dmOperation: DMAddViewerToThreadMembersOperation,
@@ -46,11 +57,9 @@
dmOperation;
const { viewerID, threadInfos } = utilities;
- const messageData =
- createAddViewerToThreadMembersMessageDataFromDMOp(dmOperation);
- const rawMessageInfos = messageID
- ? [rawMessageInfoFromMessageData(messageData, messageID)]
- : [];
+ const { rawMessageInfo } =
+ createAddViewerToThreadMembersMessageDataWithInfoFromDMOp(dmOperation);
+ const rawMessageInfos = messageID ? [rawMessageInfo] : [];
const threadID = existingThreadDetails.threadID;
const currentThreadInfo = threadInfos[threadID];
@@ -147,5 +156,5 @@
export {
addViewerToThreadMembersSpec,
- createAddViewerToThreadMembersMessageDataFromDMOp,
+ createAddViewerToThreadMembersMessageDataWithInfoFromDMOp,
};
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
@@ -11,7 +11,7 @@
DMChangeThreadSettingsOperation,
DMThreadSettingsChanges,
} from '../../types/dm-ops.js';
-import type { MessageData, RawMessageInfo } from '../../types/message-types';
+import type { RawMessageInfo } from '../../types/message-types';
import { messageTypes } from '../../types/message-types-enum.js';
import type { ChangeSettingsMessageData } from '../../types/messages/change-settings.js';
import type {
@@ -34,10 +34,15 @@
function createChangeSettingsMessageDatasAndUpdate(
dmOperation: DMChangeThreadSettingsOperation,
): {
- +fieldNameToMessageData: { +[fieldName: string]: ChangeSettingsMessageData },
+ +fieldNameToMessageData: {
+ +[fieldName: string]: {
+ +messageData: ChangeSettingsMessageData,
+ +rawMessageInfo: RawMessageInfo,
+ },
+ },
+threadInfoUpdate: DMThreadSettingsChanges,
} {
- const { changes, editorID, time } = dmOperation;
+ const { changes, editorID, time, messageIDsPrefix } = dmOperation;
const { name, description, color, avatar } = changes;
const threadID = getThreadIDFromChangeThreadSettingsDMOp(dmOperation);
@@ -60,7 +65,10 @@
}
const fieldNameToMessageData: {
- [fieldName: string]: ChangeSettingsMessageData,
+ [fieldName: string]: {
+ +messageData: ChangeSettingsMessageData,
+ +rawMessageInfo: RawMessageInfo,
+ },
} = {};
const { avatar: avatarObject, ...rest } = threadInfoUpdate;
@@ -79,7 +87,7 @@
for (const fieldName in normalizedThreadInfoUpdate) {
const value = normalizedThreadInfoUpdate[fieldName];
- fieldNameToMessageData[fieldName] = {
+ const messageData: ChangeSettingsMessageData = {
type: messageTypes.CHANGE_SETTINGS,
threadID,
creatorID: editorID,
@@ -87,6 +95,11 @@
field: fieldName,
value: value,
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(
+ messageData,
+ `${messageIDsPrefix}/${fieldName}`,
+ );
+ fieldNameToMessageData[fieldName] = { messageData, rawMessageInfo };
}
return { fieldNameToMessageData, threadInfoUpdate };
@@ -97,37 +110,27 @@
notificationsCreationData: async (
dmOperation: DMChangeThreadSettingsOperation,
) => {
- const messageDatas: Array<MessageData> = [];
-
const { fieldNameToMessageData } =
createChangeSettingsMessageDatasAndUpdate(dmOperation);
- messageDatas.push(...values(fieldNameToMessageData));
- return { messageDatas };
+
+ return { messageDatasWithMessageInfos: values(fieldNameToMessageData) };
},
processDMOperation: async (
dmOperation: DMChangeThreadSettingsOperation,
utilities: ProcessDMOperationUtilities,
) => {
- const { time, messageIDsPrefix } = dmOperation;
+ const { time } = dmOperation;
const threadID = getThreadIDFromChangeThreadSettingsDMOp(dmOperation);
const threadInfo: ?RawThreadInfo = utilities.threadInfos[threadID];
const updateInfos: Array<ClientUpdateInfo> = [];
- const rawMessageInfos: Array<RawMessageInfo> = [];
const { fieldNameToMessageData, threadInfoUpdate } =
createChangeSettingsMessageDatasAndUpdate(dmOperation);
- const fieldNameToMessageDataPairs = Object.entries(
- fieldNameToMessageData,
- );
- rawMessageInfos.push(
- ...fieldNameToMessageDataPairs.map(([fieldName, messageData]) =>
- rawMessageInfoFromMessageData(
- messageData,
- `${messageIDsPrefix}/${fieldName}`,
- ),
- ),
+ const messageDataWithMessageInfoPairs = values(fieldNameToMessageData);
+ const rawMessageInfos = messageDataWithMessageInfoPairs.map(
+ ({ rawMessageInfo }) => rawMessageInfo,
);
invariant(threadInfo?.thick, 'Thread should be thick');
@@ -146,7 +149,7 @@
}
}
- if (fieldNameToMessageDataPairs.length > 0) {
+ if (messageDataWithMessageInfoPairs.length > 0) {
updateInfos.push({
type: updateTypes.UPDATE_THREAD,
id: uuid.v4(),
diff --git a/lib/shared/dm-ops/create-entry-spec.js b/lib/shared/dm-ops/create-entry-spec.js
--- a/lib/shared/dm-ops/create-entry-spec.js
+++ b/lib/shared/dm-ops/create-entry-spec.js
@@ -14,9 +14,12 @@
import { dateFromString } from '../../utils/date-utils.js';
import { rawMessageInfoFromMessageData } from '../message-utils.js';
-function createMessageDataFromDMOperation(dmOperation: DMCreateEntryOperation) {
- const { threadID, creatorID, time, entryID, entryDate, text } = dmOperation;
- return {
+function createMessageDataWithInfoFromDMOperation(
+ dmOperation: DMCreateEntryOperation,
+) {
+ const { threadID, creatorID, time, entryID, entryDate, text, messageID } =
+ dmOperation;
+ const messageData = {
type: messageTypes.CREATE_ENTRY,
threadID,
creatorID,
@@ -25,21 +28,24 @@
date: entryDate,
text,
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(messageData, messageID);
+ return { rawMessageInfo, messageData };
}
const createEntrySpec: DMOperationSpec<DMCreateEntryOperation> = Object.freeze({
notificationsCreationData: async (dmOperation: DMCreateEntryOperation) => {
- const messageData = createMessageDataFromDMOperation(dmOperation);
- return { messageDatas: [messageData] };
+ return {
+ messageDatasWithMessageInfos: [
+ createMessageDataWithInfoFromDMOperation(dmOperation),
+ ],
+ };
},
processDMOperation: async (dmOperation: DMCreateEntryOperation) => {
- const { threadID, creatorID, time, entryID, entryDate, text, messageID } =
- dmOperation;
+ const { threadID, creatorID, time, entryID, entryDate, text } = dmOperation;
- const messageData = createMessageDataFromDMOperation(dmOperation);
- const rawMessageInfos = [
- rawMessageInfoFromMessageData(messageData, messageID),
- ];
+ const { rawMessageInfo } =
+ createMessageDataWithInfoFromDMOperation(dmOperation);
+ const rawMessageInfos = [rawMessageInfo];
const date = dateFromString(entryDate);
const rawEntryInfo: ThickRawEntryInfo = {
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
@@ -23,7 +23,7 @@
} from '../message-utils.js';
import { createThreadTimestamps } from '../thread-utils.js';
-async function createMessageDatasFromDMOperation(
+async function createMessageDatasWithInfosFromDMOperation(
dmOperation: DMCreateSidebarOperation,
utilities: ProcessDMOperationUtilities,
threadColor?: string,
@@ -35,6 +35,8 @@
parentThreadID,
memberIDs,
sourceMessageID,
+ newSidebarSourceMessageID,
+ newCreateSidebarMessageID,
} = dmOperation;
const allMemberIDs = [creatorID, ...memberIDs];
@@ -73,10 +75,20 @@
memberIDs: allMemberIDs,
},
};
+ const sidebarSourceMessageInfo = rawMessageInfoFromMessageData(
+ sidebarSourceMessageData,
+ newSidebarSourceMessageID,
+ );
+ const createSidebarMessageInfo = rawMessageInfoFromMessageData(
+ createSidebarMessageData,
+ newCreateSidebarMessageID,
+ );
return {
sidebarSourceMessageData,
createSidebarMessageData,
+ sidebarSourceMessageInfo,
+ createSidebarMessageInfo,
};
}
@@ -86,10 +98,26 @@
dmOperation: DMCreateSidebarOperation,
utilities: ProcessDMOperationUtilities,
) => {
- const { sidebarSourceMessageData, createSidebarMessageData } =
- await createMessageDatasFromDMOperation(dmOperation, utilities);
+ const {
+ sidebarSourceMessageData,
+ createSidebarMessageData,
+ createSidebarMessageInfo,
+ sidebarSourceMessageInfo,
+ } = await createMessageDatasWithInfosFromDMOperation(
+ dmOperation,
+ utilities,
+ );
return {
- messageDatas: [sidebarSourceMessageData, createSidebarMessageData],
+ messageDatasWithMessageInfos: [
+ {
+ messageData: sidebarSourceMessageData,
+ rawMessageInfo: sidebarSourceMessageInfo,
+ },
+ {
+ messageData: createSidebarMessageData,
+ rawMessageInfo: createSidebarMessageInfo,
+ },
+ ],
};
},
processDMOperation: async (
@@ -104,8 +132,6 @@
memberIDs,
sourceMessageID,
roleID,
- newSidebarSourceMessageID,
- newCreateSidebarMessageID,
} = dmOperation;
const { viewerID } = utilities;
const allMemberIDs = [creatorID, ...memberIDs];
@@ -130,22 +156,13 @@
viewerID,
);
- const { sidebarSourceMessageData, createSidebarMessageData } =
- await createMessageDatasFromDMOperation(
+ const { sidebarSourceMessageInfo, createSidebarMessageInfo } =
+ await createMessageDatasWithInfosFromDMOperation(
dmOperation,
utilities,
rawThreadInfo.color,
);
- const sidebarSourceMessageInfo = rawMessageInfoFromMessageData(
- sidebarSourceMessageData,
- newSidebarSourceMessageID,
- );
- const createSidebarMessageInfo = rawMessageInfoFromMessageData(
- createSidebarMessageData,
- newCreateSidebarMessageID,
- );
-
const rawMessageInfos: Array<RawMessageInfo> = [
sidebarSourceMessageInfo,
createSidebarMessageInfo,
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
@@ -132,13 +132,14 @@
return newThread;
}
-function createMessageDataFromDMOperation(
+function createMessageDataWithInfoFromDMOperation(
dmOperation: DMCreateThreadOperation,
) {
- const { threadID, creatorID, time, threadType, memberIDs } = dmOperation;
+ const { threadID, creatorID, time, threadType, memberIDs, newMessageID } =
+ dmOperation;
const allMemberIDs = [creatorID, ...memberIDs];
const color = generatePendingThreadColor(allMemberIDs);
- return {
+ const messageData = {
type: messageTypes.CREATE_THREAD,
threadID,
creatorID,
@@ -149,27 +150,28 @@
memberIDs: allMemberIDs,
},
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(
+ messageData,
+ newMessageID,
+ );
+ return { messageData, rawMessageInfo };
}
const createThreadSpec: DMOperationSpec<DMCreateThreadOperation> =
Object.freeze({
notificationsCreationData: async (dmOperation: DMCreateThreadOperation) => {
- const messageData = createMessageDataFromDMOperation(dmOperation);
- return { messageDatas: [messageData] };
+ return {
+ messageDatasWithMessageInfos: [
+ createMessageDataWithInfoFromDMOperation(dmOperation),
+ ],
+ };
},
processDMOperation: async (
dmOperation: DMCreateThreadOperation,
utilities: ProcessDMOperationUtilities,
) => {
- const {
- threadID,
- creatorID,
- time,
- threadType,
- memberIDs,
- roleID,
- newMessageID,
- } = dmOperation;
+ const { threadID, creatorID, time, threadType, memberIDs, roleID } =
+ dmOperation;
const { viewerID } = utilities;
const allMemberIDs = [creatorID, ...memberIDs];
const allMemberIDsWithSubscriptions = allMemberIDs.map(id => ({
@@ -190,10 +192,9 @@
viewerID,
);
- const messageData = createMessageDataFromDMOperation(dmOperation);
- const rawMessageInfos = [
- rawMessageInfoFromMessageData(messageData, newMessageID),
- ];
+ const { rawMessageInfo } =
+ createMessageDataWithInfoFromDMOperation(dmOperation);
+ const rawMessageInfos = [rawMessageInfo];
const threadJoinUpdateInfo = {
type: updateTypes.JOIN_THREAD,
diff --git a/lib/shared/dm-ops/delete-entry-spec.js b/lib/shared/dm-ops/delete-entry-spec.js
--- a/lib/shared/dm-ops/delete-entry-spec.js
+++ b/lib/shared/dm-ops/delete-entry-spec.js
@@ -14,10 +14,12 @@
import { dateFromString } from '../../utils/date-utils.js';
import { rawMessageInfoFromMessageData } from '../message-utils.js';
-function createMessageDataFromDMOperation(dmOperation: DMDeleteEntryOperation) {
- const { threadID, creatorID, time, entryID, entryDate, prevText } =
+function createMessageDataWithInfoFromDMOperation(
+ dmOperation: DMDeleteEntryOperation,
+) {
+ const { threadID, creatorID, time, entryID, entryDate, prevText, messageID } =
dmOperation;
- return {
+ const messageData = {
type: messageTypes.DELETE_ENTRY,
threadID,
creatorID,
@@ -26,12 +28,17 @@
date: entryDate,
text: prevText,
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(messageData, messageID);
+ return { rawMessageInfo, messageData };
}
const deleteEntrySpec: DMOperationSpec<DMDeleteEntryOperation> = Object.freeze({
notificationsCreationData: async (dmOperation: DMDeleteEntryOperation) => {
- const messageData = createMessageDataFromDMOperation(dmOperation);
- return { messageDatas: [messageData] };
+ return {
+ messageDatasWithMessageInfos: [
+ createMessageDataWithInfoFromDMOperation(dmOperation),
+ ],
+ };
},
processDMOperation: async (
dmOperation: DMDeleteEntryOperation,
@@ -45,14 +52,12 @@
entryID,
entryDate: dateString,
prevText,
- messageID,
} = dmOperation;
const rawEntryInfo = utilities.entryInfos[entryID];
- const messageData = createMessageDataFromDMOperation(dmOperation);
- const rawMessageInfos = [
- rawMessageInfoFromMessageData(messageData, messageID),
- ];
+ const { rawMessageInfo } =
+ createMessageDataWithInfoFromDMOperation(dmOperation);
+ const rawMessageInfos = [rawMessageInfo];
invariant(rawEntryInfo?.thick, 'Entry thread should be thick');
const timestamp = rawEntryInfo.lastUpdatedTime;
diff --git a/lib/shared/dm-ops/edit-entry-spec.js b/lib/shared/dm-ops/edit-entry-spec.js
--- a/lib/shared/dm-ops/edit-entry-spec.js
+++ b/lib/shared/dm-ops/edit-entry-spec.js
@@ -14,9 +14,12 @@
import { dateFromString } from '../../utils/date-utils.js';
import { rawMessageInfoFromMessageData } from '../message-utils.js';
-function createMessageDataFromDMOperation(dmOperation: DMEditEntryOperation) {
- const { threadID, creatorID, time, entryID, entryDate, text } = dmOperation;
- return {
+function createMessageDataWithInfoFromDMOperation(
+ dmOperation: DMEditEntryOperation,
+) {
+ const { threadID, creatorID, time, entryID, entryDate, text, messageID } =
+ dmOperation;
+ const messageData = {
type: messageTypes.EDIT_ENTRY,
threadID,
creatorID,
@@ -25,12 +28,17 @@
date: entryDate,
text,
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(messageData, messageID);
+ return { messageData, rawMessageInfo };
}
const editEntrySpec: DMOperationSpec<DMEditEntryOperation> = Object.freeze({
notificationsCreationData: async (dmOperation: DMEditEntryOperation) => {
- const messageData = createMessageDataFromDMOperation(dmOperation);
- return { messageDatas: [messageData] };
+ return {
+ messageDatasWithMessageInfos: [
+ createMessageDataWithInfoFromDMOperation(dmOperation),
+ ],
+ };
},
processDMOperation: async (
dmOperation: DMEditEntryOperation,
@@ -44,15 +52,13 @@
entryID,
entryDate: dateString,
text,
- messageID,
} = dmOperation;
const rawEntryInfo = utilities.entryInfos[entryID];
- const messageData = createMessageDataFromDMOperation(dmOperation);
- const rawMessageInfos = [
- rawMessageInfoFromMessageData(messageData, messageID),
- ];
+ const { rawMessageInfo } =
+ createMessageDataWithInfoFromDMOperation(dmOperation);
+ const rawMessageInfos = [rawMessageInfo];
invariant(rawEntryInfo?.thick, 'Entry thread should be thick');
const timestamp = rawEntryInfo.lastUpdatedTime;
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
@@ -26,28 +26,34 @@
import { rawMessageInfoFromMessageData } from '../message-utils.js';
import { roleIsDefaultRole, userIsMember } from '../thread-utils.js';
-function createMessageDataFromDMOperation(dmOperation: DMJoinThreadOperation) {
- const { joinerID, time, existingThreadDetails } = dmOperation;
- return {
+function createMessageDataWithInfoFromDMOperation(
+ dmOperation: DMJoinThreadOperation,
+) {
+ const { joinerID, time, existingThreadDetails, messageID } = dmOperation;
+ const messageData = {
type: messageTypes.JOIN_THREAD,
threadID: existingThreadDetails.threadID,
creatorID: joinerID,
time,
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(messageData, messageID);
+ return { messageData, rawMessageInfo };
}
const joinThreadSpec: DMOperationSpec<DMJoinThreadOperation> = Object.freeze({
notificationsCreationData: async (dmOperation: DMJoinThreadOperation) => {
- const messageData = createMessageDataFromDMOperation(dmOperation);
- return { messageDatas: [messageData] };
+ return {
+ messageDatasWithMessageInfos: [
+ createMessageDataWithInfoFromDMOperation(dmOperation),
+ ],
+ };
},
processDMOperation: async (
dmOperation: DMJoinThreadOperation,
utilities: ProcessDMOperationUtilities,
) => {
- const { joinerID, time, messageID, existingThreadDetails } = dmOperation;
+ const { joinerID, time, existingThreadDetails } = dmOperation;
const { viewerID, threadInfos } = utilities;
-
const currentThreadInfo = threadInfos[existingThreadDetails.threadID];
if (currentThreadInfo && !currentThreadInfo.thick) {
return {
@@ -56,10 +62,9 @@
};
}
- const messageData = createMessageDataFromDMOperation(dmOperation);
- const joinThreadMessageInfos = [
- rawMessageInfoFromMessageData(messageData, messageID),
- ];
+ const { rawMessageInfo } =
+ createMessageDataWithInfoFromDMOperation(dmOperation);
+ const joinThreadMessageInfos = [rawMessageInfo];
const memberTimestamps = { ...currentThreadInfo?.timestamps?.members };
if (!memberTimestamps[joinerID]) {
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
@@ -18,14 +18,18 @@
import { rawMessageInfoFromMessageData } from '../message-utils.js';
import { userIsMember } from '../thread-utils.js';
-function createMessageDataFromDMOperation(dmOperation: DMLeaveThreadOperation) {
- const { editorID, time, threadID } = dmOperation;
- return {
+function createMessageDataWithInfoFromDMOperation(
+ dmOperation: DMLeaveThreadOperation,
+) {
+ const { editorID, time, threadID, messageID } = dmOperation;
+ const messageData = {
type: messageTypes.LEAVE_THREAD,
threadID,
creatorID: editorID,
time,
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(messageData, messageID);
+ return { messageData, rawMessageInfo };
}
function createLeaveThreadSubthreadsUpdates(
@@ -53,23 +57,24 @@
const leaveThreadSpec: DMOperationSpec<DMLeaveThreadOperation> = Object.freeze({
notificationsCreationData: async (dmOperation: DMLeaveThreadOperation) => {
- const messageData = createMessageDataFromDMOperation(dmOperation);
- return { messageDatas: [messageData] };
+ return {
+ messageDatasWithMessageInfos: [
+ createMessageDataWithInfoFromDMOperation(dmOperation),
+ ],
+ };
},
processDMOperation: async (
dmOperation: DMLeaveThreadOperation,
utilities: ProcessDMOperationUtilities,
) => {
- const { editorID, time, messageID, threadID } = dmOperation;
+ const { editorID, time, threadID } = dmOperation;
const { viewerID, threadInfos } = utilities;
-
const threadInfo = threadInfos[threadID];
invariant(threadInfo.thick, 'Thread should be thick');
- const messageData = createMessageDataFromDMOperation(dmOperation);
- const rawMessageInfos = [
- rawMessageInfoFromMessageData(messageData, messageID),
- ];
+ const { rawMessageInfo } =
+ createMessageDataWithInfoFromDMOperation(dmOperation);
+ const rawMessageInfos = [rawMessageInfo];
if (
viewerID === editorID &&
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
@@ -14,17 +14,19 @@
import type { ClientUpdateInfo } from '../../types/update-types.js';
import { rawMessageInfoFromMessageData } from '../message-utils.js';
-function createMessageDataFromDMOperation(
+function createMessageDataWithInfoFromDMOperation(
dmOperation: DMRemoveMembersOperation,
) {
- const { editorID, time, threadID, removedUserIDs } = dmOperation;
- return {
+ const { editorID, time, threadID, removedUserIDs, messageID } = dmOperation;
+ const messageData = {
type: messageTypes.REMOVE_MEMBERS,
threadID,
time,
creatorID: editorID,
removedUserIDs: [...removedUserIDs],
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(messageData, messageID);
+ return { messageData, rawMessageInfo };
}
const removeMembersSpec: DMOperationSpec<DMRemoveMembersOperation> =
@@ -32,23 +34,24 @@
notificationsCreationData: async (
dmOperation: DMRemoveMembersOperation,
) => {
- const messageData = createMessageDataFromDMOperation(dmOperation);
- return { messageDatas: [messageData] };
+ return {
+ messageDatasWithMessageInfos: [
+ createMessageDataWithInfoFromDMOperation(dmOperation),
+ ],
+ };
},
processDMOperation: async (
dmOperation: DMRemoveMembersOperation,
utilities: ProcessDMOperationUtilities,
) => {
- const { time, messageID, threadID, removedUserIDs } = dmOperation;
+ const { time, threadID, removedUserIDs } = dmOperation;
const { viewerID, threadInfos } = utilities;
-
const threadInfo = threadInfos[threadID];
invariant(threadInfo.thick, 'Thread should be thick');
- const messageData = createMessageDataFromDMOperation(dmOperation);
- const rawMessageInfos = [
- rawMessageInfoFromMessageData(messageData, messageID),
- ];
+ const { rawMessageInfo } =
+ createMessageDataWithInfoFromDMOperation(dmOperation);
+ const rawMessageInfos = [rawMessageInfo];
const memberTimestamps = { ...threadInfo.timestamps.members };
const removedUserIDsSet = new Set<string>();
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
@@ -8,11 +8,12 @@
import { messageTypes } from '../../types/message-types-enum.js';
import { rawMessageInfoFromMessageData } from '../message-utils.js';
-function createMessageDataFromDMOperation(
+function createMessageDataWithInfoFromDMOperation(
dmOperation: DMSendEditMessageOperation,
) {
- const { threadID, creatorID, time, targetMessageID, text } = dmOperation;
- return {
+ const { threadID, creatorID, time, targetMessageID, text, messageID } =
+ dmOperation;
+ const messageData = {
type: messageTypes.EDIT_MESSAGE,
threadID,
creatorID,
@@ -20,6 +21,8 @@
targetMessageID,
text,
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(messageData, messageID);
+ return { messageData, rawMessageInfo };
}
const sendEditMessageSpec: DMOperationSpec<DMSendEditMessageOperation> =
@@ -27,15 +30,16 @@
notificationsCreationData: async (
dmOperation: DMSendEditMessageOperation,
) => {
- const messageData = createMessageDataFromDMOperation(dmOperation);
- return { messageDatas: [messageData] };
+ return {
+ messageDatasWithMessageInfos: [
+ createMessageDataWithInfoFromDMOperation(dmOperation),
+ ],
+ };
},
processDMOperation: async (dmOperation: DMSendEditMessageOperation) => {
- const { messageID } = dmOperation;
- const messageData = createMessageDataFromDMOperation(dmOperation);
- const rawMessageInfos = [
- rawMessageInfoFromMessageData(messageData, messageID),
- ];
+ const { rawMessageInfo } =
+ createMessageDataWithInfoFromDMOperation(dmOperation);
+ const rawMessageInfos = [rawMessageInfo];
return {
rawMessageInfos,
diff --git a/lib/shared/dm-ops/send-multimedia-message-spec.js b/lib/shared/dm-ops/send-multimedia-message-spec.js
--- a/lib/shared/dm-ops/send-multimedia-message-spec.js
+++ b/lib/shared/dm-ops/send-multimedia-message-spec.js
@@ -6,21 +6,22 @@
} from './dm-op-spec.js';
import type { DMSendMultimediaMessageOperation } from '../../types/dm-ops.js';
import { messageTypes } from '../../types/message-types-enum.js';
-import type { MediaMessageData } from '../../types/messages/media.js';
import type { ClientUpdateInfo } from '../../types/update-types.js';
import { rawMessageInfoFromMessageData } from '../message-utils.js';
-function createMessageDataFromDMOperation(
+function createMessageDataWithInfoFromDMOperation(
dmOperation: DMSendMultimediaMessageOperation,
-): MediaMessageData {
- const { threadID, creatorID, time, media } = dmOperation;
- return {
+) {
+ const { threadID, creatorID, time, media, messageID } = dmOperation;
+ const messageData = {
type: messageTypes.MULTIMEDIA,
threadID,
creatorID,
time,
media,
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(messageData, messageID);
+ return { messageData, rawMessageInfo };
}
const sendMultimediaMessageSpec: DMOperationSpec<DMSendMultimediaMessageOperation> =
@@ -28,17 +29,18 @@
notificationsCreationData: async (
dmOperation: DMSendMultimediaMessageOperation,
) => {
- const messageData = createMessageDataFromDMOperation(dmOperation);
- return { messageDatas: [messageData] };
+ return {
+ messageDatasWithMessageInfos: [
+ createMessageDataWithInfoFromDMOperation(dmOperation),
+ ],
+ };
},
processDMOperation: async (
dmOperation: DMSendMultimediaMessageOperation,
) => {
- const { messageID } = dmOperation;
- const messageData = createMessageDataFromDMOperation(dmOperation);
- const rawMessageInfos = [
- rawMessageInfoFromMessageData(messageData, messageID),
- ];
+ const { rawMessageInfo } =
+ createMessageDataWithInfoFromDMOperation(dmOperation);
+ const rawMessageInfos = [rawMessageInfo];
const updateInfos: Array<ClientUpdateInfo> = [];
return {
rawMessageInfos,
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
@@ -8,12 +8,19 @@
import { messageTypes } from '../../types/message-types-enum.js';
import { rawMessageInfoFromMessageData } from '../message-utils.js';
-function createMessageDataFromDMOperation(
+function createMessageDataWithInfoFromDMOperation(
dmOperation: DMSendReactionMessageOperation,
) {
- const { threadID, creatorID, time, targetMessageID, reaction, action } =
- dmOperation;
- return {
+ const {
+ threadID,
+ creatorID,
+ time,
+ targetMessageID,
+ reaction,
+ action,
+ messageID,
+ } = dmOperation;
+ const messageData = {
type: messageTypes.REACTION,
threadID,
creatorID,
@@ -22,6 +29,8 @@
reaction,
action,
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(messageData, messageID);
+ return { messageData, rawMessageInfo };
}
const sendReactionMessageSpec: DMOperationSpec<DMSendReactionMessageOperation> =
@@ -29,15 +38,16 @@
notificationsCreationData: async (
dmOperation: DMSendReactionMessageOperation,
) => {
- const messageData = createMessageDataFromDMOperation(dmOperation);
- return { messageDatas: [messageData] };
+ return {
+ messageDatasWithMessageInfos: [
+ createMessageDataWithInfoFromDMOperation(dmOperation),
+ ],
+ };
},
processDMOperation: async (dmOperation: DMSendReactionMessageOperation) => {
- const { messageID } = dmOperation;
- const messageData = createMessageDataFromDMOperation(dmOperation);
- const rawMessageInfos = [
- rawMessageInfoFromMessageData(messageData, messageID),
- ];
+ const { rawMessageInfo } =
+ createMessageDataWithInfoFromDMOperation(dmOperation);
+ const rawMessageInfos = [rawMessageInfo];
return {
rawMessageInfos,
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
@@ -9,17 +9,19 @@
import type { ClientUpdateInfo } from '../../types/update-types.js';
import { rawMessageInfoFromMessageData } from '../message-utils.js';
-function createMessageDataFromDMOperation(
+function createMessageDataWithInfoFromDMOperation(
dmOperation: DMSendTextMessageOperation,
) {
- const { threadID, creatorID, time, text } = dmOperation;
- return {
+ const { threadID, creatorID, time, text, messageID } = dmOperation;
+ const messageData = {
type: messageTypes.TEXT,
threadID,
creatorID,
time,
text,
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(messageData, messageID);
+ return { messageData, rawMessageInfo };
}
const sendTextMessageSpec: DMOperationSpec<DMSendTextMessageOperation> =
@@ -27,15 +29,16 @@
notificationsCreationData: async (
dmOperation: DMSendTextMessageOperation,
) => {
- const messageData = createMessageDataFromDMOperation(dmOperation);
- return { messageDatas: [messageData] };
+ return {
+ messageDatasWithMessageInfos: [
+ createMessageDataWithInfoFromDMOperation(dmOperation),
+ ],
+ };
},
processDMOperation: async (dmOperation: DMSendTextMessageOperation) => {
- const { messageID } = dmOperation;
- const messageData = createMessageDataFromDMOperation(dmOperation);
- const rawMessageInfos = [
- rawMessageInfoFromMessageData(messageData, messageID),
- ];
+ const { rawMessageInfo } =
+ createMessageDataWithInfoFromDMOperation(dmOperation);
+ const rawMessageInfos = [rawMessageInfo];
const updateInfos: Array<ClientUpdateInfo> = [];
return {
rawMessageInfos,
diff --git a/lib/shared/dm-ops/update-relationship-spec.js b/lib/shared/dm-ops/update-relationship-spec.js
--- a/lib/shared/dm-ops/update-relationship-spec.js
+++ b/lib/shared/dm-ops/update-relationship-spec.js
@@ -8,14 +8,14 @@
import { messageTypes } from '../../types/message-types-enum.js';
import { rawMessageInfoFromMessageData } from '../message-utils.js';
-async function createMessageDataFromDMOperation(
+async function createMessageDataWithInfoFromDMOperation(
dmOperation: DMUpdateRelationshipOperation,
utilities: ProcessDMOperationUtilities,
) {
- const { threadID, creatorID, time, operation } = dmOperation;
+ const { threadID, creatorID, time, operation, messageID } = dmOperation;
const { viewerID, findUserIdentities } = utilities;
if (operation !== 'farcaster_mutual') {
- return {
+ const messageData = {
type: messageTypes.UPDATE_RELATIONSHIP,
threadID,
creatorID,
@@ -23,6 +23,11 @@
time,
operation,
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(
+ messageData,
+ messageID,
+ );
+ return { rawMessageInfo, messageData };
}
const { identities: userIdentities } = await findUserIdentities([
creatorID,
@@ -37,7 +42,7 @@
JSON.stringify(errorMap),
);
}
- return {
+ const messageData = {
type: messageTypes.UPDATE_RELATIONSHIP,
threadID,
creatorID,
@@ -47,6 +52,8 @@
time,
operation,
};
+ const rawMessageInfo = rawMessageInfoFromMessageData(messageData, messageID);
+ return { rawMessageInfo, messageData };
}
const updateRelationshipSpec: DMOperationSpec<DMUpdateRelationshipOperation> =
@@ -55,24 +62,25 @@
dmOperation: DMUpdateRelationshipOperation,
utilities: ProcessDMOperationUtilities,
) => {
- const messageData = await createMessageDataFromDMOperation(
- dmOperation,
- utilities,
- );
- return { messageDatas: [messageData] };
+ const messageDataWithMessageInfo =
+ await createMessageDataWithInfoFromDMOperation(
+ dmOperation,
+
+ utilities,
+ );
+ return {
+ messageDatasWithMessageInfos: [messageDataWithMessageInfo],
+ };
},
processDMOperation: async (
dmOperation: DMUpdateRelationshipOperation,
utilities: ProcessDMOperationUtilities,
) => {
- const { messageID } = dmOperation;
- const messageData = await createMessageDataFromDMOperation(
+ const { rawMessageInfo } = await createMessageDataWithInfoFromDMOperation(
dmOperation,
utilities,
);
- const rawMessageInfos = [
- rawMessageInfoFromMessageData(messageData, messageID),
- ];
+ const rawMessageInfos = [rawMessageInfo];
return {
rawMessageInfos,
updateInfos: [],
@@ -83,7 +91,7 @@
utilities: ProcessDMOperationUtilities,
) => {
try {
- await createMessageDataFromDMOperation(dmOperation, utilities);
+ await createMessageDataWithInfoFromDMOperation(dmOperation, utilities);
return {
isProcessingPossible: true,
};
diff --git a/lib/types/notif-types.js b/lib/types/notif-types.js
--- a/lib/types/notif-types.js
+++ b/lib/types/notif-types.js
@@ -3,7 +3,7 @@
import type { EncryptResult } from '@commapp/olm';
import t, { type TInterface, type TUnion } from 'tcomb';
-import type { MessageData } from './message-types.js';
+import type { MessageData, RawMessageInfo } from './message-types.js';
import type { EntityText, ThreadEntity } from '../utils/entity-text.js';
import { tShape } from '../utils/validation-utils.js';
@@ -30,7 +30,10 @@
export type NotificationsCreationData =
| {
- +messageDatas: $ReadOnlyArray<MessageData>,
+ +messageDatasWithMessageInfos: ?$ReadOnlyArray<{
+ +messageData: MessageData,
+ +rawMessageInfo: RawMessageInfo,
+ }>,
}
| {
+rescindData: { threadID: string },
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 9:30 AM (19 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2694359
Default Alt Text
D13417.diff (43 KB)
Attached To
Mode
D13417: Pass pairs of message data and raw message info to notif generation code
Attached
Detach File
Event Timeline
Log In to Comment