From 70570da7ae8d24fd246b25521895cea691de28a9 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Wed, 28 Jun 2023 12:21:12 -0400 Subject: [PATCH 1/9] Fix proptypes in ArchivedReportFooter for accountIDs instead of logins --- src/components/ArchivedReportFooter.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/ArchivedReportFooter.js b/src/components/ArchivedReportFooter.js index a742b97fb0a9..1af8cadc80ca 100644 --- a/src/components/ArchivedReportFooter.js +++ b/src/components/ArchivedReportFooter.js @@ -22,11 +22,11 @@ const propTypes = { /** The reason the report was closed */ reason: PropTypes.string.isRequired, - /** (For accountMerged reason only), the email of the previous owner of this report. */ - oldLogin: PropTypes.string, + /** (For accountMerged reason only), the accountID of the previous owner of this report. */ + oldAccountID: PropTypes.number, - /** (For accountMerged reason only), the email of the account the previous owner was merged into */ - newLogin: PropTypes.string, + /** (For accountMerged reason only), the accountID of the account the previous owner was merged into */ + newLogin: PropTypes.number, }).isRequired, }), From 782f9633d6da65f6918fa37e6a80cd90c46a29b0 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Wed, 28 Jun 2023 12:22:15 -0400 Subject: [PATCH 2/9] Change newLogin to newAccountID --- src/components/ArchivedReportFooter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ArchivedReportFooter.js b/src/components/ArchivedReportFooter.js index 1af8cadc80ca..d7a138d9a473 100644 --- a/src/components/ArchivedReportFooter.js +++ b/src/components/ArchivedReportFooter.js @@ -26,7 +26,7 @@ const propTypes = { oldAccountID: PropTypes.number, /** (For accountMerged reason only), the accountID of the account the previous owner was merged into */ - newLogin: PropTypes.number, + newAccountID: PropTypes.number, }).isRequired, }), From b7854fe8677de9170ae9be9a9ef8ff3bdf89073a Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Wed, 28 Jun 2023 13:23:51 -0400 Subject: [PATCH 3/9] Use whisperedToAccountIDs instead of whisperedTo --- src/libs/ReportActionsUtils.js | 2 +- src/libs/ReportUtils.js | 14 +++++++------- src/pages/home/report/ReportActionItem.js | 12 ++++++------ src/pages/home/report/reportActionPropTypes.js | 4 ++-- tests/utils/LHNTestUtils.js | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 5c9b62ca47d9..face346872d2 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -436,7 +436,7 @@ function isMessageDeleted(reportAction) { } function isWhisperAction(action) { - return (action.whisperedTo || []).length > 0; + return (action.whisperedToAccountIDs || []).length > 0; } export { diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 84ad9585446a..193355d5def0 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2200,29 +2200,29 @@ function canLeaveRoom(report, isPolicyMember) { } /** - * @param {string[]} participants + * @param {number[]} participantAccountIDs * @returns {Boolean} */ -function isCurrentUserTheOnlyParticipant(participants) { - return participants && participants.length === 1 && participants[0] === sessionEmail; +function isCurrentUserTheOnlyParticipant(participantAccountIDs) { + return participantAccountIDs && participantAccountIDs.length === 1 && participantAccountIDs[0] === sessionAccountID; } /** * Returns display names for those that can see the whisper. * However, it returns "you" if the current user is the only one who can see it besides the person that sent it. * - * @param {string[]} participants + * @param {number[]} participantAccountIDs * @returns {string} */ -function getWhisperDisplayNames(participants) { - const isWhisperOnlyVisibleToCurrentUSer = isCurrentUserTheOnlyParticipant(participants); +function getWhisperDisplayNames(participantAccountIDs) { + const isWhisperOnlyVisibleToCurrentUSer = isCurrentUserTheOnlyParticipant(participantAccountIDs); // When the current user is the only participant, the display name needs to be "you" because that's the only person reading it if (isWhisperOnlyVisibleToCurrentUSer) { return Localize.translateLocal('common.youAfterPreposition'); } - return _.map(participants, (login) => getDisplayNameForParticipant(login, !isWhisperOnlyVisibleToCurrentUSer)).join(', '); + return _.map(participantAccountIDs, (accountID) => getDisplayNameForParticipant(accountID, !isWhisperOnlyVisibleToCurrentUSer)).join(', '); } /** diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 24be64dc6468..265876992a94 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -437,11 +437,11 @@ function ReportActionItem(props) { } const hasErrors = !_.isEmpty(props.action.errors); - const whisperedTo = props.action.whisperedTo || []; - const isWhisper = whisperedTo.length > 0; - const isMultipleParticipant = whisperedTo.length > 1; - const isWhisperOnlyVisibleByUser = isWhisper && ReportUtils.isCurrentUserTheOnlyParticipant(whisperedTo); - const whisperedToPersonalDetails = isWhisper ? _.filter(props.personalDetails, (details) => _.includes(whisperedTo, details.login)) : []; + const whisperedToAccountIDs = props.action.whisperedToAccountIDs || []; + const isWhisper = whisperedToAccountIDs.length > 0; + const isMultipleParticipant = whisperedToAccountIDs.length > 1; + const isWhisperOnlyVisibleByUser = isWhisper && ReportUtils.isCurrentUserTheOnlyParticipant(whisperedToAccountIDs); + const whisperedToPersonalDetails = isWhisper ? _.filter(props.personalDetails, (details) => _.includes(whisperedToAccountIDs, details.accountID)) : []; const displayNamesWithTooltips = isWhisper ? ReportUtils.getDisplayNamesWithTooltips(whisperedToPersonalDetails, isMultipleParticipant) : []; return ( Date: Wed, 28 Jun 2023 13:34:58 -0400 Subject: [PATCH 4/9] whisperedToAccountIDs propType should be array of numbers --- src/pages/home/report/reportActionPropTypes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/reportActionPropTypes.js b/src/pages/home/report/reportActionPropTypes.js index f66982fb5185..e0c3aebe718c 100644 --- a/src/pages/home/report/reportActionPropTypes.js +++ b/src/pages/home/report/reportActionPropTypes.js @@ -30,5 +30,5 @@ export default { error: PropTypes.string, /** accountIDs of the people to which the whisper was sent to (if any). Returns empty array if it is not a whisper */ - whisperedToAccountIDs: PropTypes.arrayOf(PropTypes.string), + whisperedToAccountIDs: PropTypes.arrayOf(PropTypes.number), }; From 8b8551e9b811faabe12402d5f2b87c66a7c82982 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Wed, 28 Jun 2023 16:45:00 -0400 Subject: [PATCH 5/9] User personalDetailsList instead of personalDetails --- src/pages/home/report/ReportActionItem.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 265876992a94..6c810973ad61 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -92,13 +92,13 @@ const propTypes = { preferredSkinTone: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), /** All of the personalDetails */ - personalDetails: PropTypes.objectOf(personalDetailsPropType), + personalDetailsList: PropTypes.objectOf(personalDetailsPropType), }; const defaultProps = { draftMessage: '', preferredSkinTone: CONST.EMOJI_DEFAULT_SKIN_TONE, - personalDetails: {}, + personalDetailsList: {}, shouldShowSubscriptAvatar: false, hasOutstandingIOU: false, }; @@ -441,7 +441,7 @@ function ReportActionItem(props) { const isWhisper = whisperedToAccountIDs.length > 0; const isMultipleParticipant = whisperedToAccountIDs.length > 1; const isWhisperOnlyVisibleByUser = isWhisper && ReportUtils.isCurrentUserTheOnlyParticipant(whisperedToAccountIDs); - const whisperedToPersonalDetails = isWhisper ? _.filter(props.personalDetails, (details) => _.includes(whisperedToAccountIDs, details.accountID)) : []; + const whisperedToPersonalDetails = isWhisper ? _.filter(props.personalDetailsList, (details) => _.includes(whisperedToAccountIDs, details.accountID)) : []; const displayNamesWithTooltips = isWhisper ? ReportUtils.getDisplayNamesWithTooltips(whisperedToPersonalDetails, isMultipleParticipant) : []; return ( Date: Thu, 29 Jun 2023 09:18:41 -0400 Subject: [PATCH 6/9] Update arg in getDisplayNamesWithTooltips from participants to personalDetailsList --- src/libs/ReportUtils.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 193355d5def0..aa3b0c9b00ff 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -858,17 +858,17 @@ function getDisplayNameForParticipant(accountID, shouldUseShortForm = false) { } /** - * @param {Object} participants + * @param {Object} personalDetailsList * @param {Boolean} isMultipleParticipantReport * @returns {Array} */ -function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport) { - return _.map(participants, (participant) => { - const accountID = Number(participant.accountID); - const displayName = getDisplayNameForParticipant(accountID, isMultipleParticipantReport) || participant.login; +function getDisplayNamesWithTooltips(personalDetailsList, isMultipleParticipantReport) { + return _.map(personalDetailsList, (user) => { + const accountID = Number(user.accountID); + const displayName = getDisplayNameForParticipant(accountID, isMultipleParticipantReport) || user.login || ''; const avatar = UserUtils.getDefaultAvatar(accountID); - let pronouns = participant.pronouns; + let pronouns = user.pronouns; if (pronouns && pronouns.startsWith(CONST.PRONOUNS.PREFIX)) { const pronounTranslationKey = pronouns.replace(CONST.PRONOUNS.PREFIX, ''); pronouns = Localize.translateLocal(`pronouns.${pronounTranslationKey}`); @@ -877,7 +877,7 @@ function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport) return { displayName, avatar, - login: participant.login, + login: user.login || '', accountID, pronouns, }; From 6e93a4a653379ec4a859a4b23300efbbb344bc43 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Thu, 29 Jun 2023 09:23:04 -0400 Subject: [PATCH 7/9] Get rid of duplicate sessionEmail and sessionAccountID --- src/libs/ReportUtils.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index aa3b0c9b00ff..ebfaecf172f4 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -21,8 +21,6 @@ import * as defaultWorkspaceAvatars from '../components/Icon/WorkspaceDefaultAva import * as CurrencyUtils from './CurrencyUtils'; import * as UserUtils from './UserUtils'; -let sessionEmail; -let sessionAccountID; let currentUserEmail; let currentUserAccountID; Onyx.connect({ @@ -33,8 +31,6 @@ Onyx.connect({ return; } - sessionEmail = val.email; - sessionAccountID = val.accountID; currentUserEmail = val.email; currentUserAccountID = val.accountID; }, @@ -200,7 +196,7 @@ function sortReportsByLastRead(reports) { */ function canEditReportAction(reportAction) { return ( - reportAction.actorEmail === sessionEmail && + reportAction.actorEmail === currentUserEmail && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !isReportMessageAttachment(lodashGet(reportAction, ['message', 0], {})) && !ReportActionsUtils.isDeletedAction(reportAction) && @@ -220,7 +216,7 @@ function canEditReportAction(reportAction) { */ function canFlagReportAction(reportAction) { return ( - reportAction.actorEmail !== sessionEmail && + reportAction.actorEmail !== currentUserEmail && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !ReportActionsUtils.isDeletedAction(reportAction) && !ReportActionsUtils.isCreatedTaskReportAction(reportAction) @@ -254,7 +250,7 @@ function canDeleteReportAction(reportAction, reportID) { ) { return false; } - if (reportAction.actorEmail === sessionEmail) { + if (reportAction.actorEmail === currentUserEmail) { return true; } const report = lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {}); @@ -1030,7 +1026,7 @@ function getReportName(report) { // Not a room or PolicyExpenseChat, generate title from participants const participants = (report && report.participantAccountIDs) || []; - const participantsWithoutCurrentUser = _.without(participants, sessionAccountID); + const participantsWithoutCurrentUser = _.without(participants, currentUserAccountID); const isMultipleParticipantReport = participantsWithoutCurrentUser.length > 1; return _.map(participantsWithoutCurrentUser, (accountID) => getDisplayNameForParticipant(accountID, isMultipleParticipantReport)).join(', '); @@ -2204,7 +2200,7 @@ function canLeaveRoom(report, isPolicyMember) { * @returns {Boolean} */ function isCurrentUserTheOnlyParticipant(participantAccountIDs) { - return participantAccountIDs && participantAccountIDs.length === 1 && participantAccountIDs[0] === sessionAccountID; + return participantAccountIDs && participantAccountIDs.length === 1 && participantAccountIDs[0] === currentUserAccountID; } /** From 6b0bdc9fa9361808a7c255d61720b664fdf8383d Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Wed, 28 Jun 2023 12:21:12 -0400 Subject: [PATCH 8/9] Fix proptypes in ArchivedReportFooter for accountIDs instead of logins --- src/components/ArchivedReportFooter.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/ArchivedReportFooter.js b/src/components/ArchivedReportFooter.js index a742b97fb0a9..1af8cadc80ca 100644 --- a/src/components/ArchivedReportFooter.js +++ b/src/components/ArchivedReportFooter.js @@ -22,11 +22,11 @@ const propTypes = { /** The reason the report was closed */ reason: PropTypes.string.isRequired, - /** (For accountMerged reason only), the email of the previous owner of this report. */ - oldLogin: PropTypes.string, + /** (For accountMerged reason only), the accountID of the previous owner of this report. */ + oldAccountID: PropTypes.number, - /** (For accountMerged reason only), the email of the account the previous owner was merged into */ - newLogin: PropTypes.string, + /** (For accountMerged reason only), the accountID of the account the previous owner was merged into */ + newLogin: PropTypes.number, }).isRequired, }), From 60dbc9c5411007259d5e9208f989be9cabbe6546 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Thu, 29 Jun 2023 17:26:42 -0400 Subject: [PATCH 9/9] Fix formatting issues --- src/libs/ReportUtils.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index a95d6331a3cb..2e5c39899e53 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2249,7 +2249,7 @@ function canLeaveRoom(report, isPolicyMember) { } /** - * @param {number[]} participantAccountIDs + * @param {Number[]} participantAccountIDs * @returns {Boolean} */ function isCurrentUserTheOnlyParticipant(participantAccountIDs) { @@ -2260,18 +2260,18 @@ function isCurrentUserTheOnlyParticipant(participantAccountIDs) { * Returns display names for those that can see the whisper. * However, it returns "you" if the current user is the only one who can see it besides the person that sent it. * - * @param {number[]} participantAccountIDs + * @param {Number[]} participantAccountIDs * @returns {string} */ function getWhisperDisplayNames(participantAccountIDs) { - const isWhisperOnlyVisibleToCurrentUSer = isCurrentUserTheOnlyParticipant(participantAccountIDs); + const isWhisperOnlyVisibleToCurrentUser = isCurrentUserTheOnlyParticipant(participantAccountIDs); // When the current user is the only participant, the display name needs to be "you" because that's the only person reading it - if (isWhisperOnlyVisibleToCurrentUSer) { + if (isWhisperOnlyVisibleToCurrentUser) { return Localize.translateLocal('common.youAfterPreposition'); } - return _.map(participantAccountIDs, (accountID) => getDisplayNameForParticipant(accountID, !isWhisperOnlyVisibleToCurrentUSer)).join(', '); + return _.map(participantAccountIDs, (accountID) => getDisplayNameForParticipant(accountID, !isWhisperOnlyVisibleToCurrentUser)).join(', '); } /**