From feedc0072047a3982f2c3b9c778a1dc120bd571e Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Thu, 13 Jul 2023 17:35:47 -0500 Subject: [PATCH 1/6] first pass --- src/libs/ReportActionsUtils.js | 2 +- src/libs/actions/Report.js | 28 +++++++++-------------- src/pages/home/report/ReportActionItem.js | 3 +-- src/pages/home/sidebar/SidebarLinks.js | 10 ++++---- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index d34c918a0f2d..04243cab0481 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; } /** diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index c403ec0e9b28..2c6d0f50150e 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1823,32 +1823,26 @@ 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 || message.moderationDecision.decision !== CONST.MODERATION.MODERATOR_DECISION_PENDING_HIDE) { + updatedDecision = { + decision: CONST.MODERATION.MODERATOR_DECISION_PENDING, + }; } } 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 0b2565f122d7..89fc6321ffcf 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -153,8 +153,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 || _.isEmpty(latestDecision)) { return; diff --git a/src/pages/home/sidebar/SidebarLinks.js b/src/pages/home/sidebar/SidebarLinks.js index 4142334d1be2..822820a0a632 100644 --- a/src/pages/home/sidebar/SidebarLinks.js +++ b/src/pages/home/sidebar/SidebarLinks.js @@ -60,11 +60,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, + }), }), ), }), @@ -335,7 +333,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')}, }, ], })); From 74b58458a547cf83955ca8fc8224d0bb7fae4132 Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Fri, 21 Jul 2023 10:26:00 -0400 Subject: [PATCH 2/6] better fix merge conflicts whoops --- src/pages/home/sidebar/SidebarLinksData.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/pages/home/sidebar/SidebarLinksData.js b/src/pages/home/sidebar/SidebarLinksData.js index a051e7e33ca7..8e0b86e4ac52 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, + }), }), ), }), @@ -154,7 +152,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')}, }, ], })); From 488314a7ee0bb8e3e3022ee5cd4cb7e43f715923 Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Fri, 21 Jul 2023 10:30:08 -0400 Subject: [PATCH 3/6] catch one more instance of moderationDecisions --- src/libs/ReportUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 764699947a97..9e7ca65a0d83 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1143,8 +1143,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'); } From b51202ffaa84fe1db3502c6b6a245174a25f5183 Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Mon, 24 Jul 2023 13:12:54 -0400 Subject: [PATCH 4/6] always set a moderationDecision --- src/libs/actions/Report.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 365ae7013d15..1727cf9a0570 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1773,10 +1773,12 @@ 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 (!message.moderationDecision || message.moderationDecision.decision !== CONST.MODERATION.MODERATOR_DECISION_PENDING_HIDE) { + 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 = { From 83733772038ee8ba1304c92ef37a9c4cf254c003 Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Tue, 25 Jul 2023 12:36:28 -0400 Subject: [PATCH 5/6] fix __FAKE__ in LHN --- src/libs/OptionsListUtils.js | 8 ++++++-- src/libs/ReportActionsUtils.js | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 2acb1f51cbe7..5db960356978 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -406,13 +406,17 @@ 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.shouldReportActionBeVisible(action, action.reportActionID) && !ReportActionUtils.isWhisperAction(action), + (action) => + ReportActionUtils.shouldReportActionBeVisible(action, action.reportActionID) && + !ReportActionUtils.isWhisperAction(action) && + !ReportActionUtils.isCreatedAction(action), ) || {}; lastMessageTextFromReport = lodashGet(latestVisibleAction, 'message[0].text', ''); } diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index bbe072b0b109..5f0fba99f26a 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -545,6 +545,7 @@ export { getLastVisibleMessage, getMostRecentIOURequestActionID, extractLinksFromMessageHtml, + isCreatedAction, isDeletedAction, shouldReportActionBeVisible, isReportActionDeprecated, From 189358b590f9ba4d97c40bf6e820dcca2428d48a Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Wed, 26 Jul 2023 11:53:09 -0400 Subject: [PATCH 6/6] prettier --- src/libs/OptionsListUtils.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 3cbef9c7b683..49c4767e4d5e 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -390,7 +390,11 @@ function getLastMessageTextForReport(report) { // 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) && !ReportActionUtils.isCreatedAction(action)) || {}; + const latestVisibleAction = + _.find( + allSortedReportActions[report.reportID], + (action) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(action) && !ReportActionUtils.isCreatedAction(action), + ) || {}; lastMessageTextFromReport = lodashGet(latestVisibleAction, 'message[0].text', ''); } }