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 @@ -61,33 +61,29 @@ }; } else if (action.type === resetUserStateActionType) { // this action is only dispatched on native - const stateCookie = state.keyserverInfos[ashoatKeyserverID]?.cookie; - const cookie = - stateCookie && stateCookie.startsWith('anonymous=') ? stateCookie : null; - const keyserverInfos = { ...state.keyserverInfos }; - for (const key in keyserverInfos) { - keyserverInfos[key] = { ...keyserverInfos[key], cookie: null }; + for (const keyserverID in keyserverInfos) { + const stateCookie = state.keyserverInfos[keyserverID]?.cookie; + const cookie = + stateCookie && stateCookie.startsWith('anonymous=') + ? stateCookie + : null; + keyserverInfos[keyserverID] = { ...keyserverInfos[keyserverID], cookie }; } state = { ...state, - keyserverInfos: { - ...keyserverInfos, - [ashoatKeyserverID]: { - ...state.keyserverInfos[ashoatKeyserverID], - cookie, - }, - }, + keyserverInfos, }; } else if (action.type === setNewSessionActionType) { + const { keyserverID } = action.payload; if (action.payload.sessionChange.cookie !== undefined) { state = { ...state, keyserverInfos: { ...state.keyserverInfos, - [ashoatKeyserverID]: { - ...state.keyserverInfos[ashoatKeyserverID], + [keyserverID]: { + ...state.keyserverInfos[keyserverID], cookie: action.payload.sessionChange.cookie, }, }, 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 @@ -635,6 +635,7 @@ preRequestUserState: this.initializedWithUserState, error: null, logInActionSource: undefined, + keyserverID: ashoatKeyserverID, }, }); } diff --git a/lib/types/session-types.js b/lib/types/session-types.js --- a/lib/types/session-types.js +++ b/lib/types/session-types.js @@ -94,10 +94,11 @@ }; export type SetSessionPayload = { - sessionChange: ClientSessionChange, - preRequestUserState: ?PreRequestUserState, - error: ?string, - logInActionSource: ?LogInActionSource, + +sessionChange: ClientSessionChange, + +preRequestUserState: ?PreRequestUserState, + +error: ?string, + +logInActionSource: ?LogInActionSource, + +keyserverID: string, }; export type SessionState = { 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 @@ -171,10 +171,17 @@ preRequestUserState: ?PreRequestUserState, error: ?string, logInActionSource: ?LogInActionSource, + keyserverID: string, ) { dispatch({ type: setNewSessionActionType, - payload: { sessionChange, preRequestUserState, error, logInActionSource }, + payload: { + sessionChange, + preRequestUserState, + error, + logInActionSource, + keyserverID, + }, }); } @@ -207,7 +214,14 @@ error: ?string, ) => { newSessionChange = sessionChange; - setNewSession(dispatch, sessionChange, null, error, logInActionSource); + setNewSession( + dispatch, + sessionChange, + null, + error, + logInActionSource, + keyserverID, + ); }; try { const result = await callServerEndpoint( @@ -309,6 +323,7 @@ }, error, undefined, + keyserverID, ); // This function gets called before callServerEndpoint sends a request, // to make sure that we're not in the middle of trying to recover