Skip to content

Commit

Permalink
[lib] Fix unable to register new user
Browse files Browse the repository at this point in the history
Summary:
issue: https://linear.app/comm/issue/ENG-6309/unable-to-connect-to-ashoats-keyserver-during-new-registration-flow
This is a super quick fix because this issue is blocking other devs.
The problem was that it was not possible to register a new user, even with Ashoat's keyserver picked

> The reason for this happening is that when we are connecting to a new keyserver we don't know its id. So to be able to call it with our actions we create paramOverride, which includes keyserverInfos. In those keyserverInfos the key is the urlPrefix, not admins id. This keyserver is later on added to the store by a setNewSessionActionType.
> So what happens in the new registration flow is that when a user selects Ashoat's keyserver, a new entry is added to the keyserverStore.keyserverInfos, with its key being defaultURLPrefix. This entry is broken - hence the missing status, which will be fixed by ENG-6097. But we should either way be using the entry for Ashoat's keyserver that is already in our store.

Test Plan: Tested that it is possible to register a user with the new registration flow, provided Ashoat's keyserver is picked

Reviewers: ginsu, ashoat

Reviewed By: ginsu, ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D10479
  • Loading branch information
InkaAlicja committed Dec 29, 2023
1 parent 2d82668 commit 95c8fb8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/selectors/keyserver-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ const baseUrlPrefixSelector: (
const urlPrefixSelector: (keyserverID: string) => (state: AppState) => ?string =
_memoize(baseUrlPrefixSelector);

const urlsToIDsSelector: (state: AppState) => {
+[url: string]: ?string,
} = createSelector(
(state: AppState) => state.keyserverStore.keyserverInfos,
(infos: { +[key: string]: KeyserverInfo }) => {
const urlToIDs: { [string]: ?string } = {};
for (const keyserverID in infos) {
urlToIDs[infos[keyserverID].urlPrefix] = keyserverID;
}
return urlToIDs;
},
);

const baseConnectionSelector: (
keyserverID: string,
) => (state: AppState) => ?ConnectionInfo = keyserverID => (state: AppState) =>
Expand Down Expand Up @@ -162,6 +175,7 @@ export {
updatesCurrentAsOfSelector,
currentAsOfSelector,
urlPrefixSelector,
urlsToIDsSelector,
connectionSelector,
lastCommunicatedPlatformDetailsSelector,
deviceTokensSelector,
Expand Down
23 changes: 22 additions & 1 deletion lib/shared/keyserver-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,43 @@ import {
useGetVersion,
getVersionActionTypes,
} from '../actions/device-actions.js';
import { urlsToIDsSelector } from '../selectors/keyserver-selectors.js';
import { useDispatchActionPromise } from '../utils/action-utils.js';
import { useSelector } from '../utils/redux-utils.js';

function useIsKeyserverURLValid(keyserverURL?: string): () => Promise<boolean> {
const urlsToIDs: { +[keyserverID: string]: ?string } =
useSelector(urlsToIDsSelector);

const keyserverID: ?string = keyserverURL
? urlsToIDs[keyserverURL]
: undefined;

const keyserverInfo = useSelector(state =>
keyserverID ? state.keyserverStore.keyserverInfos[keyserverID] : undefined,
);

const serverCallParamOverride = React.useMemo(() => {
if (!keyserverURL) {
return undefined;
}

if (keyserverInfo && keyserverID) {
return {
keyserverInfos: {
[(keyserverID: string)]: keyserverInfo,
},
};
}

return {
keyserverInfos: {
[(keyserverURL: string)]: {
urlPrefix: keyserverURL,
},
},
};
}, [keyserverURL]);
}, [keyserverID, keyserverInfo, keyserverURL]);

const getVersionCall = useGetVersion(serverCallParamOverride);

Expand Down

0 comments on commit 95c8fb8

Please sign in to comment.