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 @@ -14,7 +14,6 @@ import { ENSCacheContext } from '../components/ens-cache-provider.react.js'; import { NeynarClientContext } from '../components/neynar-client-provider.react.js'; import { usePeerOlmSessionsCreatorContext } from '../components/peer-olm-session-creator-provider.react.js'; -import { thickRawThreadInfosSelector } from '../selectors/thread-selectors.js'; import { IdentityClientContext } from '../shared/identity-client-context.js'; import type { AuthMetadata } from '../shared/identity-client-context.js'; import { useTunnelbroker } from '../tunnelbroker/tunnelbroker-context.js'; @@ -111,7 +110,6 @@ invariant(client, 'Identity context should be set'); const { getAuthMetadata } = client; const rawMessageInfos = useSelector(state => state.messageStore.messages); - const thickRawThreadInfos = useSelector(thickRawThreadInfosSelector); const auxUserInfos = useSelector(state => state.auxUserStore.auxUserInfos); const userInfos = useSelector(state => state.userStore.userInfos); const { getENSNames } = React.useContext(ENSCacheContext); @@ -138,17 +136,26 @@ senderUserID, senderDeviceDescriptor, }; - const { messageDatasWithMessageInfos, rescindData, badgeUpdateData } = - notifCreationData; + const { + messageDatasWithMessageInfos, + rawThreadInfos, + rescindData, + badgeUpdateData, + } = notifCreationData; const pushNotifsPreparationInput = { encryptedNotifUtilsAPI, senderDeviceDescriptor, olmSessionCreator, messageInfos: rawMessageInfos, - thickRawThreadInfos, + notifCreationData: + messageDatasWithMessageInfos && rawThreadInfos + ? { + thickRawThreadInfos: rawThreadInfos, + messageDatasWithMessageInfos, + } + : null, auxUserInfos, - messageDatasWithMessageInfos, userInfos, getENSNames, getFCNames, @@ -250,7 +257,6 @@ encryptedNotifUtilsAPI, olmSessionCreator, rawMessageInfos, - thickRawThreadInfos, auxUserInfos, userInfos, getENSNames, 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 @@ -111,26 +111,34 @@ async function getPushUserInfo( messageInfos: { +[id: string]: RawMessageInfo }, - thickRawThreadInfos: ThickRawThreadInfos, auxUserInfos: AuxUserInfos, - messageDataWithMessageInfos: ?$ReadOnlyArray<{ - +messageData: MessageData, - +rawMessageInfo: RawMessageInfo, - }>, + notifCreationData: ?{ + +messageDatasWithMessageInfos: $ReadOnlyArray<{ + +messageData: MessageData, + +rawMessageInfo: RawMessageInfo, + }>, + +thickRawThreadInfos: ThickRawThreadInfos, + }, ): Promise<{ - +pushInfos: ?PushInfo, + +pushInfos: ?{ + +infos: PushInfo, + +threadInfos: ThickRawThreadInfos, + }, +rescindInfos: ?PushInfo, }> { - if (!messageDataWithMessageInfos) { + if (!notifCreationData) { return { pushInfos: null, rescindInfos: null }; } + const { messageDatasWithMessageInfos, thickRawThreadInfos } = + notifCreationData; + const threadsToMessageIndices: Map = new Map(); const newMessageInfos: RawMessageInfo[] = []; const messageDatas: MessageData[] = []; let nextNewMessageIndex = 0; - for (const messageDataWithInfo of messageDataWithMessageInfos) { + for (const messageDataWithInfo of messageDatasWithMessageInfos) { const { messageData, rawMessageInfo } = messageDataWithInfo; const threadID = messageData.threadID; @@ -255,7 +263,10 @@ ]); return { - pushInfos: _pickBy(Boolean)(pushInfo), + pushInfos: { + infos: _pickBy(Boolean)(pushInfo), + threadInfos: thickRawThreadInfos, + }, rescindInfos: _pickBy(Boolean)(rescindInfo), }; } @@ -1177,12 +1188,14 @@ devices: $ReadOnlyArray, ) => Promise, +messageInfos: { +[id: string]: RawMessageInfo }, - +thickRawThreadInfos: ThickRawThreadInfos, +auxUserInfos: AuxUserInfos, - +messageDatasWithMessageInfos: ?$ReadOnlyArray<{ - +messageData: MessageData, - +rawMessageInfo: RawMessageInfo, - }>, + +notifCreationData: ?{ + +messageDatasWithMessageInfos: $ReadOnlyArray<{ + +messageData: MessageData, + +rawMessageInfo: RawMessageInfo, + }>, + +thickRawThreadInfos: ThickRawThreadInfos, + }, +userInfos: UserInfos, +getENSNames: ?GetENSNames, +getFCNames: ?GetFCNames, @@ -1195,10 +1208,9 @@ encryptedNotifUtilsAPI, senderDeviceDescriptor, olmSessionCreator, - messageDatasWithMessageInfos, + notifCreationData, messageInfos, auxUserInfos, - thickRawThreadInfos, userInfos, getENSNames, getFCNames, @@ -1206,16 +1218,16 @@ const { pushInfos } = await getPushUserInfo( messageInfos, - thickRawThreadInfos, auxUserInfos, - messageDatasWithMessageInfos, + notifCreationData, ); if (!pushInfos) { return null; } - const filteredPushInfos = filterDevicesSupportingDMNotifsForUsers(pushInfos); + const { infos, threadInfos } = pushInfos; + const filteredPushInfos = filterDevicesSupportingDMNotifsForUsers(infos); const userDevices: { [userID: string]: $ReadOnlyArray, @@ -1232,7 +1244,7 @@ encryptedNotifUtilsAPI, senderDeviceDescriptor, pushInfo: filteredPushInfos, - thickRawThreadInfos, + thickRawThreadInfos: threadInfos, userInfos, getENSNames, getFCNames, 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 @@ -153,6 +153,9 @@ const notificationsCreationData = { messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [threadID]: resultThreadInfo, + }, }; return { 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 @@ -89,10 +89,6 @@ } } - const notificationsCreationData = { - messageDatasWithMessageInfos: [messageDataWithMessageInfos], - }; - if (currentThreadInfo) { const { membershipPermissions, roleID } = createPermissionsForNewMembers(currentThreadInfo, utilities); @@ -134,6 +130,13 @@ }, ]; + const notificationsCreationData = { + messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [threadID]: resultThreadInfo, + }, + }; + return { rawMessageInfos, updateInfos, @@ -173,6 +176,12 @@ rawEntryInfos: [], }, ]; + const notificationsCreationData = { + messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [threadID]: resultThreadInfo, + }, + }; return { rawMessageInfos: [], updateInfos, 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 @@ -181,6 +181,9 @@ const notificationsCreationData = { messageDatasWithMessageInfos: values(fieldNameToMessageData), + rawThreadInfos: { + [threadID]: threadInfoUpdate, + }, }; return { diff --git a/lib/shared/dm-ops/change-thread-subscription.js b/lib/shared/dm-ops/change-thread-subscription.js --- a/lib/shared/dm-ops/change-thread-subscription.js +++ b/lib/shared/dm-ops/change-thread-subscription.js @@ -32,6 +32,9 @@ blobOps: [], notificationsCreationData: { messageDatasWithMessageInfos: [], + rawThreadInfos: { + [threadID]: threadInfo, + }, }, }; } @@ -87,6 +90,9 @@ blobOps: [], notificationsCreationData: { messageDatasWithMessageInfos: [], + rawThreadInfos: { + [threadID]: threadInfoUpdate, + }, }, }; }, 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 @@ -36,7 +36,10 @@ } const createEntrySpec: DMOperationSpec = Object.freeze({ - processDMOperation: async (dmOperation: DMCreateEntryOperation) => { + processDMOperation: async ( + dmOperation: DMCreateEntryOperation, + utilities: ProcessDMOperationUtilities, + ) => { const { threadID, creatorID, time, entryID, entryDate, text } = dmOperation; const messageDataWithMessageInfos = @@ -68,6 +71,9 @@ const notificationsCreationData = { messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [threadID]: utilities.threadInfos[threadID], + }, }; return { 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 @@ -170,6 +170,9 @@ rawMessageInfo: createSidebarMessageInfo, }, ], + rawThreadInfos: { + [threadID]: rawThreadInfo, + }, }; return { 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 @@ -275,6 +275,9 @@ const notificationsCreationData = { messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [threadID]: rawThreadInfo, + }, }; return { 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 @@ -61,6 +61,9 @@ const notificationsCreationData = { messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [threadID]: utilities.threadInfos[threadID], + }, }; if (timestamp > time) { 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 @@ -62,6 +62,9 @@ const notificationsCreationData = { messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [threadID]: utilities.threadInfos[threadID], + }, }; if (timestamp > time) { 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 @@ -65,11 +65,13 @@ }; } - const notificationsCreationData = { - messageDatasWithMessageInfos: [messageDataWithMessageInfos], - }; - if (memberTimestamps[joinerID].isMember > time) { + const notificationsCreationData = { + messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [currentThreadInfo.id]: currentThreadInfo, + }, + }; return { rawMessageInfos: joinThreadMessageInfos, updateInfos: [], @@ -86,22 +88,24 @@ const updateInfos: Array = []; const rawMessageInfos: Array = []; + let resultThreadInfo = currentThreadInfo; if (userIsMember(currentThreadInfo, joinerID)) { rawMessageInfos.push(...joinThreadMessageInfos); + resultThreadInfo = { + ...currentThreadInfo, + timestamps: { + ...currentThreadInfo.timestamps, + members: memberTimestamps, + }, + }; updateInfos.push({ type: updateTypes.UPDATE_THREAD, id: uuid.v4(), time, - threadInfo: { - ...currentThreadInfo, - timestamps: { - ...currentThreadInfo.timestamps, - members: memberTimestamps, - }, - }, + threadInfo: resultThreadInfo, }); } else if (viewerID === joinerID) { - const newThreadInfo = createThickRawThreadInfo( + resultThreadInfo = createThickRawThreadInfo( { ...existingThreadDetails, allMemberIDsWithSubscriptions: [ @@ -119,7 +123,7 @@ type: updateTypes.JOIN_THREAD, id: uuid.v4(), time, - threadInfo: newThreadInfo, + threadInfo: resultThreadInfo, rawMessageInfos: joinThreadMessageInfos, truncationStatus: messageTruncationStatus.EXHAUSTIVE, rawEntryInfos: [], @@ -156,7 +160,7 @@ isSender: joinerID === viewerID, subscription: joinThreadSubscription, }); - const updatedThreadInfo = { + resultThreadInfo = { ...currentThreadInfo, members: [...currentThreadInfo.members, member], timestamps: { @@ -168,9 +172,17 @@ type: updateTypes.UPDATE_THREAD, id: uuid.v4(), time, - threadInfo: updatedThreadInfo, + threadInfo: resultThreadInfo, }); } + + const notificationsCreationData = { + messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [resultThreadInfo.id]: resultThreadInfo, + }, + }; + return { rawMessageInfos, updateInfos, 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 @@ -135,6 +135,9 @@ const notificationsCreationData = { messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [threadID]: threadInfo, + }, }; if (viewerID === editorID) { 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 @@ -30,7 +30,10 @@ const sendEditMessageSpec: DMOperationSpec = Object.freeze({ - processDMOperation: async (dmOperation: DMSendEditMessageOperation) => { + processDMOperation: async ( + dmOperation: DMSendEditMessageOperation, + utilities: ProcessDMOperationUtilities, + ) => { const messageDataWithMessageInfos = createMessageDataWithInfoFromDMOperation(dmOperation); const { rawMessageInfo } = messageDataWithMessageInfos; @@ -38,6 +41,9 @@ const notificationsCreationData = { messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [dmOperation.threadID]: utilities.threadInfos[dmOperation.threadID], + }, }; return { 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 @@ -65,6 +65,7 @@ Object.freeze({ processDMOperation: async ( dmOperation: DMSendMultimediaMessageOperation, + utilities: ProcessDMOperationUtilities, ) => { const messageDataWithMessageInfos = createMessageDataWithInfoFromDMOperation(dmOperation); @@ -75,6 +76,9 @@ const notificationsCreationData = { messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [dmOperation.threadID]: utilities.threadInfos[dmOperation.threadID], + }, }; return { 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 @@ -38,7 +38,10 @@ const sendReactionMessageSpec: DMOperationSpec = Object.freeze({ - processDMOperation: async (dmOperation: DMSendReactionMessageOperation) => { + processDMOperation: async ( + dmOperation: DMSendReactionMessageOperation, + utilities: ProcessDMOperationUtilities, + ) => { const messageDataWithMessageInfos = createMessageDataWithInfoFromDMOperation(dmOperation); const { rawMessageInfo } = messageDataWithMessageInfos; @@ -46,6 +49,9 @@ const notificationsCreationData = { messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [dmOperation.threadID]: utilities.threadInfos[dmOperation.threadID], + }, }; return { 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 @@ -29,7 +29,10 @@ const sendTextMessageSpec: DMOperationSpec = Object.freeze({ - processDMOperation: async (dmOperation: DMSendTextMessageOperation) => { + processDMOperation: async ( + dmOperation: DMSendTextMessageOperation, + utilities: ProcessDMOperationUtilities, + ) => { const messageDataWithMessageInfos = createMessageDataWithInfoFromDMOperation(dmOperation); const { rawMessageInfo } = messageDataWithMessageInfos; @@ -38,6 +41,9 @@ const notificationsCreationData = { messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [dmOperation.threadID]: utilities.threadInfos[dmOperation.threadID], + }, }; return { 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 @@ -73,6 +73,9 @@ const notificationsCreationData = { messageDatasWithMessageInfos: [messageDataWithMessageInfos], + rawThreadInfos: { + [dmOperation.threadID]: utilities.threadInfos[dmOperation.threadID], + }, }; return { 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 @@ -4,6 +4,7 @@ import t, { type TInterface, type TUnion } from 'tcomb'; import type { MessageData, RawMessageInfo } from './message-types.js'; +import type { ThickRawThreadInfos } from './thread-types.js'; import type { EntityText, ThreadEntity } from '../utils/entity-text.js'; import { tShape } from '../utils/validation-utils.js'; @@ -34,6 +35,7 @@ +messageData: MessageData, +rawMessageInfo: RawMessageInfo, }>, + +rawThreadInfos: ThickRawThreadInfos, } | { +rescindData: { +threadID: string },