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 @@ -181,6 +181,11 @@ action, ); + const { threadActivityStore } = reduceThreadActivity( + state.threadActivityStore, + action, + ); + return { state: { ...state, @@ -209,10 +214,6 @@ ), inviteLinksStore: reduceInviteLinks(state.inviteLinksStore, action), keyserverStore, - threadActivityStore: reduceThreadActivity( - state.threadActivityStore, - action, - ), integrityStore, globalThemeInfo: reduceGlobalThemeInfo(state.globalThemeInfo, action), customServer: reduceCustomerServer(state.customServer, action), @@ -220,6 +221,7 @@ dbOpsStore: reduceDBOpsStore(state.dbOpsStore, action), syncedMetadataStore, auxUserStore, + threadActivityStore, }, storeOperations: { draftStoreOperations, diff --git a/lib/reducers/thread-activity-reducer.js b/lib/reducers/thread-activity-reducer.js --- a/lib/reducers/thread-activity-reducer.js +++ b/lib/reducers/thread-activity-reducer.js @@ -17,7 +17,10 @@ import { deleteKeyserverAccountActionTypes } from '../actions/user-actions.js'; import { extractKeyserverIDFromID } from '../keyserver-conn/keyserver-call-utils.js'; import { setNewSessionActionType } from '../keyserver-conn/keyserver-conn-types.js'; -import { threadActivityStoreOpsHandlers } from '../ops/thread-activity-store-ops.js'; +import { + threadActivityStoreOpsHandlers, + type ThreadActivityStoreOperation, +} from '../ops/thread-activity-store-ops.js'; import type { BaseAction } from '../types/redux-types.js'; import { incrementalStateSyncActionType } from '../types/socket-types.js'; import type { ThreadActivityStore } from '../types/thread-activity-types.js'; @@ -32,7 +35,10 @@ function reduceThreadActivity( state: ThreadActivityStore, action: BaseAction, -): ThreadActivityStore { +): { + +threadActivityStore: ThreadActivityStore, + +threadActivityStoreOperations: $ReadOnlyArray, +} { if (action.type === updateThreadLastNavigatedActionType) { const { threadID, time } = action.payload; const replaceOperation = { @@ -45,7 +51,10 @@ }, }, }; - return processStoreOps(state, [replaceOperation]); + return { + threadActivityStore: processStoreOps(state, [replaceOperation]), + threadActivityStoreOperations: [replaceOperation], + }; } else if (action.type === messageStorePruneActionType) { const now = Date.now(); const replaceOperations = []; @@ -62,7 +71,10 @@ }; replaceOperations.push(replaceOperation); } - return processStoreOps(state, replaceOperations); + return { + threadActivityStore: processStoreOps(state, replaceOperations), + threadActivityStoreOperations: replaceOperations, + }; } else if ( action.type === joinThreadActionTypes.success || action.type === leaveThreadActionTypes.success || @@ -78,14 +90,20 @@ ) { const { newUpdates } = action.payload.updatesResult; if (newUpdates.length === 0) { - return state; + return { + threadActivityStore: state, + threadActivityStoreOperations: [], + }; } const deleteThreadUpdates = newUpdates.filter( (update: ClientUpdateInfo) => update.type === updateTypes.DELETE_THREAD, ); if (deleteThreadUpdates.length === 0) { - return state; + return { + threadActivityStore: state, + threadActivityStoreOperations: [], + }; } const threadIDsToRemove = []; @@ -102,7 +120,10 @@ ids: threadIDsToRemove, }, }; - return processStoreOps(state, [removeOperation]); + return { + threadActivityStore: processStoreOps(state, [removeOperation]), + threadActivityStoreOperations: [removeOperation], + }; } else if (action.type === deleteKeyserverAccountActionTypes.success) { const threadIDsToRemove = []; const keyserverIDsSet = new Set(action.payload.keyserverIDs); @@ -121,7 +142,10 @@ }, }; - return processStoreOps(state, [removeOperation]); + return { + threadActivityStore: processStoreOps(state, [removeOperation]), + threadActivityStoreOperations: [removeOperation], + }; } else if ( action.type === setNewSessionActionType && action.payload.sessionChange.cookieInvalidated @@ -143,9 +167,15 @@ }, }; - return processStoreOps(state, [removeOperation]); + return { + threadActivityStore: processStoreOps(state, [removeOperation]), + threadActivityStoreOperations: [removeOperation], + }; } - return state; + return { + threadActivityStore: state, + threadActivityStoreOperations: [], + }; } export { reduceThreadActivity }; diff --git a/lib/reducers/thread-activity-reducer.test.js b/lib/reducers/thread-activity-reducer.test.js --- a/lib/reducers/thread-activity-reducer.test.js +++ b/lib/reducers/thread-activity-reducer.test.js @@ -37,7 +37,7 @@ }, }; const result = reduceThreadActivity(initialState, action); - expect(result).toEqual(expectedState); + expect(result.threadActivityStore).toEqual(expectedState); }); test('should create new thread activity entry with only lastNavigatedTo field', () => { @@ -55,7 +55,7 @@ }, }; const result = reduceThreadActivity(initialState, action); - expect(result).toEqual(expectedState); + expect(result.threadActivityStore).toEqual(expectedState); }); test('should create new thread activity entry with only lastPruned field', () => { @@ -72,7 +72,7 @@ }, }; const result = reduceThreadActivity(initialState, action); - expect(result).toEqual(expectedState); + expect(result.threadActivityStore).toEqual(expectedState); }); test('returns the initial state if the action type is not recognized', () => { @@ -101,7 +101,7 @@ }, }; const result = reduceThreadActivity(initialState, action); - expect(result).toEqual(expectedState); + expect(result.threadActivityStore).toEqual(expectedState); }); test('removes threads of keyserver the user has disconnected from', () => { @@ -142,6 +142,8 @@ }, }; - expect(reduceThreadActivity(threads, action)).toEqual(threads3); + expect(reduceThreadActivity(threads, action).threadActivityStore).toEqual( + threads3, + ); }); });