diff --git a/lib/reducers/local-id-reducer.js b/lib/reducers/local-id-reducer.js --- a/lib/reducers/local-id-reducer.js +++ b/lib/reducers/local-id-reducer.js @@ -17,6 +17,7 @@ numberFromLocalID, highestLocalIDSelector, } from '../selectors/local-id-selectors.js'; +import { updateSpecs } from '../shared/updates/update-specs.js'; import type { RawMessageInfo } from '../types/message-types.js'; import type { BaseAction } from '../types/redux-types.js'; import { rehydrateActionType } from '../types/redux-types.js'; @@ -24,7 +25,6 @@ fullStateSyncActionType, incrementalStateSyncActionType, } from '../types/socket-types.js'; -import { updateTypes } from '../types/update-types-enum.js'; import { type ClientUpdateInfo, processUpdatesActionType, @@ -112,14 +112,8 @@ function getRawMessageInfosFromUpdates( updates: $ReadOnlyArray, ): RawMessageInfo[] { - const rawMessageInfos = []; - for (const updateInfo of updates) { - if (updateInfo.type !== updateTypes.JOIN_THREAD) { - continue; - } - for (const messageInfo of updateInfo.rawMessageInfos) { - rawMessageInfos.push(messageInfo); - } - } - return rawMessageInfos; + return updates + .map(update => updateSpecs[update.type].getRawMessageInfos?.(update)) + .filter(Boolean) + .flat(); } diff --git a/lib/shared/updates/join-thread-spec.js b/lib/shared/updates/join-thread-spec.js --- a/lib/shared/updates/join-thread-spec.js +++ b/lib/shared/updates/join-thread-spec.js @@ -52,4 +52,7 @@ } return new Set([...filteredThreadIDs, update.threadInfo.id]); }, + getRawMessageInfos(update: ThreadJoinUpdateInfo) { + return update.rawMessageInfos; + }, }); 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 @@ -2,6 +2,7 @@ import type { ThreadStoreOperation } from '../../ops/thread-store-ops.js'; import type { RawEntryInfo } from '../../types/entry-types.js'; +import type { RawMessageInfo } from '../../types/message-types.js'; import type { RawThreadInfos } from '../../types/thread-types.js'; import type { ClientUpdateInfo } from '../../types/update-types.js'; import type { CurrentUserInfo, UserInfos } from '../../types/user-types.js'; @@ -25,4 +26,5 @@ filteredThreadIDs: $ReadOnlySet, update: UpdateInfo, ) => $ReadOnlySet, + +getRawMessageInfos?: (update: UpdateInfo) => $ReadOnlyArray, };