diff --git a/ts/components/dialog/edit-profile/EditProfileDialog.tsx b/ts/components/dialog/edit-profile/EditProfileDialog.tsx
index 9efffbef2..12f3655f2 100644
--- a/ts/components/dialog/edit-profile/EditProfileDialog.tsx
+++ b/ts/components/dialog/edit-profile/EditProfileDialog.tsx
@@ -10,7 +10,6 @@ import { YourSessionIDPill, YourSessionIDSelectable } from '../../basic/YourSess
import { useHotkey } from '../../../hooks/useHotkey';
import { useOurAvatarPath, useOurConversationUsername } from '../../../hooks/useParamSelector';
import { ProfileManager } from '../../../session/profile_manager/ProfileManager';
-import LIBSESSION_CONSTANTS from '../../../session/utils/libsession/libsession_constants';
import { editProfileModal, updateEditProfilePictureModal } from '../../../state/ducks/modalDialog';
import { SessionWrapperModal } from '../../SessionWrapperModal';
import { Flex } from '../../basic/Flex';
@@ -214,6 +213,8 @@ export const EditProfileDialog = () => {
try {
setLoading(true);
+ // Note: this will not throw, but just truncate the display name if it is too long.
+ // I guess it is expected as there is no UI to show anything else than a generic error?
const validName = await ProfileManager.updateOurProfileDisplayName(profileName);
setUpdateProfileName(validName);
setProfileName(validName);
@@ -330,7 +331,6 @@ export const EditProfileDialog = () => {
tabIndex={0}
required={true}
error={profileNameError}
- maxLength={LIBSESSION_CONSTANTS.CONTACT_MAX_NAME_LENGTH}
textSize={'xl'}
centerText={true}
inputRef={inputRef}
diff --git a/ts/components/registration/stages/CreateAccount.tsx b/ts/components/registration/stages/CreateAccount.tsx
index a7bcd2fa7..4fdfd1185 100644
--- a/ts/components/registration/stages/CreateAccount.tsx
+++ b/ts/components/registration/stages/CreateAccount.tsx
@@ -6,7 +6,6 @@ import { mnDecode } from '../../../session/crypto/mnemonic';
import { ProfileManager } from '../../../session/profile_manager/ProfileManager';
import { StringUtils } from '../../../session/utils';
import { fromHex } from '../../../session/utils/String';
-import LIBSESSION_CONSTANTS from '../../../session/utils/libsession/libsession_constants';
import { trigger } from '../../../shims/events';
import {
AccountCreation,
@@ -93,7 +92,8 @@ export const CreateAccount = () => {
}
try {
- const validName = await ProfileManager.updateOurProfileDisplayName(displayName, true);
+ // this throws if the display name is too long
+ const validName = await ProfileManager.updateOurProfileDisplayNameOnboarding(displayName);
await signUp({
displayName: validName,
@@ -102,12 +102,13 @@ export const CreateAccount = () => {
dispatch(setAccountCreationStep(AccountCreation.Done));
} catch (err) {
- const errorString = err.message || String(err);
window.log.error(
- `[onboarding] create account: signUpWithDetails failed! Error: ${errorString}`
+ `[onboarding] create account: signUpWithDetails failed! Error: ${err.message || String(err)}`
);
dispatch(setAccountCreationStep(AccountCreation.DisplayName));
- dispatch(setDisplayNameError(errorString));
+ // Note: we have to assume here that libsession threw an error because the name was too long.
+ // The error reporterd by libsession is not localized
+ dispatch(setDisplayNameError(window.i18n('displayNameErrorDescriptionShorter')));
}
};
@@ -146,7 +147,6 @@ export const CreateAccount = () => {
}}
onEnterPressed={signUpWithDetails}
error={displayNameError}
- maxLength={LIBSESSION_CONSTANTS.CONTACT_MAX_NAME_LENGTH}
inputDataTestId="display-name-input"
/>
diff --git a/ts/components/registration/stages/RestoreAccount.tsx b/ts/components/registration/stages/RestoreAccount.tsx
index 9a44bdd10..0fb3413e2 100644
--- a/ts/components/registration/stages/RestoreAccount.tsx
+++ b/ts/components/registration/stages/RestoreAccount.tsx
@@ -7,7 +7,6 @@ import { ProfileManager } from '../../../session/profile_manager/ProfileManager'
import { PromiseUtils } from '../../../session/utils';
import { TaskTimedOutError } from '../../../session/utils/Promise';
import { NotFoundError } from '../../../session/utils/errors';
-import LIBSESSION_CONSTANTS from '../../../session/utils/libsession/libsession_constants';
import { trigger } from '../../../shims/events';
import {
AccountRestoration,
@@ -181,7 +180,8 @@ export const RestoreAccount = () => {
}
try {
- const validName = await ProfileManager.updateOurProfileDisplayName(displayName, true);
+ // this will throw if the display name is too long
+ const validName = await ProfileManager.updateOurProfileDisplayNameOnboarding(displayName);
const trimmedPassword = recoveryPassword.trim();
setRecoveryPassword(trimmedPassword);
@@ -192,12 +192,14 @@ export const RestoreAccount = () => {
dispatch,
});
} catch (err) {
- const errorString = err.message || String(err);
window.log.error(
- `[onboarding] restore account: Failed with new display name! Error: ${errorString}`
+ `[onboarding] restore account: Failed with new display name! Error: ${err.message || String(err)}`
);
dispatch(setAccountRestorationStep(AccountRestoration.DisplayName));
- dispatch(setDisplayNameError(errorString));
+
+ // Note: we have to assume here that libsession threw an error because the name was too long.
+ // The error reporterd by libsession is not localized
+ dispatch(setDisplayNameError(window.i18n('displayNameErrorDescriptionShorter')));
}
};
@@ -314,7 +316,6 @@ export const RestoreAccount = () => {
}}
onEnterPressed={recoverAndEnterDisplayName}
error={displayNameError}
- maxLength={LIBSESSION_CONSTANTS.CONTACT_MAX_NAME_LENGTH}
inputDataTestId="display-name-input"
/>
diff --git a/ts/components/registration/utils/index.tsx b/ts/components/registration/utils/index.tsx
index 7d5a210b2..69b938483 100644
--- a/ts/components/registration/utils/index.tsx
+++ b/ts/components/registration/utils/index.tsx
@@ -7,24 +7,15 @@ export function sanitizeDisplayNameOrToast(
onDisplayNameError: (error: string | undefined) => any,
dispatch?: Dispatch
) {
- try {
- const sanitizedName = sanitizeSessionUsername(displayName);
- const errorString = !sanitizedName ? window.i18n('displayNameErrorDescription') : undefined;
- if (dispatch) {
- dispatch(onDisplayNameError(errorString));
- } else {
- onDisplayNameError(errorString); // this is is either calling dispatch in the caller or just `setDisplayNameError`
- }
-
- return sanitizedName;
- } catch (e) {
- if (dispatch) {
- dispatch(onDisplayNameError(window.i18n('displayNameErrorDescriptionShorter')));
- } else {
- onDisplayNameError(window.i18n('displayNameErrorDescriptionShorter'));
- }
- return displayName;
+ const sanitizedName = sanitizeSessionUsername(displayName);
+ const errorString = !sanitizedName ? window.i18n('displayNameErrorDescription') : undefined;
+ if (dispatch) {
+ dispatch(onDisplayNameError(errorString));
+ } else {
+ onDisplayNameError(errorString); // this is is either calling dispatch in the caller or just `setDisplayNameError`
}
+
+ return sanitizedName;
}
/**
diff --git a/ts/node/migration/sessionMigrations.ts b/ts/node/migration/sessionMigrations.ts
index 7d18460ea..bf754b578 100644
--- a/ts/node/migration/sessionMigrations.ts
+++ b/ts/node/migration/sessionMigrations.ts
@@ -1376,11 +1376,13 @@ function updateToSessionSchemaVersion31(currentVersion: number, db: BetterSqlite
const ourDbProfileKey = fromHexToArray(ourConversation.profileKey || '');
const ourConvoPriority = ourConversation.priority;
+ // we don't want to throw if somehow our display name in the DB is too long here, so we use the truncated version.
+ userProfileWrapper.setNameTruncated(ourDbName);
+ userProfileWrapper.setPriority(ourConvoPriority);
if (ourDbProfileUrl && !isEmpty(ourDbProfileKey)) {
- userProfileWrapper.setUserInfo(ourDbName, ourConvoPriority, {
- url: ourDbProfileUrl,
- key: ourDbProfileKey,
- });
+ userProfileWrapper.setProfilePic({ key: ourDbProfileKey, url: ourDbProfileUrl });
+ } else {
+ userProfileWrapper.setProfilePic({ key: null, url: null });
}
MIGRATION_HELPERS.V31.insertContactIntoContactWrapper(
diff --git a/ts/receiver/configMessage.ts b/ts/receiver/configMessage.ts
index a0ebac3ef..bf5ef17d4 100644
--- a/ts/receiver/configMessage.ts
+++ b/ts/receiver/configMessage.ts
@@ -208,8 +208,10 @@ async function updateLibsessionLatestProcessedUserTimestamp(
* Instead you will need to updateOurProfileLegacyOrViaLibSession() to support them
*/
async function handleUserProfileUpdate(result: IncomingConfResult): Promise {
- const updateUserInfo = await UserConfigWrapperActions.getUserInfo();
- if (!updateUserInfo) {
+ const profilePic = await UserConfigWrapperActions.getProfilePic();
+ const displayName = await UserConfigWrapperActions.getName();
+ const priority = await UserConfigWrapperActions.getPriority();
+ if (!profilePic || isEmpty(profilePic)) {
return result;
}
@@ -219,15 +221,15 @@ async function handleUserProfileUpdate(result: IncomingConfResult): Promise GenericWrapperActions.currentHashes('UserConfig'),
/** UserConfig wrapper specific actions */
- getUserInfo: async () =>
- callLibSessionWorker(['UserConfig', 'getUserInfo']) as Promise<
- ReturnType
- >,
- setUserInfo: async (
- name: string,
- priority: number,
- profilePic: { url: string; key: Uint8Array } | null
- ) =>
- callLibSessionWorker(['UserConfig', 'setUserInfo', name, priority, profilePic]) as Promise<
- ReturnType
+ getPriority: async () =>
+ callLibSessionWorker(['UserConfig', 'getPriority']) as Promise<
+ ReturnType
+ >,
+ getName: async () =>
+ callLibSessionWorker(['UserConfig', 'getName']) as Promise<
+ ReturnType
+ >,
+ getProfilePic: async () =>
+ callLibSessionWorker(['UserConfig', 'getProfilePic']) as Promise<
+ ReturnType
+ >,
+ setPriority: async (priority: number) =>
+ callLibSessionWorker(['UserConfig', 'setPriority', priority]) as Promise<
+ ReturnType
+ >,
+ setName: async (name: string) =>
+ callLibSessionWorker(['UserConfig', 'setName', name]) as Promise<
+ ReturnType
+ >,
+ setNameTruncated: async (name: string) =>
+ callLibSessionWorker(['UserConfig', 'setNameTruncated', name]) as Promise<
+ ReturnType
+ >,
+ setProfilePic: async (profilePic: ProfilePicture) =>
+ callLibSessionWorker(['UserConfig', 'setProfilePic', profilePic]) as Promise<
+ ReturnType
>,
getEnableBlindedMsgRequest: async () =>
callLibSessionWorker(['UserConfig', 'getEnableBlindedMsgRequest']) as Promise<