Skip to content

Commit

Permalink
Merge pull request #19405 from Expensify/dangrous-flagreportaction
Browse files Browse the repository at this point in the history
  • Loading branch information
thienlnam authored May 26, 2023
2 parents a479683 + a2b0689 commit 6f243fe
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,12 @@ const CONST = {
// This ID is used in SelectionScraper.js to query the DOM for UnreadActionIndicator's
// div and then remove it from copied contents in the getHTMLOfSelection() method.
UNREAD_ACTION_INDICATOR_ID: 'no-copy-area-unread-action-indicator',
MODERATION: {
MODERATOR_DECISION_PENDING: 'pending',
MODERATOR_DECISION_PENDING_HIDE: 'pendingHide',
FLAG_SEVERITY_SPAM: 'spam',
FLAG_SEVERITY_INCONSIDERATE: 'inconsiderate',
},
};

export default CONST;
76 changes: 76 additions & 0 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,81 @@ function leaveRoom(reportID) {
navigateToConciergeChat();
}

/**
* Flag a comment as offensive
*
* @param {String} reportID
* @param {Object} reportAction
* @param {String} severity
*/
function flagComment(reportID, reportAction, severity) {
let newDecision;
if (severity === CONST.MODERATION.FLAG_SEVERITY_SPAM || severity === CONST.MODERATION.FLAG_SEVERITY_INCONSIDERATE) {
newDecision = {
decision: CONST.MODERATION.MODERATOR_DECISION_PENDING,
};
} else {
newDecision = {
decision: CONST.MODERATION.MODERATOR_DECISION_PENDING_HIDE,
};
}

const message = reportAction.message[0];
const reportActionID = reportAction.reportActionID;

const updatedDecisions = [...(message.moderationDecisions || []), newDecision];

const updatedMessage = {
...message,
moderationDecisions: updatedDecisions,
};

const optimisticData = [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[reportActionID]: {
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
message: [updatedMessage],
},
},
},
];

const failureData = [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[reportActionID]: {
...reportAction,
pendingAction: null,
},
},
},
];

const successData = [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[reportActionID]: {
pendingAction: null,
},
},
},
];

const parameters = {
severity,
reportActionID,
};

API.write('FlagComment', parameters, {optimisticData, successData, failureData});
}

export {
addComment,
addAttachment,
Expand Down Expand Up @@ -1721,4 +1796,5 @@ export {
hasAccountIDReacted,
shouldShowReportActionNotification,
leaveRoom,
flagComment,
};

0 comments on commit 6f243fe

Please sign in to comment.