diff --git a/lib/selectors/socket-selectors.js b/lib/selectors/socket-selectors.js --- a/lib/selectors/socket-selectors.js +++ b/lib/selectors/socket-selectors.js @@ -74,22 +74,6 @@ currentUserInfo: ?CurrentUserInfo, calendarQuery: (calendarActive: boolean) => CalendarQuery, ) => { - threadInfos = convertClientIDsToServerIDs( - ashoatKeyserverID, - t.dict(tID, rawThreadInfoValidator), - threadInfos, - ); - userInfos = convertClientIDsToServerIDs( - ashoatKeyserverID, - userInfosValidator, - userInfos, - ); - currentUserInfo = convertClientIDsToServerIDs( - ashoatKeyserverID, - t.maybe(currentUserInfoValidator), - currentUserInfo, - ); - return async ( calendarActive: boolean, oneTimeKeyGenerator: ?OneTimeKeyGenerator, @@ -116,42 +100,60 @@ platformDetails: getConfig().platformDetails, }); } else if (serverRequest.type === serverRequestTypes.CHECK_STATE) { - let filteredEntryInfos = filterRawEntryInfosByCalendarQuery( + const filteredEntryInfos = filterRawEntryInfosByCalendarQuery( serverEntryInfosObject(values(entryInfos)), calendarQuery(calendarActive), ); - filteredEntryInfos = convertClientIDsToServerIDs( + const convertedEntryInfos = convertClientIDsToServerIDs( ashoatKeyserverID, t.dict(tID, rawEntryInfoValidator), filteredEntryInfos, ); + const convertedThreadInfos = convertClientIDsToServerIDs( + ashoatKeyserverID, + t.dict(tID, rawThreadInfoValidator), + threadInfos, + ); + + const convertedUserInfos = convertClientIDsToServerIDs( + ashoatKeyserverID, + userInfosValidator, + userInfos, + ); + + const convertedCurrentUserInfo = convertClientIDsToServerIDs( + ashoatKeyserverID, + t.maybe(currentUserInfoValidator), + currentUserInfo, + ); + const hashResults = {}; for (const key in serverRequest.hashesToCheck) { const expectedHashValue = serverRequest.hashesToCheck[key]; let hashValue; if (key === 'threadInfos') { - hashValue = hash(threadInfos); + hashValue = hash(convertedThreadInfos); } else if (key === 'entryInfos') { - hashValue = hash(filteredEntryInfos); + hashValue = hash(convertedEntryInfos); } else if (key === 'userInfos') { - hashValue = hash(userInfos); + hashValue = hash(convertedUserInfos); } else if (key === 'currentUserInfo') { - hashValue = hash(currentUserInfo); + hashValue = hash(convertedCurrentUserInfo); } else if (key.startsWith('threadInfo|')) { const [, threadID] = key.split('|'); - hashValue = hash(threadInfos[threadID]); + hashValue = hash(convertedThreadInfos[threadID]); } else if (key.startsWith('entryInfo|')) { const [, entryID] = key.split('|'); - let rawEntryInfo = filteredEntryInfos[entryID]; + let rawEntryInfo = convertedEntryInfos[entryID]; if (rawEntryInfo) { rawEntryInfo = serverEntryInfo(rawEntryInfo); } hashValue = hash(rawEntryInfo); } else if (key.startsWith('userInfo|')) { const [, userID] = key.split('|'); - hashValue = hash(userInfos[userID]); + hashValue = hash(convertedUserInfos[userID]); } else { continue; } @@ -160,7 +162,7 @@ const { failUnmentioned } = serverRequest; if (failUnmentioned && failUnmentioned.threadInfos) { - for (const threadID in threadInfos) { + for (const threadID in convertedThreadInfos) { const key = `threadInfo|${threadID}`; const hashResult = hashResults[key]; if (hashResult === null || hashResult === undefined) { @@ -169,7 +171,7 @@ } } if (failUnmentioned && failUnmentioned.entryInfos) { - for (const entryID in filteredEntryInfos) { + for (const entryID in convertedEntryInfos) { const key = `entryInfo|${entryID}`; const hashResult = hashResults[key]; if (hashResult === null || hashResult === undefined) { @@ -178,7 +180,7 @@ } } if (failUnmentioned && failUnmentioned.userInfos) { - for (const userID in userInfos) { + for (const userID in convertedUserInfos) { const key = `userInfo|${userID}`; const hashResult = hashResults[key]; if (hashResult === null || hashResult === undefined) {