diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -684,7 +684,24 @@ if (!identityClient.registerPasswordUser) { throw new Error('Register password user method unimplemented'); } - return identityClient.registerPasswordUser; + const { registerPasswordUser } = identityClient; + const { markPrekeysAsPublished } = getConfig().olmAPI; + + return React.useCallback( + async (username: string, password: string, fid: ?string) => { + const response = await registerPasswordUser(username, password, fid); + try { + await markPrekeysAsPublished(); + } catch (e) { + console.log( + 'Failed to mark prekeys as published:', + getMessageForException(e), + ); + } + return response; + }, + [registerPasswordUser, markPrekeysAsPublished], + ); } function useIdentityWalletRegister(): ( walletAddress: string, @@ -698,7 +715,34 @@ if (!identityClient.registerWalletUser) { throw new Error('Register wallet user method unimplemented'); } - return identityClient.registerWalletUser; + const { registerWalletUser } = identityClient; + const { markPrekeysAsPublished } = getConfig().olmAPI; + + return React.useCallback( + async ( + walletAddress: string, + siweMessage: string, + siweSignature: string, + fid: ?string, + ) => { + const response = await registerWalletUser( + walletAddress, + siweMessage, + siweSignature, + fid, + ); + try { + await markPrekeysAsPublished(); + } catch (e) { + console.log( + 'Failed to mark prekeys as published:', + getMessageForException(e), + ); + } + return response; + }, + [registerWalletUser, markPrekeysAsPublished], + ); } const identityGenerateNonceActionTypes = Object.freeze({ @@ -753,6 +797,7 @@ const identityClient = client?.identityClient; const preRequestUserState = useSelector(state => state.currentUserInfo); const callClaimUsername = useClaimUsername(); + const { markPrekeysAsPublished } = getConfig().olmAPI; return React.useCallback( (username, password) => { @@ -783,13 +828,26 @@ signature, ); } + try { + await markPrekeysAsPublished(); + } catch (e) { + console.log( + 'Failed to mark prekeys as published:', + getMessageForException(e), + ); + } return { ...result, preRequestUserState, }; })(); }, - [identityClient, preRequestUserState, callClaimUsername], + [ + identityClient, + markPrekeysAsPublished, + preRequestUserState, + callClaimUsername, + ], ); } function useIdentityWalletLogIn(): ( @@ -800,7 +858,32 @@ const client = React.useContext(IdentityClientContext); const identityClient = client?.identityClient; invariant(identityClient, 'Identity client should be set'); - return identityClient.logInWalletUser; + const { logInWalletUser } = identityClient; + const { markPrekeysAsPublished } = getConfig().olmAPI; + + return React.useCallback( + async ( + walletAddress: string, + siweMessage: string, + siweSignature: string, + ) => { + const response = await logInWalletUser( + walletAddress, + siweMessage, + siweSignature, + ); + try { + await markPrekeysAsPublished(); + } catch (e) { + console.log( + 'Failed to mark prekeys as published:', + getMessageForException(e), + ); + } + return response; + }, + [logInWalletUser, markPrekeysAsPublished], + ); } function useIdentitySecondaryDeviceLogIn(): ( userID: string, @@ -811,18 +894,32 @@ const { generateNonce, uploadKeysForRegisteredDeviceAndLogIn } = identityClient; - const { signMessage } = getConfig().olmAPI; + const { signMessage, markPrekeysAsPublished } = getConfig().olmAPI; return React.useCallback( async (userID: string) => { const nonce = await generateNonce(); const nonceSignature = await signMessage(nonce); - return await uploadKeysForRegisteredDeviceAndLogIn(userID, { + const response = await uploadKeysForRegisteredDeviceAndLogIn(userID, { nonce, nonceSignature, }); + try { + await markPrekeysAsPublished(); + } catch (e) { + console.log( + 'Failed to mark prekeys as published:', + getMessageForException(e), + ); + } + return response; }, - [generateNonce, signMessage, uploadKeysForRegisteredDeviceAndLogIn], + [ + generateNonce, + markPrekeysAsPublished, + signMessage, + uploadKeysForRegisteredDeviceAndLogIn, + ], ); }