Skip to content
Merged
8 changes: 4 additions & 4 deletions src/components/ArchivedReportFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),

Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ function isMessageDeleted(reportAction) {
}

function isWhisperAction(action) {
return (action.whisperedTo || []).length > 0;
return (action.whisperedToAccountIDs || []).length > 0;
}

export {
Expand Down
40 changes: 18 additions & 22 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -33,8 +31,6 @@ Onyx.connect({
return;
}

sessionEmail = val.email;
sessionAccountID = val.accountID;
currentUserEmail = val.email;
currentUserAccountID = val.accountID;
},
Expand Down Expand Up @@ -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) &&
Expand Down Expand Up @@ -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}`, {});
Expand Down Expand Up @@ -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}`);
Expand All @@ -883,7 +879,7 @@ function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport)
return {
displayName,
avatar,
login: participant.login,
login: user.login || '',
accountID,
pronouns,
};
Expand Down Expand Up @@ -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(', ');
Expand Down Expand Up @@ -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(', ');
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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) : [];
Comment thread
Beamanator marked this conversation as resolved.
return (
<PressableWithSecondaryInteraction
Expand Down Expand Up @@ -494,7 +494,7 @@ function ReportActionItem(props) {
&nbsp;
</Text>
<DisplayNames
fullTitle={ReportUtils.getWhisperDisplayNames(whisperedTo)}
fullTitle={ReportUtils.getWhisperDisplayNames(whisperedToAccountIDs)}
displayNamesWithTooltips={displayNamesWithTooltips}
tooltipEnabled
numberOfLines={1}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/reportActionPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ export default {
/** Error message that's come back from the server. */
error: PropTypes.string,

/** Emails of the people to which the whisper was sent to (if any). Returns empty array if it is not a whisper */
whisperedTo: PropTypes.arrayOf(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.number),
};
2 changes: 1 addition & 1 deletion tests/utils/LHNTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function getFakeReportAction(actor = 'email1@test.com', millisecondsInThePast =
text: 'Email One',
},
],
whisperedTo: [],
whisperedToAccountIDs: [],
automatic: false,
};
}
Expand Down