diff --git a/lib/reducers/master-reducer.js b/lib/reducers/master-reducer.js --- a/lib/reducers/master-reducer.js +++ b/lib/reducers/master-reducer.js @@ -72,7 +72,7 @@ }; const [userStore, newUserInconsistencies, userStoreOperations] = - reduceUserInfos(state.userStore, action, onStateDifferenceForStaff); + reduceUserInfos(state.userStore, action); const newInconsistencies = [ ...newEntryInconsistencies, diff --git a/lib/reducers/user-reducer.js b/lib/reducers/user-reducer.js --- a/lib/reducers/user-reducer.js +++ b/lib/reducers/user-reducer.js @@ -47,8 +47,6 @@ UserStore, } from '../types/user-types.js'; import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.js'; -import { getMessageForException } from '../utils/errors.js'; -import { assertObjectsAreEqual } from '../utils/objects.js'; import { relyingOnAuthoritativeKeyserver } from '../utils/services-utils.js'; function reduceCurrentUserInfo( @@ -178,31 +176,6 @@ return state; } -function assertUserStoresAreEqual( - processedUserStore: UserInfos, - expectedUserStore: UserInfos, - location: string, - onStateDifference: (message: string) => mixed, -) { - try { - assertObjectsAreEqual( - processedUserStore, - expectedUserStore, - `UserInfos - ${location}`, - ); - } catch (e) { - console.log( - 'Error processing UserStore ops', - processedUserStore, - expectedUserStore, - ); - const message = `Error processing UserStore ops ${ - getMessageForException(e) ?? '{no exception message}' - }`; - onStateDifference(message); - } -} - const { processStoreOperations: processUserStoreOps } = userStoreOpsHandlers; function generateOpsForUserUpdates(payload: { @@ -220,7 +193,6 @@ function reduceUserInfos( state: UserStore, action: BaseAction, - onStateDifference: (message: string) => mixed, ): [ UserStore, $ReadOnlyArray, @@ -240,19 +212,12 @@ state.userInfos, userStoreOps, ); - const updated: UserInfos = { ...state.userInfos, ...newUserInfos }; - assertUserStoresAreEqual( - processedUserInfos, - updated, - action.type, - onStateDifference, - ); - if (!_isEqual(state.userInfos)(updated)) { + if (!_isEqual(state.userInfos)(processedUserInfos)) { return [ { ...state, - userInfos: updated, + userInfos: processedUserInfos, }, [], userStoreOps, @@ -271,19 +236,13 @@ state.userInfos, userStoreOps, ); - assertUserStoresAreEqual( - processedUserInfos, - {}, - action.type, - onStateDifference, - ); if (Object.keys(state.userInfos).length === 0) { return [state, [], []]; } return [ { - userInfos: {}, + userInfos: processedUserInfos, }, [], userStoreOps, @@ -306,16 +265,11 @@ state.userInfos, userStoreOps, ); - assertUserStoresAreEqual( - processedUserInfos, - newUserInfos, - action.type, - onStateDifference, - ); - if (!_isEqual(state.userInfos)(newUserInfos)) { + + if (!_isEqual(state.userInfos)(processedUserInfos)) { return [ { - userInfos: newUserInfos, + userInfos: processedUserInfos, }, [], userStoreOps, @@ -337,16 +291,10 @@ state.userInfos, userStoreOps, ); - assertUserStoresAreEqual( - processedUserInfos, - newUserInfos, - action.type, - onStateDifference, - ); return [ { - userInfos: newUserInfos, + userInfos: processedUserInfos, }, [], userStoreOps, @@ -355,7 +303,6 @@ const newUserInfos = _keyBy(userInfo => userInfo.id)( action.payload.userInfos, ); - const mergedUserInfos: UserInfos = { ...state.userInfos, ...newUserInfos }; const userStoreOps: $ReadOnlyArray = convertUserInfosToReplaceUserOps(newUserInfos); @@ -363,18 +310,12 @@ state.userInfos, userStoreOps, ); - assertUserStoresAreEqual( - processedUserInfos, - mergedUserInfos, - action.type, - onStateDifference, - ); - if (!_isEqual(state.userInfos)(mergedUserInfos)) { + if (!_isEqual(state.userInfos)(processedUserInfos)) { return [ { ...state, - userInfos: mergedUserInfos, + userInfos: processedUserInfos, }, [], userStoreOps, @@ -395,32 +336,17 @@ ...convertUserInfosToReplaceUserOps(newUserInfos), ...generateOpsForUserUpdates(action.payload), ]; - const updated = action.payload.updatesResult.newUpdates.reduce( - (reducedState, update) => { - const { reduceUserInfos: reduceUserInfosUpdate } = - updateSpecs[update.type]; - return reduceUserInfosUpdate - ? reduceUserInfosUpdate(reducedState, update) - : reducedState; - }, - { ...state.userInfos, ...newUserInfos }, - ); const processedUserInfos: UserInfos = processUserStoreOps( state.userInfos, userStoreOps, ); - assertUserStoresAreEqual( - processedUserInfos, - updated, - action.type, - onStateDifference, - ); - if (!_isEqual(state.userInfos)(updated)) { + + if (!_isEqual(state.userInfos)(processedUserInfos)) { return [ { ...state, - userInfos: updated, + userInfos: processedUserInfos, }, [], userStoreOps, @@ -445,17 +371,12 @@ } const userStoreOps: UserStoreOperation[] = []; - const newUserInfos = { ...state.userInfos }; if (userInfos) { for (const userInfo of userInfos) { - newUserInfos[userInfo.id] = userInfo; userStoreOps.push({ type: 'replace_user', payload: { ...userInfo } }); } } if (deleteUserInfoIDs) { - for (const deleteUserInfoID of deleteUserInfoIDs) { - delete newUserInfos[deleteUserInfoID]; - } userStoreOps.push({ type: 'remove_users', payload: { ids: deleteUserInfoIDs }, @@ -466,21 +387,15 @@ state.userInfos, userStoreOps, ); - assertUserStoresAreEqual( - processedUserInfos, - newUserInfos, - action.type, - onStateDifference, - ); const newInconsistencies = stateSyncSpecs.users.findStoreInconsistencies( action, state.userInfos, - newUserInfos, + processedUserInfos, ); return [ { - userInfos: newUserInfos, + userInfos: processedUserInfos, }, newInconsistencies, userStoreOps, @@ -495,17 +410,11 @@ state.userInfos, userStoreOps, ); - const updated: UserInfos = { ...state.userInfos, ...newUserInfos }; - assertUserStoresAreEqual( - processedUserInfos, - updated, - action.type, - onStateDifference, - ); - const newState = !_isEqual(state.userInfos)(updated) + + const newState = !_isEqual(state.userInfos)(processedUserInfos) ? { ...state, - userInfos: updated, + userInfos: processedUserInfos, } : state; return [newState, [], userStoreOps]; @@ -513,15 +422,8 @@ if (!action.payload.users) { return [state, [], []]; } - // Once the functionality is confirmed to work correctly, - // we will proceed with returning the users from the payload. - assertUserStoresAreEqual( - action.payload.users ?? {}, - state.userInfos, - action.type, - onStateDifference, - ); - return [state, [], []]; + + return [{ userInfos: action.payload.users }, [], []]; } return [state, [], []]; diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -138,6 +138,7 @@ 'storeLoaded', 'dbOpsStore', 'syncedMetadataStore', + 'userStore', ]; function handleReduxMigrationFailure(oldState: AppState): AppState { @@ -1199,6 +1200,10 @@ return state; }, + [67]: async (state: AppState) => { + const { userStore, ...rest } = state; + return rest; + }, }; // After migration 31, we'll no longer want to persist `messageStore.messages` @@ -1266,7 +1271,7 @@ storage: AsyncStorage, blacklist: persistBlacklist, debug: __DEV__, - version: 66, + version: 67, transforms: [ messageStoreMessagesBlocklistTransform, reportStoreTransform,