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 @@ -145,9 +145,15 @@ let hashValue; const [specKey, id] = key.split('|'); if (id) { - hashValue = specPerInnerHashKey[specKey]?.getInfoHash(id); + hashValue = specPerInnerHashKey[specKey]?.getInfoHash( + id, + keyserverID, + ); } else { - hashValue = specsPerHashKey[specKey]?.getAllInfosHash(query); + hashValue = specsPerHashKey[specKey]?.getAllInfosHash( + query, + keyserverID, + ); } // If hashValue values is null then we are still calculating @@ -168,7 +174,7 @@ continue; } - const ids = spec.getIDs(query); + const ids = spec.getIDs(query, keyserverID); if (!ids) { continue; } diff --git a/lib/shared/state-sync/entries-state-sync-spec.js b/lib/shared/state-sync/entries-state-sync-spec.js --- a/lib/shared/state-sync/entries-state-sync-spec.js +++ b/lib/shared/state-sync/entries-state-sync-spec.js @@ -17,7 +17,6 @@ } from '../../types/report-types.js'; import type { ProcessServerRequestAction } from '../../types/request-types.js'; import { actionLogger } from '../../utils/action-logger.js'; -import { authoritativeKeyserverID } from '../../utils/authoritative-keyserver.js'; import { getConfig } from '../../utils/config.js'; import { values, combineUnorderedHashes, hash } from '../../utils/objects.js'; import { generateReportID } from '../../utils/report-utils.js'; @@ -37,12 +36,12 @@ (state: AppState) => state.entryStore.entryInfos, (entryInfos: RawEntryInfos) => ({ ...entriesStateSyncSpec, - getInfoHash: (id: string) => - hash(entryInfos[`${authoritativeKeyserverID()}|${id}`]), - getAllInfosHash: (calendarQuery: CalendarQuery) => - getEntryInfosHash(entryInfos, calendarQuery), - getIDs: (calendarQuery: CalendarQuery) => - getEntryIDs(entryInfos, calendarQuery), + getInfoHash: (id: string, keyserverID: string) => + hash(entryInfos[`${keyserverID}|${id}`]), + getAllInfosHash: (calendarQuery: CalendarQuery, keyserverID: string) => + getEntryInfosHash(entryInfos, calendarQuery, keyserverID), + getIDs: (calendarQuery: CalendarQuery, keyserverID: string) => + getEntryIDs(entryInfos, calendarQuery, keyserverID), }), ); @@ -108,18 +107,29 @@ function getEntryInfosHash( entryInfos: RawEntryInfos, calendarQuery: CalendarQuery, + keyserverID: string, ) { + const filteredEntries = values(entryInfos).filter( + entry => entry.id && extractKeyserverIDFromID(entry.id) === keyserverID, + ); const filteredEntryInfos = filterRawEntryInfosByCalendarQuery( - serverEntryInfosObject(values(entryInfos)), + serverEntryInfosObject(filteredEntries), calendarQuery, ); return combineUnorderedHashes(Object.values(filteredEntryInfos).map(hash)); } -function getEntryIDs(entryInfos: RawEntryInfos, calendarQuery: CalendarQuery) { +function getEntryIDs( + entryInfos: RawEntryInfos, + calendarQuery: CalendarQuery, + keyserverID: string, +) { + const filteredEntries = values(entryInfos).filter( + entry => entry.id && extractKeyserverIDFromID(entry.id) === keyserverID, + ); const filteredEntryInfos = filterRawEntryInfosByCalendarQuery( - serverEntryInfosObject(values(entryInfos)), + serverEntryInfosObject(filteredEntries), calendarQuery, ); diff --git a/lib/shared/state-sync/state-sync-spec.js b/lib/shared/state-sync/state-sync-spec.js --- a/lib/shared/state-sync/state-sync-spec.js +++ b/lib/shared/state-sync/state-sync-spec.js @@ -28,8 +28,8 @@ export type BoundStateSyncSpec = { // If these function depend on background hashing that is still not complete // they should return null, to indicate that the hashes aren't available yet - +getInfoHash: (id: string) => ?number, - +getAllInfosHash: (query: CalendarQuery) => ?number, - +getIDs: (query: CalendarQuery) => ?Array, + +getInfoHash: (id: string, keyserverID: string) => ?number, + +getAllInfosHash: (query: CalendarQuery, keyserverID: string) => ?number, + +getIDs: (query: CalendarQuery, keyserverID: string) => ?Array, ...StateSyncSpec, }; diff --git a/lib/shared/state-sync/threads-state-sync-spec.js b/lib/shared/state-sync/threads-state-sync-spec.js --- a/lib/shared/state-sync/threads-state-sync-spec.js +++ b/lib/shared/state-sync/threads-state-sync-spec.js @@ -6,6 +6,7 @@ import type { StateSyncSpec, BoundStateSyncSpec } from './state-sync-spec.js'; import { extractKeyserverIDFromID } from '../../keyserver-conn/keyserver-call-utils.js'; +import type { CalendarQuery } from '../../types/entry-types.js'; import type { RawThreadInfo } from '../../types/minimally-encoded-thread-permissions-types.js'; import type { AppState } from '../../types/redux-types.js'; import { @@ -18,9 +19,8 @@ type LegacyRawThreadInfo, } from '../../types/thread-types.js'; import { actionLogger } from '../../utils/action-logger.js'; -import { authoritativeKeyserverID } from '../../utils/authoritative-keyserver.js'; import { getConfig } from '../../utils/config.js'; -import { combineUnorderedHashes, values } from '../../utils/objects.js'; +import { combineUnorderedHashes, entries } from '../../utils/objects.js'; import { generateReportID } from '../../utils/report-utils.js'; import { sanitizeActionSecrets } from '../../utils/sanitization.js'; @@ -35,13 +35,21 @@ (state: AppState) => state.integrityStore.threadHashingStatus === 'completed', (threadHashes: { +[string]: number }, threadHashingComplete: boolean) => ({ ...threadsStateSyncSpec, - getInfoHash: (id: string) => - threadHashes[`${authoritativeKeyserverID()}|${id}`], + getInfoHash: (id: string, keyserverID: string) => + threadHashes[`${keyserverID}|${id}`], getAllInfosHash: threadHashingComplete - ? () => combineUnorderedHashes(values(threadHashes)) + ? (query: CalendarQuery, keyserverID: string) => + combineUnorderedHashes( + entries(threadHashes) + .filter(([id]) => extractKeyserverIDFromID(id) === keyserverID) + .map(([, threadHash]) => threadHash), + ) : () => null, getIDs: threadHashingComplete - ? () => Object.keys(threadHashes).map(id => id.split('|')[1]) + ? (query: CalendarQuery, keyserverID: string) => + Object.keys(threadHashes) + .filter(id => extractKeyserverIDFromID(id) === keyserverID) + .map(id => id.split('|')[1]) : () => null, }), );