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 @@ -19,17 +19,19 @@ setConnectionIssueActionType, updateConnectionStatusActionType, setLateResponseActionType, + setActiveSessionRecoveryActionType, } from '../keyserver-conn/keyserver-conn-types.js'; -import { resolveKeyserverSessionInvalidation } from '../keyserver-conn/recovery-utils.js'; import { unsupervisedBackgroundActionType } from '../reducers/lifecycle-state-reducer.js'; -import type { InitialNotifMessageOptions } from '../shared/crypto-utils.js'; import { pingFrequency, serverRequestSocketTimeout, clientRequestVisualTimeout, clientRequestSocketTimeout, } from '../shared/timeouts.js'; -import { recoveryActionSources } from '../types/account-types.js'; +import { + recoveryActionSources, + type RecoveryActionSource, +} from '../types/account-types.js'; import type { CompressedData } from '../types/compression-types.js'; import { type PlatformDetails } from '../types/device-types.js'; import type { CalendarQuery } from '../types/entry-types.js'; @@ -95,7 +97,6 @@ +sessionStateFunc: () => SessionState, +sessionIdentification: SessionIdentification, +cookie: ?string, - +urlPrefix: string, +connection: ConnectionInfo, +currentCalendarQuery: () => CalendarQuery, +frozen: boolean, @@ -103,16 +104,12 @@ +noDataAfterPolicyAcknowledgment?: boolean, +lastCommunicatedPlatformDetails: ?PlatformDetails, +decompressSocketMessage: CompressedData => string, + +activeSessionRecovery: null | RecoveryActionSource, // Redux dispatch functions +dispatch: Dispatch, +dispatchActionPromise: DispatchActionPromise, // async functions that hit server APIs +socketCrashLoopRecovery?: () => Promise, - // keyserver olm sessions specific props - +getInitialNotificationsEncryptedMessage?: ( - keyserverID: string, - options?: ?InitialNotifMessageOptions, - ) => Promise, }; type State = { +inflightRequests: ?InflightRequests, @@ -127,7 +124,6 @@ pingTimeoutID: ?TimeoutID; messageLastReceived: ?number; reopenConnectionAfterClosing: boolean = false; - invalidationRecoveryInProgress: boolean = false; initializedWithUserState: ?PreRequestUserState; failuresAfterPolicyAcknowledgment: number = 0; @@ -324,7 +320,7 @@ this.props.active && this.props.connection.status === 'disconnected' && prevProps.connection.status !== 'disconnected' && - !this.invalidationRecoveryInProgress + !this.props.activeSessionRecovery ) { this.reconnect(); } @@ -486,38 +482,14 @@ }); } } else if (message.type === serverSocketMessageTypes.AUTH_ERROR) { - const { sessionChange } = message; - const cookie = sessionChange ? sessionChange.cookie : this.props.cookie; - this.invalidationRecoveryInProgress = true; - - const recoverySessionChange = await resolveKeyserverSessionInvalidation( - this.props.dispatch, - cookie, - this.props.urlPrefix, - recoveryActionSources.socketAuthErrorResolutionAttempt, - this.props.keyserverID, - this.props.getInitialNotificationsEncryptedMessage, - ); - - if (!recoverySessionChange) { - const { cookie: newerCookie, currentUserInfo } = sessionChange; - this.props.dispatch({ - type: setNewSessionActionType, - payload: { - sessionChange: { - cookieInvalidated: true, - currentUserInfo, - cookie: newerCookie, - }, - preRequestUserState: this.initializedWithUserState, - error: null, - authActionSource: - recoveryActionSources.socketAuthErrorResolutionAttempt, - keyserverID: this.props.keyserverID, - }, - }); - } - this.invalidationRecoveryInProgress = false; + this.props.dispatch({ + type: setActiveSessionRecoveryActionType, + payload: { + activeSessionRecovery: + recoveryActionSources.socketAuthErrorResolutionAttempt, + keyserverID: this.props.keyserverID, + }, + }); } }; diff --git a/native/socket.react.js b/native/socket.react.js --- a/native/socket.react.js +++ b/native/socket.react.js @@ -140,6 +140,12 @@ keyserverID, ]); + const activeSessionRecovery = useSelector( + state => + state.keyserverStore.keyserverInfos[keyserverID]?.connection + .activeSessionRecovery, + ); + return ( ); }); diff --git a/web/socket.react.js b/web/socket.react.js --- a/web/socket.react.js +++ b/web/socket.react.js @@ -6,7 +6,6 @@ import { preRequestUserStateForSingleKeyserverSelector } from 'lib/selectors/account-selectors.js'; import { cookieSelector, - urlPrefixSelector, connectionSelector, lastCommunicatedPlatformDetailsSelector, } from 'lib/selectors/keyserver-selectors.js'; @@ -39,8 +38,6 @@ const { keyserverID } = props; const cookie = useSelector(cookieSelector(keyserverID)); - const urlPrefix = useSelector(urlPrefixSelector(keyserverID)); - invariant(urlPrefix, 'missing urlPrefix for given keyserver id'); const connection = useSelector(connectionSelector(keyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const active = useSelector( @@ -104,6 +101,12 @@ lastCommunicatedPlatformDetailsSelector(keyserverID), ); + const activeSessionRecovery = useSelector( + state => + state.keyserverStore.keyserverInfos[keyserverID]?.connection + .activeSessionRecovery, + ); + return ( ); });