diff --git a/lib/hooks/disconnected-bar.js b/lib/hooks/disconnected-bar.js --- a/lib/hooks/disconnected-bar.js +++ b/lib/hooks/disconnected-bar.js @@ -22,7 +22,7 @@ } dispatch({ type: updateDisconnectedBarActionType, - payload: { visible: newDisconnected }, + payload: { visible: newDisconnected, keyserverID: ashoatKeyserverID }, }); }, [disconnected, dispatch], 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,6 +1,5 @@ // @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'; @@ -11,11 +10,11 @@ } from '../actions/keyserver-actions.js'; import { siweAuthActionTypes } from '../actions/siwe-actions.js'; import { - logInActionTypes, - resetUserStateActionType, logOutActionTypes, deleteAccountActionTypes, registerActionTypes, + logInActionTypes, + resetUserStateActionType, } from '../actions/user-actions.js'; import { queueActivityUpdatesActionType } from '../types/activity-types.js'; import type { KeyserverStore } from '../types/keyserver-types'; @@ -24,6 +23,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'; @@ -35,18 +36,7 @@ state: KeyserverStore, action: BaseAction, ): KeyserverStore { - if ( - action.type === logOutActionTypes.success || - action.type === deleteAccountActionTypes.success - ) { - state = { - keyserverInfos: { - [ashoatKeyserverID]: { - ...state.keyserverInfos[ashoatKeyserverID], - }, - }, - }; - } else if (action.type === addKeyserverActionType) { + if (action.type === addKeyserverActionType) { return { ...state, keyserverInfos: { @@ -94,6 +84,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 @@ -273,27 +278,75 @@ ...state, keyserverInfos, }; + } else if ( + action.type === logOutActionTypes.success || + action.type === deleteAccountActionTypes.success + ) { + // We want to remove all keyservers but Ashoat's keyserver + const oldConnection = state.keyserverInfos[ashoatKeyserverID].connection; + + const keyserverInfos = { + [ashoatKeyserverID]: { + ...state.keyserverInfos[ashoatKeyserverID], + 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) { + const { keyserverID } = action.payload; + state = { + ...state, + keyserverInfos: { + ...state.keyserverInfos, + [keyserverID]: { + ...state.keyserverInfos[keyserverID], + connection: { + ...state.keyserverInfos[keyserverID].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,10 +517,14 @@ export type SetLateResponsePayload = { +messageID: number, +isLate: boolean, + +keyserverID: string, }; export const updateDisconnectedBarActionType = 'UPDATE_DISCONNECTED_BAR'; -export type UpdateDisconnectedBarPayload = { +visible: boolean }; +export type UpdateDisconnectedBarPayload = { + +visible: boolean, + +keyserverID: string, +}; export type OneTimeKeyGenerator = (inc: number) => string;