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

Use a single moderationDecision instead of the moderationDecisions array #22852

Merged
merged 9 commits into from
Jul 27, 2023
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
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 @@ -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;
}

/**
Expand Down Expand Up @@ -556,6 +556,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 @@ -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');
}
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 @@ -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 = [
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: reportAction.errors,
message: [
{
moderationDecisions: [{decision: lodashGet(reportAction, 'message[0].moderationDecisions[0].decision')}],
moderationDecision: {decision: lodashGet(reportAction, 'message[0].moderationDecision.decision')},
},
],
}));
Expand Down