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 @@ -7,7 +7,6 @@ currentAsOfSelector, } from './keyserver-selectors.js'; import { currentCalendarQuery } from './nav-selectors.js'; -import { serverEntryInfo } from '../shared/entry-utils.js'; import { stateSyncSpecs } from '../shared/state-sync/state-sync-specs.js'; import threadWatcher from '../shared/thread-watcher.js'; import type { SignedIdentityKeysBlob } from '../types/crypto-types.js'; @@ -28,7 +27,7 @@ import { type CurrentUserInfo, type UserInfos } from '../types/user-types.js'; import { getConfig } from '../utils/config.js'; import { minimumOneTimeKeysRequired } from '../utils/crypto-utils.js'; -import { hash } from '../utils/objects.js'; +import { hash, values } from '../utils/objects.js'; const queuedReports: ( state: AppState, @@ -109,32 +108,24 @@ : currentUserInfo, }; + const specPerInnerHashKey = Object.fromEntries( + values(stateSyncSpecs) + .filter(spec => spec.innerHashSpec?.hashKey) + .map(spec => [spec.innerHashSpec?.hashKey, spec]), + ); const hashResults = {}; for (const key in serverRequest.hashesToCheck) { const expectedHashValue = serverRequest.hashesToCheck[key]; let hashValue; if (convertedInfos[key]) { hashValue = hash(convertedInfos[key]); - } else if (key.startsWith('threadInfo|')) { - const [, threadID] = key.split('|'); - hashValue = hash( - convertedInfos[stateSyncSpecs.threads.hashKey][threadID], - ); - } else if (key.startsWith('entryInfo|')) { - const [, entryID] = key.split('|'); - let rawEntryInfo = - convertedInfos[stateSyncSpecs.entries.hashKey][entryID]; - if (rawEntryInfo) { - rawEntryInfo = serverEntryInfo(rawEntryInfo); - } - hashValue = hash(rawEntryInfo); - } else if (key.startsWith('userInfo|')) { - const [, userID] = key.split('|'); - hashValue = hash( - convertedInfos[stateSyncSpecs.users.hashKey][userID], - ); } else { - continue; + const [keyPrefix, id] = key.split('|'); + const innerSpec = specPerInnerHashKey[keyPrefix]; + if (!innerSpec || !id) { + continue; + } + hashValue = hash(convertedInfos[innerSpec.hashKey][id]); } hashResults[key] = expectedHashValue === hashValue; }