From 8eb226f6ae9797f969fe65f179df23bea05f17a6 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 13 Jul 2023 16:07:09 +0700 Subject: [PATCH 1/3] fix: Default avatar is changed when we select/unselect a member in Workspace invitation page --- src/libs/OptionsListUtils.js | 3 ++- src/libs/PersonalDetailsUtils.js | 2 +- src/libs/UserUtils.js | 6 +++--- src/libs/actions/Task.js | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 305ea224e6ab..c384bfb4a0e1 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -784,7 +784,8 @@ function getOptions( (searchValue !== CONST.EMAIL.CHRONOS || Permissions.canUseChronos(betas)) ) { // Generates an optimistic account ID for new users not yet saved in Onyx - const optimisticAccountID = UserUtils.generateAccountID(); + + const optimisticAccountID = UserUtils.generateAccountID(searchValue); const personalDetailsExtended = { ...personalDetails, [optimisticAccountID]: { diff --git a/src/libs/PersonalDetailsUtils.js b/src/libs/PersonalDetailsUtils.js index 26c0a67aae48..f76b985c5feb 100644 --- a/src/libs/PersonalDetailsUtils.js +++ b/src/libs/PersonalDetailsUtils.js @@ -61,7 +61,7 @@ function getAccountIDsByLogins(logins) { const currentDetail = _.find(personalDetails, (detail) => detail.login === login); if (!currentDetail) { // generate an account ID because in this case the detail is probably new, so we don't have a real accountID yet - foundAccountIDs.push(UserUtils.generateAccountID()); + foundAccountIDs.push(UserUtils.generateAccountID(login)); } else { foundAccountIDs.push(Number(currentDetail.accountID)); } diff --git a/src/libs/UserUtils.js b/src/libs/UserUtils.js index 4202856c3e75..da9ae70f68e2 100644 --- a/src/libs/UserUtils.js +++ b/src/libs/UserUtils.js @@ -209,11 +209,11 @@ function getSmallSizeAvatar(avatarURL, accountID) { /** * Generate a random accountID. * Uses the same approach of 'generateReportID'. - * + * @param {String} searchValue * @returns {Number} */ -function generateAccountID() { - return Math.floor(Math.random() * 2 ** 21) * 2 ** 32 + Math.floor(Math.random() * 2 ** 32); +function generateAccountID(searchValue) { + return hashText(searchValue, 2 ** 32); } export { diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index bc1d4d6c3536..3b57ac6a2fae 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -496,7 +496,7 @@ function setAssigneeValue(assignee, assigneeAccountID, shareDestination, isCurre // Generate optimistic accountID if this is a brand new user account that hasn't been created yet if (!newAssigneeAccountID) { - newAssigneeAccountID = UserUtils.generateAccountID(); + newAssigneeAccountID = UserUtils.generateAccountID(assignee); } if (!isCurrentUser) { let newChat = {}; From 74ddbf1ceceec9d1c3ac5e320b001c6ebd252e08 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 13 Jul 2023 16:46:58 +0700 Subject: [PATCH 2/3] fix: remove redundant empty line --- src/libs/OptionsListUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 2bae6ffdbbb2..3869fd793ae5 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -791,7 +791,6 @@ function getOptions( (searchValue !== CONST.EMAIL.CHRONOS || Permissions.canUseChronos(betas)) ) { // Generates an optimistic account ID for new users not yet saved in Onyx - const optimisticAccountID = UserUtils.generateAccountID(searchValue); const personalDetailsExtended = { ...personalDetails, From ffde4e4615571e959aa4de1d1970928fc401ce7e Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 13 Jul 2023 16:48:34 +0700 Subject: [PATCH 3/3] fix: update function comment --- src/libs/UserUtils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/UserUtils.js b/src/libs/UserUtils.js index da9ae70f68e2..dffb5580f0d3 100644 --- a/src/libs/UserUtils.js +++ b/src/libs/UserUtils.js @@ -207,8 +207,7 @@ function getSmallSizeAvatar(avatarURL, accountID) { } /** - * Generate a random accountID. - * Uses the same approach of 'generateReportID'. + * Generate a random accountID base on searchValue. * @param {String} searchValue * @returns {Number} */