Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix workspace last message when a member is removed #8473

Merged
merged 10 commits into from
Apr 6, 2022
4 changes: 2 additions & 2 deletions src/components/ArchivedReportFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import withLocalize, {withLocalizePropTypes} from './withLocalize';
import compose from '../libs/compose';
import personalDetailsPropType from '../pages/personalDetailsPropType';
import ONYXKEYS from '../ONYXKEYS';
import * as ReportUtils from '../libs/reportUtils';

const propTypes = {
/** The reason this report was archived */
Expand Down Expand Up @@ -53,7 +54,6 @@ const defaultProps = {

const ArchivedReportFooter = (props) => {
const archiveReason = lodashGet(props.reportClosedAction, 'originalMessage.reason', CONST.REPORT.ARCHIVE_REASON.DEFAULT);
const policyName = lodashGet(props.policies, `${ONYXKEYS.COLLECTION.POLICY}${props.report.policyID}.name`);
let displayName = lodashGet(props.personalDetails, `${props.report.ownerEmail}.displayName`, props.report.ownerEmail);

let oldDisplayName;
Expand All @@ -69,7 +69,7 @@ const ArchivedReportFooter = (props) => {
text={props.translate(`reportArchiveReasons.${archiveReason}`, {
displayName: `<strong>${displayName}</strong>`,
oldDisplayName: `<strong>${oldDisplayName}</strong>`,
policyName: `<strong>${policyName}</strong>`,
policyName: `<strong>${ReportUtils.getPolicyName(props.report, props.policies)}</strong>`,
})}
shouldRenderHTML={archiveReason !== CONST.REPORT.ARCHIVE_REASON.DEFAULT}
/>
Expand Down
3 changes: 1 addition & 2 deletions src/components/ReportWelcomeText.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import withLocalize, {withLocalizePropTypes} from './withLocalize';
import compose from '../libs/compose';
import * as ReportUtils from '../libs/reportUtils';
import * as OptionsListUtils from '../libs/OptionsListUtils';
import * as Localize from '../libs/Localize';
import ONYXKEYS from '../ONYXKEYS';
import CONST from '../CONST';

Expand Down Expand Up @@ -91,7 +90,7 @@ const ReportWelcomeText = (props) => {
{props.translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo')}
</Text>
<Text style={[styles.textStrong]}>
{lodashGet(props.policies, [`${ONYXKEYS.COLLECTION.POLICY}${props.report.policyID}`, 'name'], Localize.translateLocal('workspace.common.unavailable'))}
{ReportUtils.getPolicyName(props.report, props.policies)}
</Text>
<Text>
{props.translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree')}
Expand Down
7 changes: 4 additions & 3 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ function createOption(personalDetailList, report, {
}) {
const isChatRoom = ReportUtils.isChatRoom(report);
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report);
const isArchivedRoom = ReportUtils.isArchivedRoom(report);
const hasMultipleParticipants = personalDetailList.length > 1 || isChatRoom || isPolicyExpenseChat;
const personalDetail = personalDetailList[0];
const hasDraftComment = hasReportDraftComment(report);
Expand All @@ -262,7 +263,7 @@ function createOption(personalDetailList, report, {
const lastMessageTextFromReport = ReportUtils.isReportMessageAttachment(lodashGet(report, 'lastMessageText', ''))
? `[${Localize.translateLocal('common.attachment')}]`
: Str.htmlDecode(lodashGet(report, 'lastMessageText', ''));
let lastMessageText = report && hasMultipleParticipants && lastActorDetails
let lastMessageText = report && !isArchivedRoom && hasMultipleParticipants && lastActorDetails
? `${lastActorDetails.displayName}: `
: '';
lastMessageText += report ? lastMessageTextFromReport : '';
Expand All @@ -273,7 +274,7 @@ function createOption(personalDetailList, report, {
let text;
let alternateText;
if (isChatRoom || isPolicyExpenseChat) {
text = lodashGet(report, ['reportName'], '');
text = (isArchivedRoom && report.isOwnPolicyExpenseChat) ? report.oldPolicyName : lodashGet(report, ['reportName'], '');
alternateText = (showChatPreviewLine && !forcePolicyNamePreview && lastMessageText)
? lastMessageText
: subtitle;
Expand Down Expand Up @@ -315,7 +316,7 @@ function createOption(personalDetailList, report, {
isIOUReportOwner: lodashGet(iouReport, 'ownerEmail', '') === currentUserLogin,
iouReportAmount: lodashGet(iouReport, 'total', 0),
isChatRoom,
isArchivedRoom: ReportUtils.isArchivedRoom(report),
isArchivedRoom,
shouldShowSubscript: isPolicyExpenseChat && !report.isOwnPolicyExpenseChat,
isPolicyExpenseChat,
};
Expand Down
33 changes: 19 additions & 14 deletions src/libs/reportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ function isArchivedRoom(report) {
return report.statusNum === CONST.REPORT.STATUS.CLOSED && report.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED;
}

/**
* Get the policy name from a given report
* @param {Object} report
* @param {String} report.policyID
* @param {String} report.oldPolicyName
* @param {Object} policies must have Onyxkey prefix (i.e 'policy_') for keys
* @returns {String}
*/
function getPolicyName(report, policies) {
const defaultValue = report.oldPolicyName || Localize.translateLocal('workspace.common.unavailable');
return lodashGet(policies, [`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'name'], defaultValue);
}

/**
* Get either the policyName or domainName the chat is tied to
* @param {Object} report
Expand All @@ -189,17 +202,13 @@ function getChatRoomSubtitle(report, policiesMap) {
// The domainAll rooms are just #domainName, so we ignore the prefix '#' to get the domainName
return report.reportName.substring(1);
}
if (isArchivedRoom(report)) {
return report.oldPolicyName;
}
if (isPolicyExpenseChat(report) && report.isOwnPolicyExpenseChat) {
return Localize.translateLocal('workspace.common.workspace');
}
return lodashGet(
policiesMap,
[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'name'],
Localize.translateLocal('workspace.common.unavailable'),
);
if (isArchivedRoom(report)) {
return report.oldPolicyName;
}
return getPolicyName(report, policiesMap);
}

/**
Expand All @@ -211,12 +220,7 @@ function getChatRoomSubtitle(report, policiesMap) {

function getRoomWelcomeMessage(report, policiesMap) {
const welcomeMessage = {};

const workspaceName = lodashGet(
policiesMap,
[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'name'],
Localize.translateLocal('workspace.common.unavailable'),
);
const workspaceName = getPolicyName(report, policiesMap);

if (isAdminRoom(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAdminRoomPartOne', {workspaceName});
Expand Down Expand Up @@ -314,6 +318,7 @@ export {
isUserCreatedPolicyRoom,
isChatRoom,
getChatRoomSubtitle,
getPolicyName,
isArchivedRoom,
isConciergeChatReport,
hasExpensifyEmails,
Expand Down