Skip to content

Instantly share code, notes, and snippets.

@vdhanan
Created September 13, 2023 04:00
Show Gist options
  • Save vdhanan/c1a70adc6125268a8f9a085f0b1fcea2 to your computer and use it in GitHub Desktop.
Save vdhanan/c1a70adc6125268a8f9a085f0b1fcea2 to your computer and use it in GitHub Desktop.
diff --git a/native/account/registration/registration-server-call.js b/native/account/registration/registration-server-call.js
index ce8b4c053..314f40b1d 100644
--- a/native/account/registration/registration-server-call.js
+++ b/native/account/registration/registration-server-call.js
@@ -5,12 +5,17 @@ import { Platform } from 'react-native';
import { useDispatch } from 'react-redux';
import { setDataLoadedActionType } from 'lib/actions/client-db-store-actions.js';
-import { registerActionTypes, register } from 'lib/actions/user-actions.js';
+import {
+ registerActionTypes,
+ register,
+ setAccessTokenActionType,
+} from 'lib/actions/user-actions.js';
import type { LogInStartingPayload } from 'lib/types/account-types.js';
import {
useServerCall,
useDispatchActionPromise,
} from 'lib/utils/action-utils.js';
+import { values } from 'lib/utils/objects.js';
import { setURLPrefix } from 'lib/utils/url-utils.js';
import type {
@@ -22,6 +27,7 @@ import {
useNativeSetUserAvatar,
useUploadSelectedMedia,
} from '../../avatars/avatar-hooks.js';
+import { commCoreModule, commRustModule } from '../../native-modules.js';
import { NavContext } from '../../navigation/navigation-context.js';
import { useSelector } from '../../redux/redux-utils.js';
import { nativeLogInExtraInfoSelector } from '../../selectors/account-selectors.js';
@@ -66,6 +72,7 @@ function useRegistrationServerCall(): RegistrationServerCallInput => Promise<voi
const dispatchActionPromise = useDispatchActionPromise();
const callRegister = useServerCall(register);
+ const reduxDispatch = useDispatch();
const registerUsernameAccount = React.useCallback(
async (
@@ -75,6 +82,46 @@ function useRegistrationServerCall(): RegistrationServerCallInput => Promise<voi
const extraInfo = await logInExtraInfo();
const registerPromise = (async () => {
try {
+ const signedIdentityKeysBlob = extraInfo.signedIdentityKeysBlob;
+ if (signedIdentityKeysBlob) {
+ const contentOneTimeKeys =
+ await commCoreModule.getPrimaryOneTimeKeys(10);
+ const contentOneTimeKeyValues = values(
+ contentOneTimeKeys.curve25519,
+ );
+ const notifOneTimeKeys =
+ await commCoreModule.getNotificationsOneTimeKeys(10);
+ const notifOneTimeKeyValues = values(notifOneTimeKeys.curve25519);
+ const signedPrekeys = await commCoreModule.generateAndGetPrekeys();
+ const userIDAndTokenString = await commRustModule.registerUser(
+ accountSelection.username,
+ accountSelection.password,
+ signedIdentityKeysBlob.payload,
+ signedIdentityKeysBlob.signature,
+ signedPrekeys.contentPrekey,
+ signedPrekeys.contentPrekeySignature,
+ signedPrekeys.notifPrekey,
+ signedPrekeys.notifPrekeySignature,
+ contentOneTimeKeyValues,
+ notifOneTimeKeyValues,
+ );
+ const userIDAndToken = JSON.parse(userIDAndTokenString);
+ console.log('user id and token: ' + userIDAndTokenString);
+ console.log('user id: ' + userIDAndToken.user_id);
+ console.log('access token: ' + userIDAndToken.access_token);
+ if (
+ userIDAndToken &&
+ typeof userIDAndToken.user_id === 'string' &&
+ typeof userIDAndToken.access_token === 'string'
+ ) {
+ console.log('about to dispatch token action');
+ reduxDispatch({
+ type: setAccessTokenActionType,
+ payload: userIDAndToken.access_token,
+ });
+ }
+ }
+
const result = await callRegister(
{
...extraInfo,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment