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 @@ -2,7 +2,7 @@ import reduceConnectionInfo from './connection-reducer.js'; import { reduceDeviceToken } from './device-token-reducer.js'; -import reduceLastCommunicatedPlatformDetails from './last-communicated-platform-details-reducer.js'; +import { updateLastCommunicatedPlatformDetailsActionType } from '../actions/device-actions.js'; import { addKeyserverActionType, removeKeyserverActionType, @@ -13,6 +13,7 @@ resetUserStateActionType, logOutActionTypes, deleteAccountActionTypes, + registerActionTypes, } from '../actions/user-actions.js'; import type { KeyserverStore } from '../types/keyserver-types'; import type { BaseAction } from '../types/redux-types.js'; @@ -22,6 +23,7 @@ } from '../types/socket-types.js'; import { processUpdatesActionType } from '../types/update-types.js'; import { setNewSessionActionType } from '../utils/action-utils.js'; +import { getConfig } from '../utils/config.js'; import { setURLPrefix } from '../utils/url-utils.js'; import { ashoatKeyserverID } from '../utils/validation-utils.js'; @@ -101,6 +103,7 @@ [keyserverID]: { ...state.keyserverInfos[keyserverID], updatesCurrentAsOf: updatesCurrentAsOf[keyserverID], + lastCommunicatedPlatformDetails: getConfig().platformDetails, }, }, }; @@ -156,12 +159,31 @@ }, }, }; + } else if (action.type === updateLastCommunicatedPlatformDetailsActionType) { + const { keyserverID, platformDetails } = action.payload; + state = { + ...state, + keyserverInfos: { + ...state.keyserverInfos, + [keyserverID]: { + ...state.keyserverInfos[keyserverID], + lastCommunicatedPlatformDetails: platformDetails, + }, + }, + }; + } else if (action.type === registerActionTypes.success) { + state = { + ...state, + keyserverInfos: { + ...state.keyserverInfos, + [ashoatKeyserverID]: { + ...state.keyserverInfos[ashoatKeyserverID], + lastCommunicatedPlatformDetails: getConfig().platformDetails, + }, + }, + }; } - const lastCommunicatedPlatformDetails = reduceLastCommunicatedPlatformDetails( - state.keyserverInfos[ashoatKeyserverID].lastCommunicatedPlatformDetails, - action, - ); const connection = reduceConnectionInfo( state.keyserverInfos[ashoatKeyserverID].connection, action, @@ -172,8 +194,6 @@ ); if ( connection !== state.keyserverInfos[ashoatKeyserverID].connection || - lastCommunicatedPlatformDetails !== - state.keyserverInfos[ashoatKeyserverID].lastCommunicatedPlatformDetails || deviceToken !== state.keyserverInfos[ashoatKeyserverID].deviceToken ) { state = { @@ -183,7 +203,6 @@ [ashoatKeyserverID]: { ...state.keyserverInfos[ashoatKeyserverID], connection, - lastCommunicatedPlatformDetails, deviceToken, }, }, diff --git a/lib/reducers/last-communicated-platform-details-reducer.js b/lib/reducers/last-communicated-platform-details-reducer.js deleted file mode 100644 --- a/lib/reducers/last-communicated-platform-details-reducer.js +++ /dev/null @@ -1,28 +0,0 @@ -// @flow - -import { updateLastCommunicatedPlatformDetailsActionType } from '../actions/device-actions.js'; -import { siweAuthActionTypes } from '../actions/siwe-actions.js'; -import { - logInActionTypes, - registerActionTypes, -} from '../actions/user-actions.js'; -import type { PlatformDetails } from '../types/device-types'; -import type { BaseAction } from '../types/redux-types'; -import { getConfig } from '../utils/config.js'; - -export default function reduceLastCommunicatedPlatformDetails( - state: ?PlatformDetails, - action: BaseAction, -): ?PlatformDetails { - if ( - action.type === logInActionTypes.success || - action.type === siweAuthActionTypes.success || - action.type === registerActionTypes.success - ) { - return getConfig().platformDetails; - } - if (action.type === updateLastCommunicatedPlatformDetailsActionType) { - return action.payload; - } - return state; -} 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 @@ -601,7 +601,10 @@ if (shouldSendInitialPlatformDetails) { this.props.dispatch({ type: updateLastCommunicatedPlatformDetailsActionType, - payload: getConfig().platformDetails, + payload: { + platformDetails: getConfig().platformDetails, + keyserverID: ashoatKeyserverID, + }, }); } diff --git a/lib/types/device-types.js b/lib/types/device-types.js --- a/lib/types/device-types.js +++ b/lib/types/device-types.js @@ -41,6 +41,11 @@ +stateVersion?: number, }; +export type LastCommunicatedPlatformDetails = { + +platformDetails: PlatformDetails, + +keyserverID: string, +}; + export type VersionResponse = { +codeVersion: number, +ownerUsername: ?string, diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -20,7 +20,7 @@ import type { CryptoStore } from './crypto-types.js'; import type { GetVersionActionPayload, - PlatformDetails, + LastCommunicatedPlatformDetails, } from './device-types.js'; import type { ClientDBDraftInfo, DraftStore } from './draft-types.js'; import type { EnabledApps, SupportedApps } from './enabled-apps.js'; @@ -1183,7 +1183,7 @@ } | { +type: 'UPDATE_LAST_COMMUNICATED_PLATFORM_DETAILS', - +payload: PlatformDetails, + +payload: LastCommunicatedPlatformDetails, } | { +type: 'RESET_USER_STATE', +payload?: void } | { diff --git a/lib/utils/action-utils.js b/lib/utils/action-utils.js --- a/lib/utils/action-utils.js +++ b/lib/utils/action-utils.js @@ -239,6 +239,7 @@ dispatch, options, false, + keyserverID, ); if (callServerEndpointCallback) { callServerEndpointCallback(!!newSessionChange); @@ -412,6 +413,7 @@ dispatch, options, loggedIn, + keyserverID, ); } diff --git a/lib/utils/call-server-endpoint.js b/lib/utils/call-server-endpoint.js --- a/lib/utils/call-server-endpoint.js +++ b/lib/utils/call-server-endpoint.js @@ -92,6 +92,7 @@ dispatch: Dispatch, options?: ?CallServerEndpointOptions, loggedIn: boolean, + keyserverID: string, ): Promise { const possibleReplacement = await waitIfCookieInvalidated(); if (possibleReplacement) { @@ -210,7 +211,7 @@ if (!error && shouldSendPlatformDetails) { dispatch({ type: updateLastCommunicatedPlatformDetailsActionType, - payload: getConfig().platformDetails, + payload: { platformDetails: getConfig().platformDetails, keyserverID }, }); }