diff --git a/src/components/ArchivedReportFooter.js b/src/components/ArchivedReportFooter.js index a742b97fb0a9..d7a138d9a473 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 */ + newAccountID: PropTypes.number, }).isRequired, }), diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index dc8ad305fee0..61205f76d5a4 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -454,7 +454,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 97cbf184e795..2e5c39899e53 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; }, @@ -206,7 +202,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) && @@ -260,7 +256,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}`, {}); @@ -864,17 +860,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}`); @@ -883,7 +879,7 @@ function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport) return { displayName, avatar, - login: participant.login, + login: user.login || '', accountID, pronouns, }; @@ -1065,7 +1061,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(', '); @@ -2253,29 +2249,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] === currentUserAccountID; } /** * 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) { + 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 dbe48eb532dd..4286d788dd1b 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, }; @@ -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.personalDetailsList, (details) => _.includes(whisperedToAccountIDs, details.accountID)) : []; const displayNamesWithTooltips = isWhisper ? ReportUtils.getDisplayNamesWithTooltips(whisperedToPersonalDetails, isMultipleParticipant) : []; return (