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

Silently fail flagComment request if reportAction has been deleted #22831

Merged
merged 4 commits into from
Jul 18, 2023
Merged
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
30 changes: 20 additions & 10 deletions src/pages/FlagCommentPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useCallback} from 'react';
import _ from 'underscore';
import {View, ScrollView} from 'react-native';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -66,12 +66,6 @@ function getReportID(route) {
}

function FlagCommentPage(props) {
let reportAction = props.reportActions[`${props.route.params.reportActionID.toString()}`];

// Handle threads if needed
if (reportAction === undefined || reportAction.reportActionID === undefined) {
reportAction = ReportActionsUtils.getParentReportAction(props.report);
}
const severities = [
{
severity: CONST.MODERATION.FLAG_SEVERITY_SPAM,
Expand Down Expand Up @@ -123,14 +117,30 @@ function FlagCommentPage(props) {
},
];

const getActionToFlag = useCallback(() => {
let reportAction = props.reportActions[`${props.route.params.reportActionID.toString()}`];

// Handle threads if needed
if (reportAction === undefined || reportAction.reportActionID === undefined) {
reportAction = ReportActionsUtils.getParentReportAction(props.report);
}

return reportAction;
}, [props.report, props.reportActions, props.route.params.reportActionID]);

const flagComment = (severity) => {
let reportID = getReportID(props.route);
const reportAction = getActionToFlag();

// Handle threads if needed
if (reportAction === undefined || reportAction.reportActionID === undefined) {
if (ReportUtils.isChatThread(props.report) && reportAction.reportActionID === ReportActionsUtils.getParentReportAction(props.report).reportActionID) {
reportID = ReportUtils.getParentReport(props.report).reportID;
}
Report.flagComment(reportID, reportAction, severity);

if (ReportUtils.canFlagReportAction(reportAction, reportID)) {
Report.flagComment(reportID, reportAction, severity);
}

Navigation.dismissModal();
};

Expand All @@ -155,7 +165,7 @@ function FlagCommentPage(props) {
return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
{({safeAreaPaddingBottomStyle}) => (
<FullPageNotFoundView shouldShow={!shouldShowLoading && !ReportUtils.shouldShowFlagComment(reportAction, props.report)}>
<FullPageNotFoundView shouldShow={!shouldShowLoading && !ReportUtils.shouldShowFlagComment(getActionToFlag(), props.report)}>
<HeaderWithBackButton title={props.translate('reportActionContextMenu.flagAsOffensive')} />
<ScrollView
contentContainerStyle={safeAreaPaddingBottomStyle}
Expand Down
Loading