Skip to content

Commit

Permalink
[native] Use recovery callServerEndpoint when fetching notif keys in …
Browse files Browse the repository at this point in the history
…resolveInvalidatedCookie

Summary:
This resolves [ENG-5410](https://linear.app/comm/issue/ENG-5410/resolution-attempt-triggers-second-resolution-attempt).

The version of `callServerEndpoint` that `resolveInvalidatedCookie` gets passed is defined [here](https://github.com/CommE2E/comm/blob/007502788f0ce66b602f27038106baf83236bfdb/lib/utils/action-utils.js#L192-L231). Instead of trying to dispatch a recovery attempt when it sees a session change that invalidates its cookie, this version of `callServerEndpoint` ignores the session change.

That solves the "double resolution" issue. It's also the right thing to use here... this overriden `callServerEndpoint` is used by the `logIn` action, and should be used by all other actions during the recovery attempt.

Depends on D9584

Test Plan: I used [this](https://gist.github.com/Ashoat/712e7d1e9aaee825dd8b4c6871b8a7d3) patch to test. Before this diff, logs showed the first recovery attempt triggering a second one. After this diff, there was only one recovery attempt, and the `initialNotificationsEncryptedMessage` was resolved correctly.

Reviewers: marcin, atul

Reviewed By: atul

Subscribers: tomek, wyilio

Differential Revision: https://phab.comm.dev/D9585
  • Loading branch information
Ashoat committed Oct 25, 2023
1 parent fd6684b commit 395ff5e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
7 changes: 5 additions & 2 deletions native/account/resolve-invalidated-cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import { fetchNativeKeychainCredentials } from './native-credentials.js';
import { getGlobalNavContext } from '../navigation/icky-global.js';
import { store } from '../redux/redux-setup.js';
import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors.js';
import type { InitialNotifMessageOptions } from '../utils/crypto-utils.js';

async function resolveInvalidatedCookie(
callServerEndpoint: CallServerEndpoint,
dispatchRecoveryAttempt: DispatchRecoveryAttempt,
logInActionSource: LogInActionSource,
getInitialNotificationsEncryptedMessage?: () => Promise<string>,
getInitialNotificationsEncryptedMessage?: (
?InitialNotifMessageOptions,
) => Promise<string>,
) {
const keychainCredentials = await fetchNativeKeychainCredentials();
if (!keychainCredentials) {
Expand All @@ -27,7 +30,7 @@ async function resolveInvalidatedCookie(

if (getInitialNotificationsEncryptedMessage) {
const initialNotificationsEncryptedMessage =
await getInitialNotificationsEncryptedMessage();
await getInitialNotificationsEncryptedMessage({ callServerEndpoint });
extraInfo = { ...extraInfo, initialNotificationsEncryptedMessage };
}

Expand Down
17 changes: 12 additions & 5 deletions native/utils/crypto-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import {
useServerCall,
useDispatchActionPromise,
} from 'lib/utils/action-utils.js';
import type { CallServerEndpointOptions } from 'lib/utils/call-server-endpoint.js';
import type {
CallServerEndpoint,
CallServerEndpointOptions,
} from 'lib/utils/call-server-endpoint.js';

import { commCoreModule } from '../native-modules.js';

type InitialNotifMessageOptions = {
export type InitialNotifMessageOptions = {
+callServerEndpoint?: ?CallServerEndpoint,
+callServerEndpointOptions?: ?CallServerEndpointOptions,
};
function useInitialNotificationsEncryptedMessage(): (
Expand All @@ -27,10 +31,13 @@ function useInitialNotificationsEncryptedMessage(): (

return React.useCallback(
async options => {
const callServerEndpoint = options?.callServerEndpoint;
const callServerEndpointOptions = options?.callServerEndpointOptions;
const olmSessionDataPromise = callGetOlmSessionInitializationData(
callServerEndpointOptions,
);

const initDataAction = callServerEndpoint
? getOlmSessionInitializationData(callServerEndpoint)
: callGetOlmSessionInitializationData;
const olmSessionDataPromise = initDataAction(callServerEndpointOptions);

dispatchActionPromise(
getOlmSessionInitializationDataActionTypes,
Expand Down

0 comments on commit 395ff5e

Please sign in to comment.