-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix user are able to flag their own comment #21771
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ import CONST from '../CONST'; | |
import * as ReportUtils from '../libs/ReportUtils'; | ||
import * as ReportActionsUtils from '../libs/ReportActionsUtils'; | ||
import * as Session from '../libs/actions/Session'; | ||
import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView'; | ||
import FullscreenLoadingIndicator from '../components/FullscreenLoadingIndicator'; | ||
|
||
const propTypes = { | ||
/** Array of report actions for this report */ | ||
|
@@ -39,12 +41,16 @@ const propTypes = { | |
}), | ||
}).isRequired, | ||
|
||
/** Indicates whether the report data is loading */ | ||
isLoadingReportData: PropTypes.bool, | ||
|
||
...withLocalizePropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
reportActions: {}, | ||
report: {}, | ||
isLoadingReportData: true, | ||
}; | ||
|
||
/** | ||
|
@@ -61,6 +67,11 @@ 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, | ||
|
@@ -118,7 +129,6 @@ function FlagCommentPage(props) { | |
// Handle threads if needed | ||
if (reportAction === undefined || reportAction.reportActionID === undefined) { | ||
reportID = ReportUtils.getParentReport(props.report).reportID; | ||
reportAction = ReportActionsUtils.getParentReportAction(props.report); | ||
} | ||
Report.flagComment(reportID, reportAction, severity); | ||
Navigation.dismissModal(); | ||
|
@@ -138,10 +148,15 @@ function FlagCommentPage(props) { | |
/> | ||
)); | ||
|
||
const shouldShowLoading = props.isLoadingReportData || props.report.isLoadingReportActions; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit concerned that we're using
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. We defined defaultProps for report is an empty object and that work as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was concerned about non-existent report, but I tested it shows up the invalid access page. Thanks for the patience here. |
||
if (shouldShowLoading) { | ||
return <FullscreenLoadingIndicator />; | ||
} | ||
Comment on lines
+152
to
+154
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dukenv0307 Why this code is needed? I couldn’t find any reference and it seems to be causing a regression in #23125 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fedirjh We need it to wait the report data and report action data are loaded completely before we should not found page or flag page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we remove this code, when we open the page by deep link or reload the page we will see page not found will display briefly before flag page is displayed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This approach will not work in offline mode. Instead, we should check if report is empty. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think updating the check to this will be fine
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This will not work in offline mode when we do something to make the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's continue the discussion on the linked issue #23125 |
||
|
||
return ( | ||
<ScreenWrapper includeSafeAreaPaddingBottom={false}> | ||
{({safeAreaPaddingBottomStyle}) => ( | ||
<> | ||
<FullPageNotFoundView shouldShow={!shouldShowLoading && !ReportUtils.shouldShowFlagComment(reportAction, props.report)}> | ||
<HeaderWithBackButton title={props.translate('reportActionContextMenu.flagAsOffensive')} /> | ||
<ScrollView | ||
contentContainerStyle={safeAreaPaddingBottomStyle} | ||
|
@@ -155,7 +170,7 @@ function FlagCommentPage(props) { | |
<Text style={[styles.ph5, styles.textLabelSupporting, styles.mb1]}>{props.translate('moderation.chooseAReason')}</Text> | ||
{severityMenuItems} | ||
</ScrollView> | ||
</> | ||
</FullPageNotFoundView> | ||
)} | ||
</ScreenWrapper> | ||
); | ||
|
@@ -175,5 +190,8 @@ export default compose( | |
report: { | ||
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportID(route)}`, | ||
}, | ||
isLoadingReportData: { | ||
key: ONYXKEYS.IS_LOADING_REPORT_DATA, | ||
}, | ||
}), | ||
)(FlagCommentPage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make any difference if we move this if block to
shouldShowFlagComment
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should get the correct reportAction here to pass it into
Report.flagComment
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay