From 89aba76f7564715c482340f0eb520c59a6d13085 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 4 Dec 2024 09:56:57 +1100 Subject: [PATCH 1/8] fix: send approved message only when previously unapproved --- ts/interactions/conversationInteractions.ts | 2 +- ts/session/utils/calling/CallManager.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ts/interactions/conversationInteractions.ts b/ts/interactions/conversationInteractions.ts index 5f0265292..ab483c60d 100644 --- a/ts/interactions/conversationInteractions.ts +++ b/ts/interactions/conversationInteractions.ts @@ -91,7 +91,7 @@ export async function unblockConvoById(conversationId: string) { export const approveConvoAndSendResponse = async (conversationId: string) => { const convoToApprove = getConversationController().get(conversationId); - if (!convoToApprove) { + if (!convoToApprove || convoToApprove.isApproved()) { window?.log?.info('Conversation is already approved.'); return; } diff --git a/ts/session/utils/calling/CallManager.ts b/ts/session/utils/calling/CallManager.ts index 862b40919..62fa76d2b 100644 --- a/ts/session/utils/calling/CallManager.ts +++ b/ts/session/utils/calling/CallManager.ts @@ -35,6 +35,7 @@ import { MessageSender } from '../../sending'; import { getIsRinging } from '../RingingManager'; import { getBlackSilenceMediaStream } from './Silence'; import { ed25519Str } from '../String'; +import { sleepFor } from '../Promise'; export type InputItem = { deviceId: string; label: string }; @@ -534,6 +535,10 @@ export async function USER_callRecipient(recipient: string) { calledConvo.set('active_at', Date.now()); // addSingleOutgoingMessage does the commit for us on the convo await calledConvo.unhideIfNeeded(false); weAreCallerOnCurrentCall = true; + // Not ideal, but also temporary (see you in 2 years). + // We need to make sure the preoffer AND the messageRequestResponse sent in + // approveConvoAndSendResponse have different timestamps, as iOS will throw an error otherwise + await sleepFor(2); // initiating a call is analogous to sending a message request await approveConvoAndSendResponse(recipient); From a0f2f9dd509399943921212b78e720c41cf130aa Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 4 Dec 2024 10:23:06 +1100 Subject: [PATCH 2/8] chore: bump release 1.14.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d5b0f2cd6..ea3e888e4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "session-desktop", "productName": "Session", "description": "Private messaging from your desktop", - "version": "1.14.2", + "version": "1.14.3", "license": "GPL-3.0", "author": { "name": "Oxen Labs", From dc846573badc6aaf53167fe3f6a0385da30ba5e2 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 4 Dec 2024 10:27:00 +1100 Subject: [PATCH 3/8] chore: use gh runner image macos-13 as macos-12 is deprecated, and sometimes hang for 1h doing nothing --' --- .github/workflows/build-binaries.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml index 507e01178..0f7b35dab 100644 --- a/.github/workflows/build-binaries.yml +++ b/.github/workflows/build-binaries.yml @@ -118,7 +118,7 @@ jobs: # We want a mac arm64 build, and according to this https://github.com/actions/runner-images#available-images macos-14 is always arm64 # macos-14 is disabled for now as we hit our free tier limit for macos builds build_macos_x64: - runs-on: macos-12 + runs-on: macos-13 env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} MAC_CERTIFICATE: ${{ secrets.MAC_CERTIFICATE }} From d09a8aaf4c8b88edbadde9d3d7103f10fabae19b Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 4 Dec 2024 10:33:06 +1100 Subject: [PATCH 4/8] chore: replace 'clearnet' with 'unstable' --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- .github/workflows/build-binaries.yml | 2 -- CONTRIBUTING.md | 4 ++-- THEMES.md | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 2e219d735..d957f6f4d 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -14,7 +14,7 @@ Remember, you can preview this before saving it. ### Contributor checklist: - [ ] My commits are in nice logical chunks with [good commit messages](http://chris.beams.io/posts/git-commit/) -- [ ] My changes are [rebased](https://blog.axosoft.com/golden-rule-of-rebasing-in-git/) on the latest [`clearnet`](https://github.com/oxen-io/session-desktop/tree/clearnet) branch +- [ ] My changes are [rebased](https://blog.axosoft.com/golden-rule-of-rebasing-in-git/) on the latest [`unstable`](https://github.com/oxen-io/session-desktop/tree/unstable) branch - [ ] A `yarn ready` run passes successfully ([more about tests here](https://github.com/oxen-io/session-desktop/blob/master/CONTRIBUTING.md#tests)) - [ ] My changes are ready to be shipped to users diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml index 0f7b35dab..020b37bf0 100644 --- a/.github/workflows/build-binaries.yml +++ b/.github/workflows/build-binaries.yml @@ -8,13 +8,11 @@ on: push: branches: - master - - clearnet - unstable - 'release/**' - 'ci/**' pull_request: branches: - - clearnet - unstable - 'release/**' - 'ci/**' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fc2c48049..c4891a3b8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -239,10 +239,10 @@ So you wanna make a pull request? Please observe the following guidelines. - Please do not submit pull requests for pure translation fixes. Anyone can update the translations at [Crowdin](https://getsession.org/translate). - [Rebase](https://nathanleclaire.com/blog/2014/09/14/dont-be-scared-of-git-rebase/) your - changes on the latest `clearnet` branch, resolving any conflicts. + changes on the latest `unstable` branch, resolving any conflicts. This ensures that your changes will merge cleanly when you open your PR. - Be sure to add and run tests! -- Make sure the diff between `clearnet` and your branch contains only the +- Make sure the diff between `unstable` and your branch contains only the minimal set of changes needed to implement your feature or bugfix. This will make it easier for the person reviewing your code to approve the changes. Please do not submit a PR with commented out code or unfinished features. diff --git a/THEMES.md b/THEMES.md index 37a98dfc2..86e82a95c 100644 --- a/THEMES.md +++ b/THEMES.md @@ -23,7 +23,7 @@ Session doesn't support custom theming yet but it's pretty easy to add a new the [Here](https://github.com/yougotwill/session-desktop/pull/19) is an example PR for the `Windows Crash` theme which was inspired by the classic [blue screen of death](https://user-images.githubusercontent.com/14887287/203880658-e4a768d7-1b25-45d2-9e6d-00b233eb84a8.png). -Keep in mind that if you swap back to the latest `clearnet` with the `Windows Crash` theme set it may cause a database issue. So when you change your branch back make sure to set your theme to one of the [available themes](#available-themes) above. +Keep in mind that if you swap back to the latest `unstable` with the `Windows Crash` theme set it may cause a database issue. So when you change your branch back make sure to set your theme to one of the [available themes](#available-themes) above. ### Screenshot From df159d389b22ebc0bfacdaeb91e425d30fa8fe5c Mon Sep 17 00:00:00 2001 From: yougotwill Date: Fri, 20 Dec 2024 09:48:14 +0200 Subject: [PATCH 5/8] fix: updated git repo and clearnet references this also fixes links to the release notes --- .github/ISSUE_TEMPLATE/bug_report.yml | 4 ++-- .github/PULL_REQUEST_TEMPLATE.md | 6 +++--- CONTRIBUTING.md | 11 ++++++----- README.md | 6 +++--- THEMES.md | 2 +- package.json | 2 +- ts/components/settings/SessionSettings.tsx | 2 +- ts/mains/main_node.ts | 2 +- ts/node/locale.ts | 2 +- yarn.lock | 4 ++-- 10 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 5a679a315..9cc2082b0 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -6,9 +6,9 @@ body: - type: checkboxes attributes: label: Code of conduct - description: I have read and agree to adhere to the [Code of Conduct](https://github.com/oxen-io/session-desktop/blob/master/CODE_OF_CONDUCT.md). + description: I have read and agree to adhere to the [Code of Conduct](https://github.com/session-foundation/session-desktop/blob/master/CODE_OF_CONDUCT.md). options: - - label: I have read and agree to adhere to the [Code of Conduct](https://github.com/oxen-io/session-desktop/blob/master/CODE_OF_CONDUCT.md) + - label: I have read and agree to adhere to the [Code of Conduct](https://github.com/session-foundation/session-desktop/blob/master/CODE_OF_CONDUCT.md) required: true - type: checkboxes diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 2e219d735..40ec4b7fc 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -9,13 +9,13 @@ Remember, you can preview this before saving it. ### First time contributor checklist: -- [ ] I have read the [README](https://github.com/oxen-io/session-desktop/blob/master/README.md) and [Contributor Guidelines](https://github.com/oxen-io/session-desktop/blob/master/CONTRIBUTING.md) +- [ ] I have read the [README](https://github.com/session-foundation/session-desktop/blob/master/README.md) and [Contributor Guidelines](https://github.com/session-foundation/session-desktop/blob/master/CONTRIBUTING.md) ### Contributor checklist: - [ ] My commits are in nice logical chunks with [good commit messages](http://chris.beams.io/posts/git-commit/) -- [ ] My changes are [rebased](https://blog.axosoft.com/golden-rule-of-rebasing-in-git/) on the latest [`clearnet`](https://github.com/oxen-io/session-desktop/tree/clearnet) branch -- [ ] A `yarn ready` run passes successfully ([more about tests here](https://github.com/oxen-io/session-desktop/blob/master/CONTRIBUTING.md#tests)) +- [ ] My changes are [rebased](https://blog.axosoft.com/golden-rule-of-rebasing-in-git/) on the latest [`unstable`](https://github.com/session-foundation/session-desktop/tree/unstable) branch +- [ ] A `yarn ready` run passes successfully ([more about tests here](https://github.com/session-foundation/session-desktop/blob/master/CONTRIBUTING.md#tests)) - [ ] My changes are ready to be shipped to users ### Description diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fc2c48049..f04c2c6f6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ It's a good idea to gauge interest in your intended work by finding the current for it or creating a new one yourself. Use Github issues as a place to signal your intentions and get feedback from the users most likely to appreciate your changes. -You're most likely to have your pull request accepted if it addresses an existing Github issue marked with the [good-first-issue](https://github.com/oxen-io/session-desktop/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) tag, these issues are specifically tagged, because they are generally features/bug fixes which can be cleanly merged on a single platform without requiring cross platform work, are generally of lower complexity than larger features and are non contentious, meaning that the core team doesn't need to try and assess the community desire for such a feature before merging. +You're most likely to have your pull request accepted if it addresses an existing Github issue marked with the [good-first-issue](https://github.com/session-foundation/session-desktop/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) tag, these issues are specifically tagged, because they are generally features/bug fixes which can be cleanly merged on a single platform without requiring cross platform work, are generally of lower complexity than larger features and are non contentious, meaning that the core team doesn't need to try and assess the community desire for such a feature before merging. Of course we encourage community developers to work on ANY issue filed on our Github regardless of how it’s tagged, however if you pick up or create an issue without the “Good first issue” tag it would be best if you leave a comment on the issue so that the core team can give you any guidance required, especially around UI heavy features or issues which require cross platform integration. @@ -18,7 +18,7 @@ Of course we encourage community developers to work on ANY issue filed on our Gi ## Node.js -You'll need a [Node.js](https://nodejs.org/) version which matches our current version. You can check [`.nvmrc` in the `unstable` branch](https://github.com/oxen-io/session-desktop/blob/unstable/.nvmrc) to see what the current version is. +You'll need a [Node.js](https://nodejs.org/) version which matches our current version. You can check [`.nvmrc` in the `unstable` branch](https://github.com/session-foundation/session-desktop/blob/unstable/.nvmrc) to see what the current version is. If you use other node versions you might have or need a node version manager. @@ -139,7 +139,7 @@ sudo dnf install make automake gcc gcc-c++ kernel-devel Now, run these commands in your preferred terminal in a good directory for development: ``` -git clone https://github.com/oxen-io/session-desktop.git +git clone https://github.com/session-foundation/session-desktop.git cd session-desktop npm install --global yarn # (only if you don’t already have `yarn`) yarn install --frozen-lockfile # Install and build dependencies (this will take a while) @@ -239,10 +239,10 @@ So you wanna make a pull request? Please observe the following guidelines. - Please do not submit pull requests for pure translation fixes. Anyone can update the translations at [Crowdin](https://getsession.org/translate). - [Rebase](https://nathanleclaire.com/blog/2014/09/14/dont-be-scared-of-git-rebase/) your - changes on the latest `clearnet` branch, resolving any conflicts. + changes on the latest `unstable` branch, resolving any conflicts. This ensures that your changes will merge cleanly when you open your PR. - Be sure to add and run tests! -- Make sure the diff between `clearnet` and your branch contains only the +- Make sure the diff between `unstable` and your branch contains only the minimal set of changes needed to implement your feature or bugfix. This will make it easier for the person reviewing your code to approve the changes. Please do not submit a PR with commented out code or unfinished features. @@ -262,6 +262,7 @@ So you wanna make a pull request? Please observe the following guidelines. choices that may be helpful to someone reviewing or auditing the commit history in the future. When in doubt, err on the side of a longer commit message. + Above all, spend some time with the repository. Follow the pull request template added to your pull request description automatically. Take a look at recent approved pull requests, see how they did things. diff --git a/README.md b/README.md index f33e765d1..8ccac5f7c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Session integrates directly with [Oxen Service Nodes](https://docs.oxen.io/about ## Want to Contribute? Found a Bug or Have a feature request? -Please search for any [existing issues](https://github.com/oxen-io/session-desktop/issues) that describe your bug in order to avoid duplicate submissions.

Submissions can be made by making a pull request to our development branch.If you don't know where to start contributing please read [Contributing.md](CONTRIBUTING.md) and refer to issues tagged with the [Good-first-issue](https://github.com/oxen-io/session-desktop/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) tag. +Please search for any [existing issues](https://github.com/session-foundation/session-desktop/issues) that describe your bug in order to avoid duplicate submissions.

Submissions can be made by making a pull request to our development branch.If you don't know where to start contributing please read [Contributing.md](CONTRIBUTING.md) and refer to issues tagged with the [Good-first-issue](https://github.com/session-foundation/session-desktop/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) tag. ## Supported platforms @@ -32,8 +32,8 @@ gpg --import KeeJef.asc Get the signed hash for this release, the SESSION_VERSION needs to be updated for the release you want to verify ``` -export SESSION_VERSION=1.6.1 -wget https://github.com/oxen-io/session-desktop/releases/download/v$SESSION_VERSION/signatures.asc +export SESSION_VERSION=1.14.5 +wget https://github.com/session-foundation/session-desktop/releases/download/v$SESSION_VERSION/signatures.asc ``` Verify the signature of the hashes of the files diff --git a/THEMES.md b/THEMES.md index 37a98dfc2..86e82a95c 100644 --- a/THEMES.md +++ b/THEMES.md @@ -23,7 +23,7 @@ Session doesn't support custom theming yet but it's pretty easy to add a new the [Here](https://github.com/yougotwill/session-desktop/pull/19) is an example PR for the `Windows Crash` theme which was inspired by the classic [blue screen of death](https://user-images.githubusercontent.com/14887287/203880658-e4a768d7-1b25-45d2-9e6d-00b233eb84a8.png). -Keep in mind that if you swap back to the latest `clearnet` with the `Windows Crash` theme set it may cause a database issue. So when you change your branch back make sure to set your theme to one of the [available themes](#available-themes) above. +Keep in mind that if you swap back to the latest `unstable` with the `Windows Crash` theme set it may cause a database issue. So when you change your branch back make sure to set your theme to one of the [available themes](#available-themes) above. ### Screenshot diff --git a/package.json b/package.json index db91f1d02..c62b0c378 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "bytebuffer": "^5.0.1", "classnames": "2.2.5", "config": "1.28.1", - "curve25519-js": "https://github.com/oxen-io/curve25519-js", + "curve25519-js": "https://github.com/session-foundation/curve25519-js", "date-fns": "^3.6.0", "dompurify": "^2.0.7", "electron-localshortcut": "^3.2.1", diff --git a/ts/components/settings/SessionSettings.tsx b/ts/components/settings/SessionSettings.tsx index 86f913b2a..fee434e4d 100644 --- a/ts/components/settings/SessionSettings.tsx +++ b/ts/components/settings/SessionSettings.tsx @@ -73,7 +73,7 @@ const SessionInfo = () => { { void shell.openExternal( - `https://github.com/oxen-io/session-desktop/releases/tag/v${window.versionInfo.version}` + `https://github.com/session-foundation/session-desktop/releases/tag/v${window.versionInfo.version}` ); }} > diff --git a/ts/mains/main_node.ts b/ts/mains/main_node.ts index e3105124c..370815e46 100644 --- a/ts/mains/main_node.ts +++ b/ts/mains/main_node.ts @@ -529,7 +529,7 @@ setTimeout(readyForUpdates, TEN_MINUTES); function openReleaseNotes() { void shell.openExternal( - `https://github.com/oxen-io/session-desktop/releases/tag/v${app.getVersion()}` + `https://github.com/session-foundation/session-desktop/releases/tag/v${app.getVersion()}` ); } diff --git a/ts/node/locale.ts b/ts/node/locale.ts index 7acf1527a..9363b6796 100644 --- a/ts/node/locale.ts +++ b/ts/node/locale.ts @@ -11,7 +11,7 @@ export function normalizeLocaleName(locale: string) { const dashedLocale = locale.replaceAll('_', '-'); // Note: this is a pain, but we somehow needs to keep in sync this logic and the LOCALE_PATH_MAPPING from - // https://github.com/oxen-io/session-shared-scripts/blob/main/crowdin/generate_desktop_strings.py + // https://github.com/session-foundation/session-shared-scripts/blob/main/crowdin/generate_desktop_strings.py // What we do, is keep as is, anything given in LOCALE_PATH_MAPPING, but otherwise, keep only the first part of the locale. // So `es-419` is allowed, but `es-es` is hardcoded to es, fr_FR is hardcoded to fr, and so on. if ( diff --git a/yarn.lock b/yarn.lock index ba5e93eb0..a6246ca79 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2584,9 +2584,9 @@ csstype@3.1.3, csstype@^3.0.2, csstype@^3.1.2: resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.3.tgz#d80ff294d114fb0e6ac500fbf85b60137d7eff81" integrity sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw== -"curve25519-js@https://github.com/oxen-io/curve25519-js": +"curve25519-js@https://github.com/session-foundation/curve25519-js": version "0.0.4" - resolved "https://github.com/oxen-io/curve25519-js#102f8c0a31b5c58bad8606979036cf763be9f4f6" + resolved "https://github.com/session-foundation/curve25519-js#102f8c0a31b5c58bad8606979036cf763be9f4f6" dargs@^7.0.0: version "7.0.0" From c922d22c98dfec6b73053a3f73eacc37255ffddc Mon Sep 17 00:00:00 2001 From: yougotwill Date: Fri, 20 Dec 2024 10:02:26 +0200 Subject: [PATCH 6/8] fix: bump up minimum macOS version in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ccac5f7c..db2d115e3 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Please search for any [existing issues](https://github.com/session-foundation/se ## Supported platforms -Session requires Windows 10 or later, macOS Monterey (12) or later, or a Linux distribution with glibc 2.28 or later like Debian 10 or Ubuntu 20.04. +Session requires Windows 10 or later, macOS Ventura (13) or later, or a Linux distribution with glibc 2.28 or later like Debian 10 or Ubuntu 20.04. ## Build instruction From f9ccc317b68031aaf7f3c932b19bc90d3ba68367 Mon Sep 17 00:00:00 2001 From: yougotwill Date: Wed, 15 Jan 2025 13:34:31 +1100 Subject: [PATCH 7/8] fix: catch truncation errors when setting the display name fixes incorrectly showing shorter display name error in integration tests --- .../registration/stages/CreateAccount.tsx | 17 +++++++++++++++-- .../registration/stages/RestoreAccount.tsx | 16 ++++++++++++++-- ts/session/profile_manager/ProfileManager.ts | 6 ++---- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/ts/components/registration/stages/CreateAccount.tsx b/ts/components/registration/stages/CreateAccount.tsx index 05c04e9e3..db3391838 100644 --- a/ts/components/registration/stages/CreateAccount.tsx +++ b/ts/components/registration/stages/CreateAccount.tsx @@ -33,6 +33,7 @@ import { resetRegistration } from '../RegistrationStages'; import { ContinueButton, OnboardDescription, OnboardHeading } from '../components'; import { BackButtonWithinContainer } from '../components/BackButton'; import { displayNameIsValid, sanitizeDisplayNameOrToast } from '../utils'; +import { localize } from '../../../util/i18n/localizedString'; export type AccountDetails = { recoveryPassword: string; @@ -106,9 +107,21 @@ export const CreateAccount = () => { `[onboarding] create account: signUpWithDetails failed! Error: ${err.message || String(err)}` ); dispatch(setAccountCreationStep(AccountCreation.DisplayName)); - // Note: we have to assume here that libsession threw an error because the name was too long. + + switch (err.message) { + case 'failed to retrieve display name after setting it': + dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString())); + return; + case 'failed to get truncated displayName after setting it': + dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString())); + return; + default: + // we can't guarantee that an error has a message so we handle the final case outside of the switch + } + + // Note: we have to assume here that libsession threw an error because the name was too long since we covered the other cases. // The error reported by libsession is not localized - dispatch(setDisplayNameError(window.i18n('displayNameErrorDescriptionShorter'))); + dispatch(setDisplayNameError(localize('displayNameErrorDescriptionShorter').toString())); } }; diff --git a/ts/components/registration/stages/RestoreAccount.tsx b/ts/components/registration/stages/RestoreAccount.tsx index d006287b0..0635f874c 100644 --- a/ts/components/registration/stages/RestoreAccount.tsx +++ b/ts/components/registration/stages/RestoreAccount.tsx @@ -43,6 +43,7 @@ import { BackButtonWithinContainer } from '../components/BackButton'; import { useRecoveryProgressEffect } from '../hooks'; import { displayNameIsValid, sanitizeDisplayNameOrToast } from '../utils'; import { AccountDetails } from './CreateAccount'; +import { localize } from '../../../util/i18n/localizedString'; type AccountRestoreDetails = AccountDetails & { dispatch: Dispatch; abortSignal?: AbortSignal }; @@ -197,9 +198,20 @@ export const RestoreAccount = () => { ); dispatch(setAccountRestorationStep(AccountRestoration.DisplayName)); - // Note: we have to assume here that libsession threw an error because the name was too long. + switch (err.message) { + case 'failed to retrieve display name after setting it': + dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString())); + return; + case 'failed to get truncated displayName after setting it': + dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString())); + return; + default: + // we can't guarantee that an error has a message so we handle the final case outside of the switch + } + + // Note: we have to assume here that libsession threw an error because the name was too long since we covered the other cases. // The error reported by libsession is not localized - dispatch(setDisplayNameError(window.i18n('displayNameErrorDescriptionShorter'))); + dispatch(setDisplayNameError(localize('displayNameErrorDescriptionShorter').toString())); } }; diff --git a/ts/session/profile_manager/ProfileManager.ts b/ts/session/profile_manager/ProfileManager.ts index 3b321cac7..630574a9f 100644 --- a/ts/session/profile_manager/ProfileManager.ts +++ b/ts/session/profile_manager/ProfileManager.ts @@ -115,9 +115,7 @@ async function updateOurProfileDisplayNameOnboarding(newName: string) { const appliedName = await UserConfigWrapperActions.getName(); if (isNil(appliedName)) { - throw new Error( - 'updateOurProfileDisplayNameOnboarding failed to retrieve name after setting it' - ); + throw new Error('failed to retrieve display name after setting it'); } return appliedName; @@ -143,7 +141,7 @@ async function updateOurProfileDisplayName(newName: string) { await UserConfigWrapperActions.setNameTruncated(sanitizeSessionUsername(newName).trim()); const truncatedName = await UserConfigWrapperActions.getName(); if (isNil(truncatedName)) { - throw new Error('updateOurProfileDisplayName: failed to get truncated displayName back'); + throw new Error('failed to get truncated displayName after setting it'); } await UserConfigWrapperActions.setPriority(dbPriority); if (dbProfileUrl && !isEmpty(dbProfileKey)) { From fd24a47b91507a5bfacb32719dd0a8d12e81422f Mon Sep 17 00:00:00 2001 From: yougotwill Date: Wed, 15 Jan 2025 15:25:08 +1100 Subject: [PATCH 8/8] fix: create custom error for display name retrieval errors --- .../registration/stages/CreateAccount.tsx | 13 ++++--------- .../registration/stages/RestoreAccount.tsx | 14 ++++---------- ts/session/profile_manager/ProfileManager.ts | 5 +++-- ts/session/utils/errors.ts | 8 ++++++++ 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/ts/components/registration/stages/CreateAccount.tsx b/ts/components/registration/stages/CreateAccount.tsx index db3391838..4b8feae32 100644 --- a/ts/components/registration/stages/CreateAccount.tsx +++ b/ts/components/registration/stages/CreateAccount.tsx @@ -34,6 +34,7 @@ import { ContinueButton, OnboardDescription, OnboardHeading } from '../component import { BackButtonWithinContainer } from '../components/BackButton'; import { displayNameIsValid, sanitizeDisplayNameOrToast } from '../utils'; import { localize } from '../../../util/i18n/localizedString'; +import { RetrieveDisplayNameError } from '../../../session/utils/errors'; export type AccountDetails = { recoveryPassword: string; @@ -108,15 +109,9 @@ export const CreateAccount = () => { ); dispatch(setAccountCreationStep(AccountCreation.DisplayName)); - switch (err.message) { - case 'failed to retrieve display name after setting it': - dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString())); - return; - case 'failed to get truncated displayName after setting it': - dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString())); - return; - default: - // we can't guarantee that an error has a message so we handle the final case outside of the switch + if (err instanceof RetrieveDisplayNameError) { + dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString())); + return; } // Note: we have to assume here that libsession threw an error because the name was too long since we covered the other cases. diff --git a/ts/components/registration/stages/RestoreAccount.tsx b/ts/components/registration/stages/RestoreAccount.tsx index 0635f874c..d995efaa1 100644 --- a/ts/components/registration/stages/RestoreAccount.tsx +++ b/ts/components/registration/stages/RestoreAccount.tsx @@ -6,7 +6,7 @@ import { InvalidWordsError, NotEnoughWordsError } from '../../../session/crypto/ 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 { NotFoundError, RetrieveDisplayNameError } from '../../../session/utils/errors'; import { trigger } from '../../../shims/events'; import { AccountRestoration, @@ -198,15 +198,9 @@ export const RestoreAccount = () => { ); dispatch(setAccountRestorationStep(AccountRestoration.DisplayName)); - switch (err.message) { - case 'failed to retrieve display name after setting it': - dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString())); - return; - case 'failed to get truncated displayName after setting it': - dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString())); - return; - default: - // we can't guarantee that an error has a message so we handle the final case outside of the switch + if (err instanceof RetrieveDisplayNameError) { + dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString())); + return; } // Note: we have to assume here that libsession threw an error because the name was too long since we covered the other cases. diff --git a/ts/session/profile_manager/ProfileManager.ts b/ts/session/profile_manager/ProfileManager.ts index 630574a9f..8f03302cf 100644 --- a/ts/session/profile_manager/ProfileManager.ts +++ b/ts/session/profile_manager/ProfileManager.ts @@ -6,6 +6,7 @@ import { SyncUtils, UserUtils } from '../utils'; import { fromHexToArray, sanitizeSessionUsername, toHex } from '../utils/String'; import { AvatarDownload } from '../utils/job_runners/jobs/AvatarDownloadJob'; import { CONVERSATION_PRIORITIES, ConversationTypeEnum } from '../../models/types'; +import { RetrieveDisplayNameError } from '../utils/errors'; export type Profile = { displayName: string | undefined; @@ -115,7 +116,7 @@ async function updateOurProfileDisplayNameOnboarding(newName: string) { const appliedName = await UserConfigWrapperActions.getName(); if (isNil(appliedName)) { - throw new Error('failed to retrieve display name after setting it'); + throw new RetrieveDisplayNameError(); } return appliedName; @@ -141,7 +142,7 @@ async function updateOurProfileDisplayName(newName: string) { await UserConfigWrapperActions.setNameTruncated(sanitizeSessionUsername(newName).trim()); const truncatedName = await UserConfigWrapperActions.getName(); if (isNil(truncatedName)) { - throw new Error('failed to get truncated displayName after setting it'); + throw new RetrieveDisplayNameError(); } await UserConfigWrapperActions.setPriority(dbPriority); if (dbProfileUrl && !isEmpty(dbProfileKey)) { diff --git a/ts/session/utils/errors.ts b/ts/session/utils/errors.ts index 9ede6802a..a6b4d5c12 100644 --- a/ts/session/utils/errors.ts +++ b/ts/session/utils/errors.ts @@ -74,3 +74,11 @@ export class SnodeResponseError extends Error { Object.setPrototypeOf(this, SnodeResponseError.prototype); } } + +export class RetrieveDisplayNameError extends Error { + constructor(message = 'failed to retrieve display name after setting it') { + super(message); + // restore prototype chain + Object.setPrototypeOf(this, SnodeResponseError.prototype); + } +}