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

Update isReportMessageAttachment logic #8117

Merged
merged 6 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function createOption(personalDetailList, report, {
: {};

const lastActorDetails = report ? _.find(personalDetailList, {login: report.lastActorEmail}) : null;
const lastMessageTextFromReport = ReportUtils.isReportMessageAttachment(lodashGet(report, 'lastMessageText', ''))
const lastMessageTextFromReport = ReportUtils.isReportMessageAttachment({text: lodashGet(report, 'lastMessageText', ''), html: lodashGet(report, 'lastMessageHtml', '')})
? `[${Localize.translateLocal('common.attachment')}]`
: Str.htmlDecode(lodashGet(report, 'lastMessageText', ''));
let lastMessageText = report && hasMultipleParticipants && lastActorDetails
Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ function getSimplifiedReportObject(report) {
oldPolicyName,
visibility,
isOwnPolicyExpenseChat: lodashGet(report, ['isOwnPolicyExpenseChat'], false),
lastMessageHtml: lastActionMessage,
};
}

Expand Down Expand Up @@ -628,7 +629,7 @@ function updateReportWithNewAction(
// Add the action into Onyx
reportActionsToMerge[reportAction.sequenceNumber] = {
...reportAction,
isAttachment: ReportUtils.isReportMessageAttachment(messageText),
isAttachment: ReportUtils.isReportMessageAttachment(lodashGet(reportAction, ['message', 0], {})),
loading: false,
};

Expand Down
11 changes: 6 additions & 5 deletions src/libs/reportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ function getReportParticipantsTitle(logins) {
}

/**
* Check whether a report action is Attachment is not.
* Check whether a report action is Attachment or not.
* Ignore messages containing [Attachment] as the main content. Attachments are actions with only text as [Attachment].
*
* @param {Object} reportMessageText report action's message as text
* @param {Object} reportActionMessage report action's message as text and html
sobitneupane marked this conversation as resolved.
Show resolved Hide resolved
* @returns {Boolean}
*/
function isReportMessageAttachment(reportMessageText) {
return reportMessageText === '[Attachment]';
function isReportMessageAttachment({text, html}) {
return text === '[Attachment]' && html !== '[Attachment]';
}

/**
Expand Down Expand Up @@ -60,7 +61,7 @@ function canEditReportAction(reportAction) {
return reportAction.actorEmail === sessionEmail
&& reportAction.reportActionID
&& reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT
&& !isReportMessageAttachment(lodashGet(reportAction, ['message', 0, 'text'], ''));
&& !isReportMessageAttachment(lodashGet(reportAction, ['message', 0], {}));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default [
// `ContextMenuItem` with `successText` and `successIcon` which will fallback to
// the `text` and `icon`
onPress: (closePopover, {reportAction, selection}) => {
const message = _.last(lodashGet(reportAction, 'message', null));
const message = _.last(lodashGet(reportAction, 'message', [{}]));
const html = lodashGet(message, 'html', '');

const parser = new ExpensiMark();
Expand All @@ -58,7 +58,7 @@ export default [

const isAttachment = _.has(reportAction, 'isAttachment')
? reportAction.isAttachment
: ReportUtils.isReportMessageAttachment(text);
: ReportUtils.isReportMessageAttachment(message);
sobitneupane marked this conversation as resolved.
Show resolved Hide resolved
if (!isAttachment) {
Clipboard.setString(text);
} else {
Expand Down