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 @@ -3,7 +3,6 @@ import reduceConnectionInfo from './connection-reducer.js'; import { reduceDeviceToken } from './device-token-reducer.js'; import reduceLastCommunicatedPlatformDetails from './last-communicated-platform-details-reducer.js'; -import reduceUpdatesCurrentAsOf from './updates-reducer.js'; import { addKeyserverActionType, removeKeyserverActionType, @@ -91,21 +90,57 @@ } } else if ( action.type === logInActionTypes.success || - action.type === siweAuthActionTypes.success || - action.type === fullStateSyncActionType || - action.type === incrementalStateSyncActionType || - action.type === processUpdatesActionType + action.type === siweAuthActionTypes.success ) { - const updatesCurrentAsOf = reduceUpdatesCurrentAsOf( - state.keyserverInfos[ashoatKeyserverID].updatesCurrentAsOf, - action, + const { updatesCurrentAsOf } = action.payload; + for (const keyserverID in updatesCurrentAsOf) { + state = { + ...state, + keyserverInfos: { + ...state.keyserverInfos, + [keyserverID]: { + ...state.keyserverInfos[keyserverID], + updatesCurrentAsOf: updatesCurrentAsOf[keyserverID], + }, + }, + }; + } + } else if (action.type === fullStateSyncActionType) { + const { keyserverID } = action.payload; + state = { + ...state, + keyserverInfos: { + ...state.keyserverInfos, + [keyserverID]: { + ...state.keyserverInfos[keyserverID], + updatesCurrentAsOf: action.payload.updatesCurrentAsOf, + }, + }, + }; + } else if (action.type === incrementalStateSyncActionType) { + const { keyserverID } = action.payload; + state = { + ...state, + keyserverInfos: { + ...state.keyserverInfos, + [keyserverID]: { + ...state.keyserverInfos[keyserverID], + updatesCurrentAsOf: action.payload.updatesResult.currentAsOf, + }, + }, + }; + } else if (action.type === processUpdatesActionType) { + const { keyserverID } = action.payload; + const updatesCurrentAsOf = Math.max( + action.payload.updatesResult.currentAsOf, + state.keyserverInfos[keyserverID].updatesCurrentAsOf, ); state = { ...state, keyserverInfos: { ...state.keyserverInfos, - [ashoatKeyserverID]: { - ...state.keyserverInfos[ashoatKeyserverID], + [keyserverID]: { + ...state.keyserverInfos[keyserverID], updatesCurrentAsOf, }, }, diff --git a/lib/reducers/updates-reducer.js b/lib/reducers/updates-reducer.js deleted file mode 100644 --- a/lib/reducers/updates-reducer.js +++ /dev/null @@ -1,32 +0,0 @@ -// @flow - -import { siweAuthActionTypes } from '../actions/siwe-actions.js'; -import { logInActionTypes } from '../actions/user-actions.js'; -import type { BaseAction } from '../types/redux-types.js'; -import { - fullStateSyncActionType, - incrementalStateSyncActionType, -} from '../types/socket-types.js'; -import { processUpdatesActionType } from '../types/update-types.js'; -import { ashoatKeyserverID } from '../utils/validation-utils.js'; - -function reduceUpdatesCurrentAsOf( - currentAsOf: number, - action: BaseAction, -): number { - if ( - action.type === logInActionTypes.success || - action.type === siweAuthActionTypes.success - ) { - return action.payload.updatesCurrentAsOf[ashoatKeyserverID]; - } else if (action.type === fullStateSyncActionType) { - return action.payload.updatesCurrentAsOf; - } else if (action.type === incrementalStateSyncActionType) { - return action.payload.updatesResult.currentAsOf; - } else if (action.type === processUpdatesActionType) { - return Math.max(action.payload.updatesResult.currentAsOf, currentAsOf); - } - return currentAsOf; -} - -export default reduceUpdatesCurrentAsOf; 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 @@ -352,6 +352,7 @@ sendMessage={this.sendMessageWithoutID} addListener={this.addListener} removeListener={this.removeListener} + keyserverID={ashoatKeyserverID} /> number, +addListener: (listener: SocketListener) => void, +removeListener: (listener: SocketListener) => void, + +keyserverID: string, }; export default function UpdateHandler(props: Props): React.Node { - const { addListener, removeListener, sendMessage } = props; + const { addListener, removeListener, sendMessage, keyserverID } = props; const dispatch = useDispatch(); const connection = useSelector(connectionSelector(ashoatKeyserverID)); @@ -36,7 +37,7 @@ } dispatch({ type: processUpdatesActionType, - payload: message.payload, + payload: { ...message.payload, keyserverID }, }); if (connectionStatus !== 'connected') { return; @@ -48,7 +49,7 @@ }, }); }, - [connectionStatus, dispatch, sendMessage], + [connectionStatus, dispatch, keyserverID, sendMessage], ); useEffect(() => { addListener(onMessage); 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 @@ -203,6 +203,7 @@ export type StateSyncFullActionPayload = { ...ClientFullStateSync, +calendarQuery: CalendarQuery, + +keyserverID: string, }; export type ClientStateSyncFullSocketPayload = { ...ClientFullStateSync, @@ -254,6 +255,7 @@ export type StateSyncIncrementalActionPayload = { ...ClientIncrementalStateSync, +calendarQuery: CalendarQuery, + +keyserverID: string, }; type ClientStateSyncIncrementalSocketPayload = { +type: 1, diff --git a/lib/types/update-types.js b/lib/types/update-types.js --- a/lib/types/update-types.js +++ b/lib/types/update-types.js @@ -282,6 +282,7 @@ export type ClientUpdatesResultWithUserInfos = { +updatesResult: ClientUpdatesResult, +userInfos: $ReadOnlyArray, + +keyserverID: string, }; export type CreateUpdatesResult = {