diff --git a/keyserver/src/creators/update-creator.js b/keyserver/src/creators/update-creator.js --- a/keyserver/src/creators/update-creator.js +++ b/keyserver/src/creators/update-creator.js @@ -399,6 +399,9 @@ .map(({ detailedThreadID }) => detailedThreadID) .filter(Boolean), ); + const userIDsToFetch = new Set( + entitiesToFetch.map(({ userID }) => userID).filter(Boolean), + ); const promises = {}; @@ -458,12 +461,17 @@ })(); } + if (userIDsToFetch.size > 0) { + promises.userInfosResult = fetchKnownUserInfos(viewer, [...userIDsToFetch]); + } + const { threadResult, messageInfosResult, calendarResult, entryInfosResult, currentUserInfoResult, + userInfosResult, } = await promiseAll(promises); let threadInfos = {}; @@ -479,6 +487,7 @@ calendarResult, entryInfosResult, currentUserInfoResult, + userInfosResult, }); } @@ -487,7 +496,7 @@ rawUpdateInfos: $ReadOnlyArray, rawData: UpdateInfosRawData, ): Promise { - const { messageInfosResult, calendarResult } = rawData; + const { messageInfosResult, calendarResult, userInfosResult } = rawData; const rawEntryInfosByThreadID = {}; for (const entryInfo of calendarResult?.rawEntryInfos ?? []) { @@ -505,13 +514,6 @@ rawMessageInfosByThreadID[messageInfo.threadID].push(messageInfo); } - const userIDsToFetch = new Set( - rawUpdateInfos - .map(update => - update.type === updateTypes.UPDATE_USER ? update.updatedUserID : null, - ) - .filter(Boolean), - ); const params = { data: rawData, rawEntryInfosByThreadID, @@ -523,11 +525,6 @@ ) .filter(Boolean); - let userInfos = {}; - if (userIDsToFetch.size > 0) { - userInfos = await fetchKnownUserInfos(viewer, [...userIDsToFetch]); - } - updateInfos.sort(sortFunction); // Now we'll attempt to merge UpdateInfos so that we only have one per key @@ -573,7 +570,7 @@ } mergedUpdates.sort(sortFunction); - return { updateInfos: mergedUpdates, userInfos }; + return { updateInfos: mergedUpdates, userInfos: userInfosResult ?? {} }; } type PublishInfo = { diff --git a/lib/shared/updates/update-spec.js b/lib/shared/updates/update-spec.js --- a/lib/shared/updates/update-spec.js +++ b/lib/shared/updates/update-spec.js @@ -29,6 +29,7 @@ +calendarResult: ?FetchEntryInfosBase, +entryInfosResult: ?RawEntryInfos, +currentUserInfoResult: LoggedInUserInfo, + +userInfosResult: ?UserInfos, }; export type UpdateInfoFromRawInfoParams = { @@ -78,6 +79,7 @@ +detailedThreadID?: string, +entryID?: string, +currentUser?: boolean, + +userID?: string, }, +updateInfoFromRawInfo: ( info: RawInfo, diff --git a/lib/shared/updates/update-user-spec.js b/lib/shared/updates/update-user-spec.js --- a/lib/shared/updates/update-user-spec.js +++ b/lib/shared/updates/update-user-spec.js @@ -22,6 +22,11 @@ updatedUserID: content.updatedUserID, }; }, + entitiesToFetch(info: UserRawUpdateInfo) { + return { + userID: info.updatedUserID, + }; + }, updateContentForServerDB(data: UserUpdateData) { const { updatedUserID } = data; return JSON.stringify({ updatedUserID });