diff --git a/keyserver/src/creators/message-creator.js b/keyserver/src/creators/message-creator.js --- a/keyserver/src/creators/message-creator.js +++ b/keyserver/src/creators/message-creator.js @@ -107,7 +107,7 @@ } } if (newMessageDatas.length === 0) { - return shimUnsupportedRawMessageInfos( + return await shimUnsupportedRawMessageInfos( existingMessageInfos, viewer.platformDetails, ); @@ -213,7 +213,7 @@ return []; } - return shimUnsupportedRawMessageInfos( + return await shimUnsupportedRawMessageInfos( returnMessageInfos, viewer.platformDetails, ); diff --git a/keyserver/src/fetchers/message-fetchers.js b/keyserver/src/fetchers/message-fetchers.js --- a/keyserver/src/fetchers/message-fetchers.js +++ b/keyserver/src/fetchers/message-fetchers.js @@ -386,7 +386,7 @@ } } - const shimmedRawMessageInfos = shimUnsupportedRawMessageInfos( + const shimmedRawMessageInfos = await shimUnsupportedRawMessageInfos( rawMessageInfos, viewer.platformDetails, ); @@ -565,7 +565,7 @@ } } - const shimmedRawMessageInfos = shimUnsupportedRawMessageInfos( + const shimmedRawMessageInfos = await shimUnsupportedRawMessageInfos( rawMessageInfos, viewer.platformDetails, ); @@ -576,16 +576,16 @@ }; } -function getMessageFetchResultFromRedisMessages( +async function getMessageFetchResultFromRedisMessages( viewer: Viewer, rawMessageInfos: $ReadOnlyArray, -): FetchMessageInfosResult { +): Promise { const truncationStatuses = {}; for (const rawMessageInfo of rawMessageInfos) { truncationStatuses[rawMessageInfo.threadID] = messageTruncationStatus.UNCHANGED; } - const shimmedRawMessageInfos = shimUnsupportedRawMessageInfos( + const shimmedRawMessageInfos = await shimUnsupportedRawMessageInfos( rawMessageInfos, viewer.platformDetails, ); @@ -701,7 +701,7 @@ const pinnedAndRelatedMessages = await rawMessageInfoForRowsAndRelatedMessages(messageRows, viewer); - const shimmedPinnedRawMessageInfos = shimUnsupportedRawMessageInfos( + const shimmedPinnedRawMessageInfos = await shimUnsupportedRawMessageInfos( pinnedAndRelatedMessages, viewer.platformDetails, ); @@ -965,7 +965,7 @@ ); return { - messages: shimUnsupportedRawMessageInfos( + messages: await shimUnsupportedRawMessageInfos( rawMessageInfos, viewer?.platformDetails, ), diff --git a/keyserver/src/push/send.js b/keyserver/src/push/send.js --- a/keyserver/src/push/send.js +++ b/keyserver/src/push/send.js @@ -208,11 +208,12 @@ if (iosVersionsToTokens) { for (const [codeVersion, devices] of iosVersionsToTokens) { const platformDetails = { platform: 'ios', codeVersion }; - const shimmedNewRawMessageInfos = shimUnsupportedRawMessageInfos( - newRawMessageInfos, - platformDetails, - ); const deliveryPromise = (async () => { + const shimmedNewRawMessageInfos = + await shimUnsupportedRawMessageInfos( + newRawMessageInfos, + platformDetails, + ); const targetedNotifications = await prepareAPNsNotification( { notifTexts, @@ -237,11 +238,12 @@ if (androidVersionsToTokens) { for (const [codeVersion, devices] of androidVersionsToTokens) { const platformDetails = { platform: 'android', codeVersion }; - const shimmedNewRawMessageInfos = shimUnsupportedRawMessageInfos( - newRawMessageInfos, - platformDetails, - ); const deliveryPromise = (async () => { + const shimmedNewRawMessageInfos = + await shimUnsupportedRawMessageInfos( + newRawMessageInfos, + platformDetails, + ); const targetedNotifications = await prepareAndroidNotification( { notifTexts, @@ -287,11 +289,12 @@ if (macosVersionsToTokens) { for (const [codeVersion, devices] of macosVersionsToTokens) { const platformDetails = { platform: 'macos', codeVersion }; - const shimmedNewRawMessageInfos = shimUnsupportedRawMessageInfos( - newRawMessageInfos, - platformDetails, - ); const deliveryPromise = (async () => { + const shimmedNewRawMessageInfos = + await shimUnsupportedRawMessageInfos( + newRawMessageInfos, + platformDetails, + ); const targetedNotifications = await prepareAPNsNotification( { notifTexts, diff --git a/keyserver/src/socket/socket.js b/keyserver/src/socket/socket.js --- a/keyserver/src/socket/socket.js +++ b/keyserver/src/socket/socket.js @@ -720,7 +720,7 @@ const { viewer } = this; invariant(viewer, 'should be set'); const rawMessageInfos = message.messages; - const messageFetchResult = getMessageFetchResultFromRedisMessages( + const messageFetchResult = await getMessageFetchResultFromRedisMessages( viewer, rawMessageInfos, ); diff --git a/lib/shared/message-utils.js b/lib/shared/message-utils.js --- a/lib/shared/message-utils.js +++ b/lib/shared/message-utils.js @@ -223,20 +223,25 @@ } } -function shimUnsupportedRawMessageInfos( +async function shimUnsupportedRawMessageInfos( rawMessageInfos: $ReadOnlyArray, platformDetails: ?PlatformDetails, -): RawMessageInfo[] { +): Promise { if (platformDetails && isWebPlatform(platformDetails.platform)) { return [...rawMessageInfos]; } - return rawMessageInfos.map(rawMessageInfo => { + const shimmedRawMessageInfos = []; + for (const rawMessageInfo of rawMessageInfos) { const { shimUnsupportedMessageInfo } = messageSpecs[rawMessageInfo.type]; if (shimUnsupportedMessageInfo) { - return shimUnsupportedMessageInfo(rawMessageInfo, platformDetails); + shimmedRawMessageInfos.push( + await shimUnsupportedMessageInfo(rawMessageInfo, platformDetails), + ); + } else { + shimmedRawMessageInfos.push(rawMessageInfo); } - return rawMessageInfo; - }); + } + return shimmedRawMessageInfos; } type MediaMessageDataCreationInput = { diff --git a/lib/shared/messages/create-sidebar-message-spec.js b/lib/shared/messages/create-sidebar-message-spec.js --- a/lib/shared/messages/create-sidebar-message-spec.js +++ b/lib/shared/messages/create-sidebar-message-spec.js @@ -158,10 +158,10 @@ return ET`${creator} ${text}`; }, - shimUnsupportedMessageInfo( + async shimUnsupportedMessageInfo( rawMessageInfo: RawCreateSidebarMessageInfo, platformDetails: ?PlatformDetails, - ): RawCreateSidebarMessageInfo | RawUnsupportedMessageInfo { + ): Promise { if (hasMinCodeVersion(platformDetails, { native: 75 })) { return rawMessageInfo; } diff --git a/lib/shared/messages/edit-message-spec.js b/lib/shared/messages/edit-message-spec.js --- a/lib/shared/messages/edit-message-spec.js +++ b/lib/shared/messages/edit-message-spec.js @@ -115,10 +115,10 @@ return { ...messageData, id }; }, - shimUnsupportedMessageInfo( + async shimUnsupportedMessageInfo( rawMessageInfo: RawEditMessageInfo, platformDetails: ?PlatformDetails, - ): RawEditMessageInfo | RawUnsupportedMessageInfo { + ): Promise { if (hasMinCodeVersion(platformDetails, { native: 215 })) { return rawMessageInfo; } diff --git a/lib/shared/messages/message-spec.js b/lib/shared/messages/message-spec.js --- a/lib/shared/messages/message-spec.js +++ b/lib/shared/messages/message-spec.js @@ -92,7 +92,7 @@ +shimUnsupportedMessageInfo?: ( rawMessageInfo: RawInfo, platformDetails: ?PlatformDetails, - ) => RawInfo | RawUnsupportedMessageInfo, + ) => Promise, +unshimMessageInfo?: ( unwrapped: RawInfo, messageInfo: RawMessageInfo, diff --git a/lib/shared/messages/multimedia-message-spec.js b/lib/shared/messages/multimedia-message-spec.js --- a/lib/shared/messages/multimedia-message-spec.js +++ b/lib/shared/messages/multimedia-message-spec.js @@ -207,10 +207,12 @@ } }, - shimUnsupportedMessageInfo( + async shimUnsupportedMessageInfo( rawMessageInfo: RawMediaMessageInfo | RawImagesMessageInfo, platformDetails: ?PlatformDetails, - ): RawMediaMessageInfo | RawImagesMessageInfo | RawUnsupportedMessageInfo { + ): Promise< + RawMediaMessageInfo | RawImagesMessageInfo | RawUnsupportedMessageInfo, + > { if (rawMessageInfo.type === messageTypes.IMAGES) { return rawMessageInfo; } diff --git a/lib/shared/messages/reaction-message-spec.js b/lib/shared/messages/reaction-message-spec.js --- a/lib/shared/messages/reaction-message-spec.js +++ b/lib/shared/messages/reaction-message-spec.js @@ -136,10 +136,10 @@ return { ...messageData, id }; }, - shimUnsupportedMessageInfo( + async shimUnsupportedMessageInfo( rawMessageInfo: RawReactionMessageInfo, platformDetails: ?PlatformDetails, - ): RawReactionMessageInfo | RawUnsupportedMessageInfo { + ): Promise { if (hasMinCodeVersion(platformDetails, { native: 167 })) { return rawMessageInfo; } diff --git a/lib/shared/messages/sidebar-source-message-spec.js b/lib/shared/messages/sidebar-source-message-spec.js --- a/lib/shared/messages/sidebar-source-message-spec.js +++ b/lib/shared/messages/sidebar-source-message-spec.js @@ -130,10 +130,10 @@ return { ...messageData, id }; }, - shimUnsupportedMessageInfo( + async shimUnsupportedMessageInfo( rawMessageInfo: RawSidebarSourceMessageInfo, platformDetails: ?PlatformDetails, - ): RawSidebarSourceMessageInfo | RawUnsupportedMessageInfo { + ): Promise { if ( hasMinCodeVersion(platformDetails, { native: 75 }) && rawMessageInfo.sourceMessage diff --git a/lib/shared/messages/toggle-pin-message-spec.js b/lib/shared/messages/toggle-pin-message-spec.js --- a/lib/shared/messages/toggle-pin-message-spec.js +++ b/lib/shared/messages/toggle-pin-message-spec.js @@ -128,10 +128,10 @@ })}`; }, - shimUnsupportedMessageInfo( + async shimUnsupportedMessageInfo( rawMessageInfo: RawTogglePinMessageInfo, platformDetails: ?PlatformDetails, - ): RawTogglePinMessageInfo | RawUnsupportedMessageInfo { + ): Promise { if (hasMinCodeVersion(platformDetails, { native: 209 })) { return rawMessageInfo; } diff --git a/lib/shared/messages/update-relationship-message-spec.js b/lib/shared/messages/update-relationship-message-spec.js --- a/lib/shared/messages/update-relationship-message-spec.js +++ b/lib/shared/messages/update-relationship-message-spec.js @@ -128,10 +128,10 @@ ); }, - shimUnsupportedMessageInfo( + async shimUnsupportedMessageInfo( rawMessageInfo: RawUpdateRelationshipMessageInfo, platformDetails: ?PlatformDetails, - ): RawUpdateRelationshipMessageInfo | RawUnsupportedMessageInfo { + ): Promise { if (hasMinCodeVersion(platformDetails, { native: 71 })) { return rawMessageInfo; }