From bc84c8e7c7dfbd71ada02ac0f853cc181bb05d60 Mon Sep 17 00:00:00 2001
From: dukenv0307 <dukenv0307@gmail.com>
Date: Wed, 28 Jun 2023 10:39:28 +0700
Subject: [PATCH 1/2] Fix user are able to flag their own comment

---
 src/libs/ReportUtils.js      | 27 ++++++++++++++++++++++++++-
 src/pages/FlagCommentPage.js | 24 +++++++++++++++++++++---
 2 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js
index 83fae8287c74..b2a3d411800e 100644
--- a/src/libs/ReportUtils.js
+++ b/src/libs/ReportUtils.js
@@ -40,6 +40,12 @@ Onyx.connect({
     },
 });
 
+let loginList;
+Onyx.connect({
+    key: ONYXKEYS.LOGIN_LIST,
+    callback: (val) => (loginList = _.isEmpty(val) ? [] : _.keys(val)),
+});
+
 let preferredLocale = CONST.LOCALES.DEFAULT;
 Onyx.connect({
     key: ONYXKEYS.NVP_PREFERRED_LOCALE,
@@ -220,7 +226,7 @@ function canEditReportAction(reportAction) {
  */
 function canFlagReportAction(reportAction) {
     return (
-        reportAction.actorEmail !== sessionEmail &&
+        !loginList.includes(reportAction.actorEmail) &&
         reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT &&
         !ReportActionsUtils.isDeletedAction(reportAction) &&
         !ReportActionsUtils.isCreatedTaskReportAction(reportAction)
@@ -2029,6 +2035,24 @@ function chatIncludesChronos(report) {
     return report.participantAccountIDs && _.contains(report.participantAccountIDs, CONST.ACCOUNT_ID.CHRONOS);
 }
 
+/**
+ * Whether flag comment page should show
+ *
+ * @param {Object} reportAction
+ * @param {Object} report
+ * @returns {Boolean}
+ */
+
+function shouldShowFlagComment(reportAction, report) {
+    return (
+        canFlagReportAction(reportAction) &&
+        !isArchivedRoom(report) &&
+        !chatIncludesChronos(report) &&
+        !isConciergeChatReport(report.reportID) &&
+        reportAction.actorEmail !== CONST.EMAIL.CONCIERGE
+    );
+}
+
 /**
  * @param {Object} report
  * @param {String} report.lastReadTime
@@ -2275,6 +2299,7 @@ export {
     findLastAccessedReport,
     canEditReportAction,
     canFlagReportAction,
+    shouldShowFlagComment,
     canDeleteReportAction,
     canLeaveRoom,
     sortReportsByLastRead,
diff --git a/src/pages/FlagCommentPage.js b/src/pages/FlagCommentPage.js
index 568f6073a76e..adfe869ce7fb 100644
--- a/src/pages/FlagCommentPage.js
+++ b/src/pages/FlagCommentPage.js
@@ -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,
 
+    /** Indicated 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;
+    if (shouldShowLoading) {
+        return <FullscreenLoadingIndicator />;
+    }
+
     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);

From 83536969cd2d2721a6ee90b69fca08980424ff62 Mon Sep 17 00:00:00 2001
From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com>
Date: Thu, 29 Jun 2023 01:31:17 +0700
Subject: [PATCH 2/2] Update src/pages/FlagCommentPage.js

Co-authored-by: Manan <manan.jadhav@gmail.com>
---
 src/pages/FlagCommentPage.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/pages/FlagCommentPage.js b/src/pages/FlagCommentPage.js
index adfe869ce7fb..4c602f15c5fd 100644
--- a/src/pages/FlagCommentPage.js
+++ b/src/pages/FlagCommentPage.js
@@ -41,7 +41,7 @@ const propTypes = {
         }),
     }).isRequired,
 
-    /** Indicated whether the report data is loading */
+    /** Indicates whether the report data is loading */
     isLoadingReportData: PropTypes.bool,
 
     ...withLocalizePropTypes,