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

Check if policy room is archived because of merging #14779

Merged
merged 16 commits into from
Feb 8, 2023
Merged
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ const CONST = {
AFTER_FIRST_LINE_BREAK: /\n.*/g,
CODE_2FA: /^\d{6}$/,
ATTACHMENT_ID: /chat-attachments\/(\d+)/,
MERGED_ACCOUNT_PREFIX: /^(MERGED_\d+@)/,
},

PRONOUNS: {
Expand Down
5 changes: 3 additions & 2 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import moment from 'moment';
import * as CollectionUtils from './CollectionUtils';
import CONST from '../CONST';
import ONYXKEYS from '../ONYXKEYS';
import * as ReportUtils from './ReportUtils';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to resolve a cyclic dependency between these two utility libraries


const allReportActions = {};
Onyx.connect({
Expand Down Expand Up @@ -170,7 +169,9 @@ function getLastVisibleMessageText(reportID, actionsToMerge = {}) {

const parser = new ExpensiMark();
const messageText = parser.htmlToText(htmlText);
return ReportUtils.formatReportLastMessageText(messageText);
return String(messageText)
.replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '')
.substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH);
}

export {
Expand Down
39 changes: 36 additions & 3 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Navigation from './Navigation/Navigation';
import ROUTES from '../ROUTES';
import * as NumberUtils from './NumberUtils';
import * as NumberFormatUtils from './NumberFormatUtils';
import * as ReportActionsUtils from './ReportActionsUtils';
import Permissions from './Permissions';
import DateUtils from './DateUtils';
import linkingConfig from './Navigation/linkingConfig';
Expand Down Expand Up @@ -72,7 +73,7 @@ let doesDomainHaveApprovedAccountant;
Onyx.connect({
key: ONYXKEYS.ACCOUNT,
waitForCollectionCallback: true,
callback: val => doesDomainHaveApprovedAccountant = val.doesDomainHaveApprovedAccountant,
callback: val => doesDomainHaveApprovedAccountant = val.doesDomainHaveApprovedAccountant || false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been running to this value not being defined locally and causing the app not to load so casting this to false in case val is not defined helped. Should be no harm in this change

});

function getChatType(report) {
Expand Down Expand Up @@ -654,6 +655,39 @@ function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport)
});
}

/**
* Get the title for a policy expense chat which depends on the role of the policy member seeing this report
*
* @param {Object} report
* @param {Object} [policies]
* @returns {String}
*/
function getPolicyExpenseChatName(report, policies = {}) {
const reportOwnerDisplayName = getDisplayNameForParticipant(report.ownerEmail) || report.ownerEmail || report.reportName;

// If the policy expense chat is owned by this user, use the name of the policy as the report name.
if (report.isOwnPolicyExpenseChat) {
return getPolicyName(report, policies);
}

const policyExpenseChatRole = lodashGet(policies, [
`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'role',
]) || 'user';

// If this user is not admin and this policy expense chat has been archived because of account merging, this must be an old workspace chat
// of the account which was merged into the current user's account. Use the name of the policy as the name of the report.
if (isArchivedRoom(report)) {
const lastAction = ReportActionsUtils.getLastVisibleAction(report.reportID);
const archiveReason = (lastAction && lastAction.originalMessage && lastAction.originalMessage.reason) || CONST.REPORT.ARCHIVE_REASON.DEFAULT;
if (archiveReason === CONST.REPORT.ARCHIVE_REASON.ACCOUNT_MERGED && policyExpenseChatRole !== CONST.POLICY.ROLE.ADMIN) {
return getPolicyName(report, policies);
}
}

// If user can see this report and they are not its owner, they must be an admin and the report name should be the name of the policy member
return reportOwnerDisplayName;
}

/**
* Get the title for a report.
*
Expand All @@ -668,8 +702,7 @@ function getReportName(report, policies = {}) {
}

if (isPolicyExpenseChat(report)) {
const reportOwnerDisplayName = getDisplayNameForParticipant(report.ownerEmail) || report.ownerEmail || report.reportName;
formattedName = report.isOwnPolicyExpenseChat ? getPolicyName(report, policies) : reportOwnerDisplayName;
formattedName = getPolicyExpenseChatName(report, policies);
}

if (isArchivedRoom(report)) {
Expand Down
14 changes: 8 additions & 6 deletions src/pages/home/report/ReportActionItemSingle.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Tooltip from '../../../components/Tooltip';
import ControlSelection from '../../../libs/ControlSelection';
import * as ReportUtils from '../../../libs/ReportUtils';
import OfflineWithFeedback from '../../../components/OfflineWithFeedback';
import CONST from '../../../CONST';

const propTypes = {
/** All the data of the action */
Expand Down Expand Up @@ -51,13 +52,14 @@ const showUserDetails = (email) => {
};

const ReportActionItemSingle = (props) => {
const actorEmail = props.action.actorEmail.replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not directly related, but we should have created a utility function that did this replacement. Later on, at some places we forgot to do this replacement which caused #32127.

const {
avatar,
displayName,
login,
pendingFields,
} = props.personalDetails[props.action.actorEmail] || {};
const avatarSource = ReportUtils.getAvatar(avatar, props.action.actorEmail);
} = props.personalDetails[actorEmail] || {};
const avatarSource = ReportUtils.getAvatar(avatar, actorEmail);

// Since the display name for a report action message is delivered with the report history as an array of fragments
// we'll need to take the displayName from personal details and have it be in the same format for now. Eventually,
Expand All @@ -72,9 +74,9 @@ const ReportActionItemSingle = (props) => {
style={[styles.alignSelfStart, styles.mr3]}
onPressIn={ControlSelection.block}
onPressOut={ControlSelection.unblock}
onPress={() => showUserDetails(props.action.actorEmail)}
onPress={() => showUserDetails(actorEmail)}
>
<Tooltip text={props.action.actorEmail}>
<Tooltip text={actorEmail}>
<OfflineWithFeedback
pendingAction={lodashGet(pendingFields, 'avatar', null)}
>
Expand All @@ -92,13 +94,13 @@ const ReportActionItemSingle = (props) => {
style={[styles.flexShrink1, styles.mr1]}
onPressIn={ControlSelection.block}
onPressOut={ControlSelection.unblock}
onPress={() => showUserDetails(props.action.actorEmail)}
onPress={() => showUserDetails(actorEmail)}
>
{_.map(personArray, (fragment, index) => (
<ReportActionItemFragment
key={`person-${props.action.reportActionID}-${index}`}
fragment={fragment}
tooltipText={props.action.actorEmail}
tooltipText={actorEmail}
isAttachment={props.action.isAttachment}
isLoading={props.action.isLoading}
isSingleLine
Expand Down
Loading