diff --git a/lib/reducers/draft-reducer.js b/lib/reducers/draft-reducer.js --- a/lib/reducers/draft-reducer.js +++ b/lib/reducers/draft-reducer.js @@ -1,8 +1,8 @@ // @flow +import { setClientDBStoreActionType } from '../actions/client-db-store-actions'; import { moveDraftActionType, - setDraftStoreDrafts, updateDraftActionType, } from '../actions/draft-actions'; import { @@ -72,9 +72,9 @@ }, }, }; - } else if (action.type === setDraftStoreDrafts) { + } else if (action.type === setClientDBStoreActionType) { const drafts = {}; - for (const dbDraftInfo of action.payload) { + for (const dbDraftInfo of action.payload.drafts) { drafts[dbDraftInfo.key] = dbDraftInfo.text; } return { 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 @@ -14,6 +14,7 @@ import _pickBy from 'lodash/fp/pickBy'; import _uniq from 'lodash/fp/uniq'; +import { setClientDBStoreActionType } from '../actions/client-db-store-actions'; import { createEntryActionTypes, saveEntryActionTypes, @@ -30,7 +31,6 @@ messageStorePruneActionType, createLocalMessageActionType, fetchSingleMostRecentMessagesFromThreadsActionTypes, - setMessageStoreMessages, } from '../actions/message-actions'; import { sendMessageReportActionTypes } from '../actions/message-report-actions'; import { @@ -1287,7 +1287,7 @@ messages: processedMessageStore.messages, }, }; - } else if (action.type === setMessageStoreMessages) { + } else if (action.type === setClientDBStoreActionType) { const { messageStoreOperations, messageStore: updatedMessageStore, @@ -1306,7 +1306,7 @@ } const threadsNeedMsgIDsResorting = new Set(); const actionPayloadMessages = translateClientDBMessageInfosToRawMessageInfos( - action.payload, + action.payload.messages, ); // When starting the app on native, we filter out any local-only multimedia diff --git a/lib/reducers/message-reducer.test.js b/lib/reducers/message-reducer.test.js --- a/lib/reducers/message-reducer.test.js +++ b/lib/reducers/message-reducer.test.js @@ -288,8 +288,15 @@ currentAsOf: 1234567890123, }, { - type: 'SET_MESSAGE_STORE_MESSAGES', - payload: clientDBMessages, + type: 'SET_CLIENT_DB_STORE', + payload: { + currentUserID: '', + drafts: [], + threadStore: { + threadInfos: {}, + }, + messages: clientDBMessages, + }, }, { [88471]: createPendingThread({ diff --git a/lib/reducers/thread-reducer.js b/lib/reducers/thread-reducer.js --- a/lib/reducers/thread-reducer.js +++ b/lib/reducers/thread-reducer.js @@ -6,6 +6,7 @@ setThreadUnreadStatusActionTypes, updateActivityActionTypes, } from '../actions/activity-actions'; +import { setClientDBStoreActionType } from '../actions/client-db-store-actions.js'; import { saveMessagesActionType } from '../actions/message-actions'; import { changeThreadSettingsActionTypes, @@ -15,7 +16,6 @@ changeThreadMemberRolesActionTypes, joinThreadActionTypes, leaveThreadActionTypes, - setThreadStoreActionType, } from '../actions/thread-actions'; import { logOutActionTypes, @@ -469,9 +469,9 @@ newThreadInconsistencies: [], threadStoreOperations, }; - } else if (action.type === setThreadStoreActionType) { + } else if (action.type === setClientDBStoreActionType) { return { - threadStore: action.payload, + threadStore: action.payload.threadStore, newThreadInconsistencies: [], threadStoreOperations: [], }; diff --git a/native/redux/redux-setup.js b/native/redux/redux-setup.js --- a/native/redux/redux-setup.js +++ b/native/redux/redux-setup.js @@ -7,6 +7,7 @@ import { persistStore, persistReducer } from 'redux-persist'; import thunk from 'redux-thunk'; +import { setClientDBStoreActionType } from 'lib/actions/client-db-store-actions'; import { setDeviceTokenActionTypes } from 'lib/actions/device-actions'; import { logOutActionTypes, @@ -352,6 +353,26 @@ storeLoaded: true, }; } + if (action.type === setClientDBStoreActionType) { + state = { + ...state, + storeLoaded: true, + }; + const currentLoggedInUserID = state.currentUserInfo?.anonymous + ? undefined + : state.currentUserInfo?.id; + const actionCurrentLoggedInUserID = action.payload.currentUserID; + if ( + !currentLoggedInUserID || + !actionCurrentLoggedInUserID || + actionCurrentLoggedInUserID !== currentLoggedInUserID + ) { + // If user is logged out now, was logged out at the time action was + // dispatched or their ID changed between action dispatch and a + // call to reducer we ignore the SQLite data since it is not valid + return state; + } + } const baseReducerResult = baseReducer(state, (action: BaseAction)); state = baseReducerResult.state;