Skip to content
Open
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
15 changes: 10 additions & 5 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10541,9 +10541,8 @@ function chatIncludesChronosWithID(reportOrID?: string | Report): boolean {
* - It's a welcome message whisper
* - It's an ADD_COMMENT that is not an attachment
*/
// TODO: currentUserAccountID will be required eventually so this becomes a pure function. Subscribe the data via useOnyx and pass it from the component. Refactor issue: https://github.com/Expensify/App/issues/66412
function canFlagReportAction(reportAction: OnyxInputOrEntry<ReportAction>, reportID: string | undefined, currentUserAccountID?: number): boolean {
const isCurrentUserAction = reportAction?.actorAccountID === (currentUserAccountID ?? deprecatedCurrentUserAccountID);
function canFlagReportAction(reportAction: OnyxInputOrEntry<ReportAction>, reportID: string | undefined, currentUserAccountID: number | undefined): boolean {
const isCurrentUserAction = reportAction?.actorAccountID === currentUserAccountID;
if (isWhisperAction(reportAction)) {
// Allow flagging whispers that are sent by other users
if (!isCurrentUserAction && reportAction?.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE) {
Expand Down Expand Up @@ -10576,9 +10575,15 @@ function canFlagReportAction(reportAction: OnyxInputOrEntry<ReportAction>, repor
/**
* Whether flag comment page should show
*/
function shouldShowFlagComment(reportAction: OnyxInputOrEntry<ReportAction>, report: OnyxInputOrEntry<Report>, conciergeReportID: string | undefined, isReportArchived = false): boolean {
function shouldShowFlagComment(
reportAction: OnyxInputOrEntry<ReportAction>,
report: OnyxInputOrEntry<Report>,
conciergeReportID: string | undefined,
isReportArchived: boolean,
currentUserAccountID: number | undefined,
): boolean {
return (
canFlagReportAction(reportAction, report?.reportID) &&
canFlagReportAction(reportAction, report?.reportID, currentUserAccountID) &&
!isArchivedNonExpenseReport(report, isReportArchived) &&
!chatIncludesChronos(report) &&
!isConciergeChatReport(report, conciergeReportID) &&
Expand Down
6 changes: 4 additions & 2 deletions src/pages/DynamicFlagCommentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import {useWideRHPState} from '@components/WideRHPContextProvider';

import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDynamicBackPath from '@hooks/useDynamicBackPath';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
Expand Down Expand Up @@ -52,6 +53,7 @@ type SeverityItemList = SeverityItem[];
function DynamicFlagCommentPage({parentReportAction, report, parentReport, reportAction}: DynamicFlagCommentPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
const backPath = useDynamicBackPath(DYNAMIC_ROUTES.FLAG_COMMENT.path);
const isReportArchived = useReportIsArchived(report?.reportID);
let reportID: string | undefined = report?.reportID;
Expand Down Expand Up @@ -119,7 +121,7 @@ function DynamicFlagCommentPage({parentReportAction, report, parentReport, repor
];

const flagComment = (severity: Severity) => {
if (reportAction && canFlagReportAction(reportAction, reportID)) {
if (reportAction && canFlagReportAction(reportAction, reportID, currentUserAccountID)) {
flagCommentUtil(reportAction, severity, originalReport, isOriginalReportArchived);
}

Expand Down Expand Up @@ -149,7 +151,7 @@ function DynamicFlagCommentPage({parentReportAction, report, parentReport, repor
testID="DynamicFlagCommentPage"
>
{({safeAreaPaddingBottomStyle}) => (
<FullPageNotFoundView shouldShow={!shouldShowFlagComment(reportAction, report, conciergeReportID, isReportArchived)}>
<FullPageNotFoundView shouldShow={!shouldShowFlagComment(reportAction, report, conciergeReportID, isReportArchived, currentUserAccountID)}>
<HeaderWithBackButton
title={translate('reportActionContextMenu.flagAsOffensive')}
onBackButtonPress={() => Navigation.goBack(backPath)}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1538,9 +1538,9 @@ const ContextMenuActions: ContextMenuAction[] = [
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.flagAsOffensive',
icon: 'Flag',
shouldShow: ({type, reportAction, isArchivedRoom, isChronosReport, reportID}) =>
shouldShow: ({type, reportAction, isArchivedRoom, isChronosReport, reportID, currentUserAccountID}) =>
type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION &&
canFlagReportAction(reportAction, reportID) &&
canFlagReportAction(reportAction, reportID, currentUserAccountID) &&
!isArchivedRoom &&
!isChronosReport &&
reportAction?.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE,
Expand Down
Loading
Loading