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 @@ -18,6 +18,7 @@ logInActionTypes, resetUserStateActionType, } from '../actions/user-actions.js'; +import { setNewSessionKeyserverInfoBase } from '../shared/keyserver-utils.js'; import { queueActivityUpdatesActionType } from '../types/activity-types.js'; import type { KeyserverInfos, KeyserverStore } from '../types/keyserver-types'; import type { BaseAction } from '../types/redux-types.js'; @@ -76,13 +77,18 @@ }; } else if (action.type === setNewSessionActionType) { const { keyserverID } = action.payload; + const keyserverInfoBase = setNewSessionKeyserverInfoBase( + state, + action.payload, + ); + if (action.payload.sessionChange.cookie !== undefined) { state = { ...state, keyserverInfos: { ...state.keyserverInfos, [keyserverID]: { - ...state.keyserverInfos[keyserverID], + ...keyserverInfoBase, cookie: action.payload.sessionChange.cookie, }, }, @@ -94,7 +100,7 @@ keyserverInfos: { ...state.keyserverInfos, [keyserverID]: { - ...state.keyserverInfos[keyserverID], + ...keyserverInfoBase, connection: { ...state.keyserverInfos[keyserverID].connection, queuedActivityUpdates: [], diff --git a/lib/shared/keyserver-utils.js b/lib/shared/keyserver-utils.js --- a/lib/shared/keyserver-utils.js +++ b/lib/shared/keyserver-utils.js @@ -7,6 +7,12 @@ getVersionActionTypes, } from '../actions/device-actions.js'; import { urlsToIDsSelector } from '../selectors/keyserver-selectors.js'; +import { + type KeyserverInfo, + type KeyserverStore, + defaultKeyserverInfo, +} from '../types/keyserver-types.js'; +import type { SetSessionPayload } from '../types/session-types'; import { useDispatchActionPromise } from '../utils/action-utils.js'; import { useSelector } from '../utils/redux-utils.js'; @@ -66,4 +72,19 @@ }, [dispatchActionPromise, getVersionCall, keyserverURL]); } -export { useIsKeyserverURLValid }; +function setNewSessionKeyserverInfoBase( + state: KeyserverStore, + actionPayload: SetSessionPayload, +): KeyserverInfo { + const { keyserverID, urlPrefix } = actionPayload; + let baseInfo = state.keyserverInfos[keyserverID]; + if (!baseInfo) { + baseInfo = { + ...defaultKeyserverInfo, + urlPrefix, + }; + } + return baseInfo; +} + +export { useIsKeyserverURLValid, setNewSessionKeyserverInfoBase }; 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 @@ -506,6 +506,7 @@ logInActionSource: logInActionSources.socketAuthErrorResolutionAttempt, keyserverID: ashoatKeyserverID, + urlPrefix: this.props.urlPrefix, }, }); } @@ -642,6 +643,7 @@ error: null, logInActionSource: undefined, keyserverID: ashoatKeyserverID, + urlPrefix: this.props.urlPrefix, }, }); } 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 @@ -83,6 +83,7 @@ +error: ?string, +logInActionSource: ?LogInActionSource, +keyserverID: string, + +urlPrefix: 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 @@ -172,6 +172,7 @@ error: ?string, logInActionSource: ?LogInActionSource, keyserverID: string, + urlPrefix: string, ) { dispatch({ type: setNewSessionActionType, @@ -181,6 +182,7 @@ error, logInActionSource, keyserverID, + urlPrefix, }, }); } @@ -221,6 +223,7 @@ error, logInActionSource, keyserverID, + urlPrefix, ); }; try { @@ -327,6 +330,7 @@ error, undefined, keyserverID, + urlPrefix, ); // This function gets called before callServerEndpoint sends a request, // to make sure that we're not in the middle of trying to recover diff --git a/web/redux/redux-setup.js b/web/redux/redux-setup.js --- a/web/redux/redux-setup.js +++ b/web/redux/redux-setup.js @@ -15,6 +15,7 @@ import baseReducer from 'lib/reducers/master-reducer.js'; import { mostRecentlyReadThreadSelector } from 'lib/selectors/thread-selectors.js'; import { isLoggedIn } from 'lib/selectors/user-selectors.js'; +import { setNewSessionKeyserverInfoBase } from 'lib/shared/keyserver-utils.js'; import { invalidSessionDowngrade } from 'lib/shared/session-utils.js'; import type { CryptoStore } from 'lib/types/crypto-types.js'; import type { DraftStore } from 'lib/types/draft-types.js'; @@ -179,6 +180,10 @@ loadingStatuses: reduceLoadingStatuses(state.loadingStatuses, action), }; } + const keyserverInfoBase = setNewSessionKeyserverInfoBase( + state.keyserverStore, + action.payload, + ); state = { ...state, @@ -187,7 +192,7 @@ keyserverInfos: { ...state.keyserverStore.keyserverInfos, [keyserverID]: { - ...state.keyserverStore.keyserverInfos[keyserverID], + ...keyserverInfoBase, sessionID: action.payload.sessionChange.sessionID, }, },