Skip to content

Commit

Permalink
Merge pull request #8117 from sobitneupane/sn_bug-is-attachment
Browse files Browse the repository at this point in the history
Update isReportMessageAttachment logic
  • Loading branch information
Luke9389 authored Apr 5, 2022
2 parents e1bb9b4 + fc3c0bb commit 4b5abf6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,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 @@ -236,6 +236,7 @@ function getSimplifiedReportObject(report) {
oldPolicyName,
visibility,
isOwnPolicyExpenseChat: lodashGet(report, ['isOwnPolicyExpenseChat'], false),
lastMessageHtml: lastActionMessage,
};
}

Expand Down Expand Up @@ -629,7 +630,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
* @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 @@ -62,7 +62,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 @@ -72,7 +72,7 @@ export default [

const isAttachment = _.has(reportAction, 'isAttachment')
? reportAction.isAttachment
: ReportUtils.isReportMessageAttachment(text);
: ReportUtils.isReportMessageAttachment(message);
if (!isAttachment) {
Clipboard.setString(text);
} else {
Expand Down

0 comments on commit 4b5abf6

Please sign in to comment.