diff --git a/lib/reducers/connection-reducer.js b/lib/reducers/connection-reducer.js deleted file mode 100644 --- a/lib/reducers/connection-reducer.js +++ /dev/null @@ -1,42 +0,0 @@ -// @flow - -import { - logOutActionTypes, - deleteAccountActionTypes, -} from '../actions/user-actions.js'; -import { type BaseAction } from '../types/redux-types.js'; -import { - type ConnectionInfo, - setLateResponseActionType, - updateDisconnectedBarActionType, -} from '../types/socket-types.js'; -import { setNewSessionActionType } from '../utils/action-utils.js'; - -export default function reduceConnectionInfo( - state: ConnectionInfo, - action: BaseAction, -): ConnectionInfo { - if ( - action.type === logOutActionTypes.success || - action.type === deleteAccountActionTypes.success || - (action.type === setNewSessionActionType && - action.payload.sessionChange.cookieInvalidated) - ) { - return { - ...state, - queuedActivityUpdates: [], - }; - } else if (action.type === setLateResponseActionType) { - const { messageID, isLate } = action.payload; - const lateResponsesSet = new Set(state.lateResponses); - if (isLate) { - lateResponsesSet.add(messageID); - } else { - lateResponsesSet.delete(messageID); - } - return { ...state, lateResponses: [...lateResponsesSet] }; - } else if (action.type === updateDisconnectedBarActionType) { - return { ...state, showDisconnectedBar: action.payload.visible }; - } - return state; -} diff --git a/lib/reducers/keyserver-reducer.js b/lib/reducers/keyserver-reducer.js --- a/lib/reducers/keyserver-reducer.js +++ b/lib/reducers/keyserver-reducer.js @@ -1,12 +1,13 @@ // @flow -import reduceConnectionInfo from './connection-reducer.js'; import { reduceDeviceToken } from './device-token-reducer.js'; import { unsupervisedBackgroundActionType } from './lifecycle-state-reducer.js'; import { updateActivityActionTypes } from '../actions/activity-actions.js'; import { updateLastCommunicatedPlatformDetailsActionType } from '../actions/device-actions.js'; import { siweAuthActionTypes } from '../actions/siwe-actions.js'; import { + logOutActionTypes, + deleteAccountActionTypes, logInActionTypes, resetUserStateActionType, } from '../actions/user-actions.js'; @@ -17,6 +18,8 @@ fullStateSyncActionType, incrementalStateSyncActionType, updateConnectionStatusActionType, + setLateResponseActionType, + updateDisconnectedBarActionType, } from '../types/socket-types.js'; import { processUpdatesActionType } from '../types/update-types.js'; import { setNewSessionActionType } from '../utils/action-utils.js'; @@ -58,6 +61,21 @@ }, }; } + if (action.payload.sessionChange.cookieInvalidated) { + state = { + ...state, + keyserverInfos: { + ...state.keyserverInfos, + [keyserverID]: { + ...state.keyserverInfos[keyserverID], + connection: { + ...state.keyserverInfos[keyserverID].connection, + queuedActivityUpdates: [], + }, + }, + }, + }; + } } else if ( action.type === logInActionTypes.success || action.type === siweAuthActionTypes.success @@ -226,27 +244,76 @@ ...state, keyserverInfos, }; + } else if ( + action.type === logOutActionTypes.success || + action.type === deleteAccountActionTypes.success + ) { + let keyserverInfos = { ...state.keyserverInfos }; + for (const keyserverID in keyserverInfos) { + const oldConnection = keyserverInfos[keyserverID].connection; + + keyserverInfos = { + ...keyserverInfos, + [keyserverID]: { + ...keyserverInfos[keyserverID], + connection: { ...oldConnection, queuedActivityUpdates: [] }, + }, + }; + } + state = { + ...state, + keyserverInfos, + }; + } else if (action.type === setLateResponseActionType) { + const { messageID, isLate, keyserverID } = action.payload; + const lateResponsesSet = new Set( + state.keyserverInfos[keyserverID].connection.lateResponses, + ); + if (isLate) { + lateResponsesSet.add(messageID); + } else { + lateResponsesSet.delete(messageID); + } + state = { + ...state, + keyserverInfos: { + ...state.keyserverInfos, + [keyserverID]: { + ...state.keyserverInfos[keyserverID], + connection: { + ...state.keyserverInfos[keyserverID].connection, + lateResponses: [...lateResponsesSet], + }, + }, + }, + }; + } else if (action.type === updateDisconnectedBarActionType) { + state = { + ...state, + keyserverInfos: { + ...state.keyserverInfos, + [ashoatKeyserverID]: { + ...state.keyserverInfos[ashoatKeyserverID], + connection: { + ...state.keyserverInfos[ashoatKeyserverID].connection, + showDisconnectedBar: action.payload.visible, + }, + }, + }, + }; } - const connection = reduceConnectionInfo( - state.keyserverInfos[ashoatKeyserverID].connection, - action, - ); const deviceToken = reduceDeviceToken( state.keyserverInfos[ashoatKeyserverID].deviceToken, action, ); - if ( - connection !== state.keyserverInfos[ashoatKeyserverID].connection || - deviceToken !== state.keyserverInfos[ashoatKeyserverID].deviceToken - ) { + if (deviceToken !== state.keyserverInfos[ashoatKeyserverID].deviceToken) { state = { ...state, keyserverInfos: { ...state.keyserverInfos, [ashoatKeyserverID]: { ...state.keyserverInfos[ashoatKeyserverID], - connection, deviceToken, }, }, diff --git a/lib/socket/socket.react.js b/lib/socket/socket.react.js --- a/lib/socket/socket.react.js +++ b/lib/socket/socket.react.js @@ -771,7 +771,7 @@ ) => { this.props.dispatch({ type: setLateResponseActionType, - payload: { messageID, isLate }, + payload: { messageID, isLate, keyserverID: ashoatKeyserverID }, }); }; diff --git a/lib/types/socket-types.js b/lib/types/socket-types.js --- a/lib/types/socket-types.js +++ b/lib/types/socket-types.js @@ -517,6 +517,7 @@ export type SetLateResponsePayload = { +messageID: number, +isLate: boolean, + +keyserverID: string, }; export const updateDisconnectedBarActionType = 'UPDATE_DISCONNECTED_BAR';