diff --git a/lib/reducers/message-reducer.js b/lib/reducers/message-reducer.js --- a/lib/reducers/message-reducer.js +++ b/lib/reducers/message-reducer.js @@ -101,7 +101,10 @@ } from '../types/update-types.js'; import { setNewSessionActionType } from '../utils/action-utils.js'; import { isDev } from '../utils/dev-utils.js'; -import { translateClientDBMessageInfosToRawMessageInfos } from '../utils/message-ops-utils.js'; +import { + translateClientDBMessageInfosToRawMessageInfos, + translateClientDBThreadMessageInfos, +} from '../utils/message-ops-utils.js'; import { assertObjectsAreEqual } from '../utils/objects.js'; const PROCESSED_MSG_STORE_INVARIANTS_DISABLED = !isDev; @@ -1604,6 +1607,26 @@ }, }; } else if (action.type === setClientDBStoreActionType) { + const actionPayloadMessageStoreThreads = + translateClientDBThreadMessageInfos(action.payload.messageStoreThreads); + + const newThreads = {}; + for (const threadID in actionPayloadMessageStoreThreads) { + newThreads[threadID] = { + ...actionPayloadMessageStoreThreads[threadID], + messageIDs: messageStore.threads[threadID].messageIDs, + }; + } + + assertMessageStoreThreadsAreEqual( + { + ...messageStore, + threads: newThreads, + }, + messageStore, + action.type, + ); + const { messageStoreOperations, messageStore: updatedMessageStore } = updateMessageStoreWithLatestThreadInfos(messageStore, newThreadInfos); diff --git a/lib/utils/message-ops-utils.js b/lib/utils/message-ops-utils.js --- a/lib/utils/message-ops-utils.js +++ b/lib/utils/message-ops-utils.js @@ -231,6 +231,28 @@ ); } +type TranslatedThreadMessageInfos = { + [threadID: string]: { + startReached: boolean, + lastNavigatedTo: number, + lastPruned: number, + }, +}; +function translateClientDBThreadMessageInfos( + clientDBThreadMessageInfo: $ReadOnlyArray, +): TranslatedThreadMessageInfos { + return Object.fromEntries( + clientDBThreadMessageInfo.map((threadInfo: ClientDBThreadMessageInfo) => [ + threadInfo.id, + { + startReached: threadInfo.start_reached === '1', + lastNavigatedTo: parseInt(threadInfo.last_navigated_to), + lastPruned: parseInt(threadInfo.last_pruned), + }, + ]), + ); +} + function translateThreadMessageInfoToClientDBThreadMessageInfo( id: string, threadMessageInfo: ThreadMessageInfo, @@ -312,4 +334,5 @@ convertMessageStoreOperationsToClientDBOperations, translateClientDBMediaInfosToMedia, getPinnedContentFromClientDBMessageInfo, + translateClientDBThreadMessageInfos, }; diff --git a/native/data/sqlite-data-handler.js b/native/data/sqlite-data-handler.js --- a/native/data/sqlite-data-handler.js +++ b/native/data/sqlite-data-handler.js @@ -151,7 +151,7 @@ mediaCacheContext?.evictCache(), ]); try { - const { threads, messages, drafts } = + const { threads, messages, drafts, messageStoreThreads } = await commCoreModule.getClientDBStore(); const threadInfosFromDB = convertClientDBThreadInfosToRawThreadInfos(threads); @@ -162,6 +162,7 @@ messages, threadStore: { threadInfos: threadInfosFromDB }, currentUserID: currentLoggedInUserID, + messageStoreThreads, }, }); } catch (setStoreException) {