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 @@ -634,22 +634,7 @@ keyserverID: this.props.keyserverID, }, }); - if (sessionID !== null && sessionID !== undefined) { - invariant( - this.initializedWithUserState, - 'initializedWithUserState should be set when state sync received', - ); - this.props.dispatch({ - type: setNewSessionActionType, - payload: { - sessionChange: { cookieInvalidated: false, sessionID }, - preRequestUserState: this.initializedWithUserState, - error: null, - authActionSource: undefined, - keyserverID: this.props.keyserverID, - }, - }); - } + this.setNewReceivedSession(sessionID); } else { const { type, ...actionPayload } = stateSyncMessage.payload; this.props.dispatch({ @@ -674,6 +659,26 @@ this.markSocketInitialized(); } + setNewReceivedSession(sessionID: ?string) { + if (sessionID === null || sessionID === undefined) { + return; + } + invariant( + this.initializedWithUserState, + 'initializedWithUserState should be set when state sync received', + ); + this.props.dispatch({ + type: setNewSessionActionType, + payload: { + sessionChange: { cookieInvalidated: false, sessionID }, + preRequestUserState: this.initializedWithUserState, + error: null, + authActionSource: undefined, + keyserverID: this.props.keyserverID, + }, + }); + } + initializeSocket: (retriesLeft?: number) => Promise = async ( retriesLeft = 1, ) => { @@ -689,13 +694,9 @@ this.initFailureCount = 0; this.fetchingPendingUpdates = true; try { - const sessionState = this.props.sessionStateFunc(); void this.props.dispatchActionPromise( fetchPendingUpdatesActionTypes, - this.props.fetchPendingUpdates({ - ...sessionState, - keyserverID: this.props.keyserverID, - }), + this.fetchPendingUpdates(), ); } finally { this.fetchingPendingUpdates = false; @@ -733,6 +734,17 @@ } }; + async fetchPendingUpdates(): Promise { + const sessionState = this.props.sessionStateFunc(); + const result = await this.props.fetchPendingUpdates({ + ...sessionState, + keyserverID: this.props.keyserverID, + }); + const { sessionID, ...actionPayload } = result; + this.setNewReceivedSession(sessionID); + return actionPayload; + } + stopPing() { if (this.pingTimeoutID) { clearTimeout(this.pingTimeoutID);