Skip to content

Commit

Permalink
Merge pull request #22852 from Expensify/dangrous-objectmoderationdec…
Browse files Browse the repository at this point in the history
…isionnotarray
  • Loading branch information
thienlnam authored Jul 27, 2023
2 parents 1d8f5fd + 189358b commit 190f759
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
9 changes: 7 additions & 2 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function isDeletedParentAction(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;
}

/**
Expand Down Expand Up @@ -567,6 +567,7 @@ export {
getLastVisibleMessage,
getMostRecentIOURequestActionID,
extractLinksFromMessageHtml,
isCreatedAction,
isDeletedAction,
shouldReportActionBeVisible,
shouldReportActionBeVisibleAsLastAction,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1254,8 +1254,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');
}
Expand Down
30 changes: 13 additions & 17 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1790,32 +1790,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 = [
Expand Down
3 changes: 1 addition & 2 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions src/pages/home/sidebar/SidebarLinksData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
}),
),
}),
Expand Down Expand Up @@ -155,7 +153,7 @@ const reportActionsSelector = (reportActions) =>
errors: lodashGet(reportAction, 'errors', []),
message: [
{
moderationDecisions: [{decision: lodashGet(reportAction, 'message[0].moderationDecisions[0].decision')}],
moderationDecision: {decision: lodashGet(reportAction, 'message[0].moderationDecision.decision')},
},
],
}));
Expand Down

0 comments on commit 190f759

Please sign in to comment.