diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index fc031cab5748..49c4767e4d5e 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -386,10 +386,15 @@ function getLastMessageTextForReport(report) { } else { lastMessageTextFromReport = report ? report.lastMessageText || '' : ''; - // Yeah this is a bit ugly. If the latest report action that is not a whisper has been moderated as pending remove, then set the last message text to the text of the latest visible action that is not a whisper. + // Yeah this is a bit ugly. If the latest report action that is not a whisper has been moderated as pending remove + // then set the last message text to the text of the latest visible action that is not a whisper or the report creation message. const lastNonWhisper = _.find(allSortedReportActions[report.reportID], (action) => !ReportActionUtils.isWhisperAction(action)) || {}; if (ReportActionUtils.isPendingRemove(lastNonWhisper)) { - const latestVisibleAction = _.find(allSortedReportActions[report.reportID], (action) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(action)) || {}; + const latestVisibleAction = + _.find( + allSortedReportActions[report.reportID], + (action) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(action) && !ReportActionUtils.isCreatedAction(action), + ) || {}; lastMessageTextFromReport = lodashGet(latestVisibleAction, 'message[0].text', ''); } } diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index e4cc6ced62ec..b525ffadd258 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -66,7 +66,7 @@ function isDeletedAction(reportAction) { * @returns {Boolean} */ function isPendingRemove(reportAction) { - return lodashGet(reportAction, 'message[0].moderationDecisions[0].decision') === CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE; + return lodashGet(reportAction, 'message[0].moderationDecision.decision') === CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE; } /** @@ -556,6 +556,7 @@ export { getLastVisibleMessage, getMostRecentIOURequestActionID, extractLinksFromMessageHtml, + isCreatedAction, isDeletedAction, shouldReportActionBeVisible, shouldReportActionBeVisibleAsLastAction, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index e4a6b801db57..3b4df83c56a9 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1246,8 +1246,8 @@ function getReportName(report, policy = undefined) { return `[${Localize.translateLocal('common.attachment')}]`; } if ( - lodashGet(parentReportAction, 'message[0].moderationDecisions[0].decision') === CONST.MODERATION.MODERATOR_DECISION_PENDING_HIDE || - lodashGet(parentReportAction, 'message[0].moderationDecisions[0].decision') === CONST.MODERATION.MODERATOR_DECISION_HIDDEN + lodashGet(parentReportAction, 'message[0].moderationDecision.decision') === CONST.MODERATION.MODERATOR_DECISION_PENDING_HIDE || + lodashGet(parentReportAction, 'message[0].moderationDecision.decision') === CONST.MODERATION.MODERATOR_DECISION_HIDDEN ) { return Localize.translateLocal('parentReportAction.hiddenMessage'); } diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 726fd736eb7f..103628411c15 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1789,32 +1789,28 @@ function flagComment(reportID, reportAction, severity) { const message = reportAction.message[0]; let updatedDecision; if (severity === CONST.MODERATION.FLAG_SEVERITY_SPAM || severity === CONST.MODERATION.FLAG_SEVERITY_INCONSIDERATE) { - if (_.isEmpty(message.moderationDecisions) || message.moderationDecisions[message.moderationDecisions.length - 1].decision !== CONST.MODERATION.MODERATOR_DECISION_PENDING_HIDE) { - updatedDecision = [ - { - decision: CONST.MODERATION.MODERATOR_DECISION_PENDING, - }, - ]; + if (!message.moderationDecision) { + updatedDecision = { + decision: CONST.MODERATION.MODERATOR_DECISION_PENDING, + }; + } else { + updatedDecision = message.moderationDecision; } } else if (severity === CONST.MODERATION.FLAG_SEVERITY_ASSAULT || severity === CONST.MODERATION.FLAG_SEVERITY_HARASSMENT) { - updatedDecision = [ - { - decision: CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE, - }, - ]; + updatedDecision = { + decision: CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE, + }; } else { - updatedDecision = [ - { - decision: CONST.MODERATION.MODERATOR_DECISION_PENDING_HIDE, - }, - ]; + updatedDecision = { + decision: CONST.MODERATION.MODERATOR_DECISION_PENDING_HIDE, + }; } const reportActionID = reportAction.reportActionID; const updatedMessage = { ...message, - moderationDecisions: updatedDecision, + moderationDecision: updatedDecision, }; const optimisticData = [ diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 259502a9eff9..8114f3776acc 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -162,8 +162,7 @@ function ReportActionItem(props) { // Hide the message if it is being moderated for a higher offense, or is hidden by a moderator // Removed messages should not be shown anyway and should not need this flow - const decisions = lodashGet(props, ['action', 'message', 0, 'moderationDecisions'], []); - const latestDecision = lodashGet(_.last(decisions), 'decision', ''); + const latestDecision = lodashGet(props, ['action', 'message', 0, 'moderationDecision', 'decision'], ''); useEffect(() => { if (props.action.actionName !== CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT) { return; diff --git a/src/pages/home/sidebar/SidebarLinksData.js b/src/pages/home/sidebar/SidebarLinksData.js index 8c208ee82611..9f8f5bd74e7d 100644 --- a/src/pages/home/sidebar/SidebarLinksData.js +++ b/src/pages/home/sidebar/SidebarLinksData.js @@ -30,11 +30,9 @@ const propTypes = { error: PropTypes.string, message: PropTypes.arrayOf( PropTypes.shape({ - moderationDecisions: PropTypes.arrayOf( - PropTypes.shape({ - decision: PropTypes.string, - }), - ), + moderationDecision: PropTypes.shape({ + decision: PropTypes.string, + }), }), ), }), @@ -155,7 +153,7 @@ const reportActionsSelector = (reportActions) => errors: reportAction.errors, message: [ { - moderationDecisions: [{decision: lodashGet(reportAction, 'message[0].moderationDecisions[0].decision')}], + moderationDecision: {decision: lodashGet(reportAction, 'message[0].moderationDecision.decision')}, }, ], }));