fix: truncate submitted display names

we dont look for libsession throws when setting a display name.
libsession now truncates by default
pull/3083/head
William Grant 10 months ago
parent bc2e28b6b7
commit d252662630

@ -194,17 +194,17 @@ export const EditProfileDialog = () => {
const backButton = const backButton =
mode === 'edit' || mode === 'qr' mode === 'edit' || mode === 'qr'
? [ ? [
{ {
iconType: 'chevron', iconType: 'chevron',
iconRotation: 90, iconRotation: 90,
onClick: () => { onClick: () => {
if (loading) { if (loading) {
return; return;
} }
setMode('default'); setMode('default');
},
}, },
] },
]
: undefined; : undefined;
const onClickOK = async () => { const onClickOK = async () => {
@ -214,16 +214,12 @@ export const EditProfileDialog = () => {
try { try {
setLoading(true); setLoading(true);
await ProfileManager.updateOurProfileDisplayName(profileName); const validName = await ProfileManager.updateOurProfileDisplayName(profileName);
setUpdateProfileName(profileName); setUpdateProfileName(validName);
setMode('default'); setMode('default');
} catch (err) { } catch (err) {
// Note error substring is taken from libsession-util window.log.error('Profile update error', err);
if (err.message && err.message.includes('exceeds maximum length')) { setProfileNameError(window.i18n('unknownError'));
setProfileNameError(window.i18n('displayNameTooLong'));
} else {
setProfileNameError(window.i18n('unknownError'));
}
} finally { } finally {
setLoading(false); setLoading(false);
} }

@ -3,7 +3,6 @@ import { useDispatch } from 'react-redux';
import useMount from 'react-use/lib/useMount'; import useMount from 'react-use/lib/useMount';
import { SettingsKey } from '../../../data/settings-key'; import { SettingsKey } from '../../../data/settings-key';
import { mnDecode } from '../../../session/crypto/mnemonic'; import { mnDecode } from '../../../session/crypto/mnemonic';
import { ProfileManager } from '../../../session/profile_manager/ProfileManager';
import { StringUtils } from '../../../session/utils'; import { StringUtils } from '../../../session/utils';
import { fromHex } from '../../../session/utils/String'; import { fromHex } from '../../../session/utils/String';
import LIBSESSION_CONSTANTS from '../../../session/utils/libsession/libsession_constants'; import LIBSESSION_CONSTANTS from '../../../session/utils/libsession/libsession_constants';
@ -29,7 +28,6 @@ import {
sessionGenerateKeyPair, sessionGenerateKeyPair,
} from '../../../util/accountManager'; } from '../../../util/accountManager';
import { Storage, setSignWithRecoveryPhrase } from '../../../util/storage'; import { Storage, setSignWithRecoveryPhrase } from '../../../util/storage';
import { UserConfigWrapperActions } from '../../../webworker/workers/browser/libsession_worker_interface';
import { Flex } from '../../basic/Flex'; import { Flex } from '../../basic/Flex';
import { SpacerLG, SpacerSM } from '../../basic/Text'; import { SpacerLG, SpacerSM } from '../../basic/Text';
import { SessionInput } from '../../inputs'; import { SessionInput } from '../../inputs';
@ -101,32 +99,20 @@ export const CreateAccount = () => {
if (!privateKeyBytes) { if (!privateKeyBytes) {
throw new Error('Private key not found'); throw new Error('Private key not found');
} }
// validate display name using libsession
// eslint-disable-next-line max-len
// TODO [libsession validation] if we try and use a different display name after entering one that is already too long we get an error because the user config has been initialised. I call .free() in the finally but that doesn't help
await UserConfigWrapperActions.init(privateKeyBytes, null);
const validName = await ProfileManager.updateOurProfileDisplayName(displayName, true);
await signUp({ await signUp({
displayName: validName, displayName,
recoveryPassword, recoveryPassword,
}); });
dispatch(setAccountCreationStep(AccountCreation.Done)); dispatch(setAccountCreationStep(AccountCreation.Done));
} catch (err) { } catch (err) {
let errorString = err.message || String(err); const errorString = err.message || String(err);
// Note error substring is taken from libsession-util
if (err.message && err.message.includes('exceeds maximum length')) {
errorString = window.i18n('displayNameTooLong');
}
window.log.error( window.log.error(
`[onboarding] create account: signUpWithDetails failed! Error: ${errorString}` `[onboarding] create account: signUpWithDetails failed! Error: ${errorString}`
); );
dispatch(setAccountCreationStep(AccountCreation.DisplayName)); dispatch(setAccountCreationStep(AccountCreation.DisplayName));
dispatch(setDisplayNameError(errorString)); dispatch(setDisplayNameError(errorString));
} finally {
await UserConfigWrapperActions.free();
} }
}; };

@ -177,8 +177,6 @@ export const RestoreAccount = () => {
} }
try { try {
// validate display name using libsession
// TODO [libsession validation] once you have it working in CreateAccount.tsx you will need to do it here
const validName = await ProfileManager.updateOurProfileDisplayName(displayName, true); const validName = await ProfileManager.updateOurProfileDisplayName(displayName, true);
await signInWithNewDisplayName({ await signInWithNewDisplayName({
@ -187,11 +185,7 @@ export const RestoreAccount = () => {
dispatch, dispatch,
}); });
} catch (err) { } catch (err) {
let errorString = err.message || String(err); const errorString = err.message || String(err);
// Note error substring is taken from libsession-util
if (err.message && err.message.includes('exceeds maximum length')) {
errorString = window.i18n('displayNameTooLong');
}
window.log.error( window.log.error(
`[onboarding] restore account: Failed with new display name! Error: ${errorString}` `[onboarding] restore account: Failed with new display name! Error: ${errorString}`
); );

@ -99,8 +99,8 @@ export async function updateOurProfileDisplayName(newName: string, onboarding?:
const cleanName = sanitizeSessionUsername(newName).trim(); const cleanName = sanitizeSessionUsername(newName).trim();
if (onboarding) { if (onboarding) {
await UserConfigWrapperActions.setUserInfo(cleanName, CONVERSATION_PRIORITIES.default, null); const userInfoName = await UserConfigWrapperActions.setUserInfo(cleanName, CONVERSATION_PRIORITIES.default, null);
return cleanName; return userInfoName;
} }
const ourNumber = UserUtils.getOurPubKeyStrFromCache(); const ourNumber = UserUtils.getOurPubKeyStrFromCache();
@ -120,9 +120,9 @@ export async function updateOurProfileDisplayName(newName: string, onboarding?:
dbPriority, dbPriority,
dbProfileUrl && dbProfileKey dbProfileUrl && dbProfileKey
? { ? {
url: dbProfileUrl, url: dbProfileUrl,
key: dbProfileKey, key: dbProfileKey,
} }
: null : null
); );

Loading…
Cancel
Save