Skip to content
Draft
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
18 changes: 8 additions & 10 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
type MemberChangeMessageElement = MessageTextElement | MemberChangeMessageUserMentionElement | MemberChangeMessageRoomReferenceElement;

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 63 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -72,7 +72,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 75 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -81,14 +81,13 @@
});

let isNetworkOffline = false;
Onyx.connect({

Check warning on line 84 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NETWORK,
callback: (val) => (isNetworkOffline = val?.isOffline ?? false),
});

let currentUserAccountID: number | undefined;
let currentEmail = '';
let deprecatedCurrentUserAccountID: number | undefined;
Onyx.connect({

Check warning on line 90 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, value is undefined
Expand All @@ -96,8 +95,7 @@
return;
}

currentUserAccountID = value.accountID;
currentEmail = value?.email ?? '';
deprecatedCurrentUserAccountID = value.accountID;
},
});

Expand Down Expand Up @@ -381,7 +379,7 @@
if (!isWhisperAction(reportAction)) {
return false;
}
return !getWhisperedTo(reportAction).includes(currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID);
return !getWhisperedTo(reportAction).includes(deprecatedCurrentUserAccountID ?? CONST.DEFAULT_NUMBER_ID);
}

function isReimbursementQueuedAction(reportAction: OnyxInputOrEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_QUEUED> {
Expand Down Expand Up @@ -2151,18 +2149,18 @@
return matches.map((match) => Str.removeSMSDomain(match[1].substring(1)));
}

function didMessageMentionCurrentUser(reportAction: OnyxInputOrEntry<ReportAction>) {
function didMessageMentionCurrentUser(reportAction: OnyxInputOrEntry<ReportAction>, currentUserEmail: string) {
const accountIDsFromMessage = getMentionedAccountIDsFromAction(reportAction);
const message = getReportActionMessage(reportAction)?.html ?? '';
const emailsFromMessage = getMentionedEmailsFromMessage(message);
return accountIDsFromMessage.includes(currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID) || emailsFromMessage.includes(currentEmail) || message.includes('<mention-here>');
return accountIDsFromMessage.includes(deprecatedCurrentUserAccountID ?? CONST.DEFAULT_NUMBER_ID) || emailsFromMessage.includes(currentUserEmail) || message.includes('<mention-here>');
}

/**
* Check if the current user is the requestor of the action
*/
function wasActionTakenByCurrentUser(reportAction: OnyxInputOrEntry<ReportAction>): boolean {
return currentUserAccountID === reportAction?.actorAccountID;
return deprecatedCurrentUserAccountID === reportAction?.actorAccountID;
}

/**
Expand Down Expand Up @@ -3257,7 +3255,7 @@
const originalMessage = getOriginalMessage(reportAction);
const submittersNames = getPersonalDetailsByIDs({
accountIDs: originalMessage?.submittersAccountIDs ?? [],
currentUserAccountID: currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
currentUserAccountID: deprecatedCurrentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
}).map(({displayName, login}) => displayName ?? login ?? 'Unknown Submitter');
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('workspaceActions.removedFromApprovalWorkflow', {submittersNames, count: submittersNames.length});
Expand Down Expand Up @@ -3431,7 +3429,7 @@
const isExpensifyCardActive = isCardActive(expensifyCard);
const expensifyCardLink = (expensifyCardLinkText: string) =>
shouldRenderHTML && isExpensifyCardActive ? `<a href='${environmentURL}/${navigateRoute}'>${expensifyCardLinkText}</a>` : expensifyCardLinkText;
const isAssigneeCurrentUser = currentUserAccountID === assigneeAccountID;
const isAssigneeCurrentUser = deprecatedCurrentUserAccountID === assigneeAccountID;
const companyCardLink =
shouldRenderHTML && isAssigneeCurrentUser && companyCard
? `<a href='${environmentURL}/${ROUTES.SETTINGS_WALLET}'>${translate('workspace.companyCards.companyCard')}</a>`
Expand Down
8 changes: 5 additions & 3 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
let currentUserAccountID = -1;
let currentUserEmail: string | undefined;

Onyx.connect({

Check warning on line 279 in src/libs/actions/Report.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -289,7 +289,7 @@
},
});

Onyx.connect({

Check warning on line 292 in src/libs/actions/Report.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => (conciergeReportID = value),
});
Expand All @@ -297,7 +297,7 @@
// map of reportID to all reportActions for that report
const allReportActions: OnyxCollection<ReportActions> = {};

Onyx.connect({

Check warning on line 300 in src/libs/actions/Report.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (actions, key) => {
if (!key || !actions) {
Expand All @@ -309,14 +309,14 @@
});

let allTransactionViolations: OnyxCollection<TransactionViolations> = {};
Onyx.connect({

Check warning on line 312 in src/libs/actions/Report.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => (allTransactionViolations = value),
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 319 in src/libs/actions/Report.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -325,7 +325,7 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
Onyx.connect({

Check warning on line 328 in src/libs/actions/Report.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -1996,6 +1996,7 @@
ancestors: Ancestor[],
isReportArchived: boolean | undefined,
isOriginalReportArchived: boolean | undefined,
currentEmail: string,
) {
const originalReportID = getOriginalReportID(reportID, reportAction);
const reportActionID = reportAction.reportActionID;
Expand Down Expand Up @@ -2035,13 +2036,13 @@
...optimisticLastReportData,
};

const didCommentMentionCurrentUser = ReportActionsUtils.didMessageMentionCurrentUser(reportAction);
const didCommentMentionCurrentUser = ReportActionsUtils.didMessageMentionCurrentUser(reportAction, currentEmail);
if (didCommentMentionCurrentUser && reportAction.created === report?.lastMentionedTime) {
const reportActionsForReport = allReportActions?.[reportID];
const latestMentionedReportAction = Object.values(reportActionsForReport ?? {}).find(
(action) =>
action.reportActionID !== reportAction.reportActionID &&
ReportActionsUtils.didMessageMentionCurrentUser(action) &&
ReportActionsUtils.didMessageMentionCurrentUser(action, currentEmail) &&
ReportActionsUtils.shouldReportActionBeVisible(action, action.reportActionID),
);
optimisticReport.lastMentionedTime = latestMentionedReportAction?.created ?? null;
Expand Down Expand Up @@ -2172,6 +2173,7 @@
textForNewComment: string,
isOriginalReportArchived: boolean | undefined,
isOriginalParentReportArchived: boolean | undefined,
currentEmail: string,
videoAttributeCache?: Record<string, string>,
) {
const originalReportID = originalReport?.reportID;
Expand Down Expand Up @@ -2205,7 +2207,7 @@

// Delete the comment if it's empty
if (!htmlForNewComment) {
deleteReportComment(originalReportID, originalReportAction, ancestors, isOriginalReportArchived, isOriginalParentReportArchived);
deleteReportComment(originalReportID, originalReportAction, ancestors, isOriginalReportArchived, isOriginalParentReportArchived, currentEmail);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ function PopoverReportActionContextMenu({ref}: PopoverReportActionContextMenuPro
} else if (reportAction) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => {
deleteReportComment(reportIDRef.current, reportAction, ancestorsRef.current, isReportArchived, isOriginalReportArchived);
deleteReportComment(reportIDRef.current, reportAction, ancestorsRef.current, isReportArchived, isOriginalReportArchived, email ?? '');
});
}

Expand Down
27 changes: 25 additions & 2 deletions src/pages/home/report/ReportActionItemMessageEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as Expensicons from '@components/Icon/Expensicons';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import Tooltip from '@components/Tooltip';
import useAncestors from '@hooks/useAncestors';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useHandleExceedMaxCommentLength from '@hooks/useHandleExceedMaxCommentLength';
import useIsScrollLikelyLayoutTriggered from '@hooks/useIsScrollLikelyLayoutTriggered';
import useKeyboardState from '@hooks/useKeyboardState';
Expand Down Expand Up @@ -110,6 +111,7 @@ function ReportActionItemMessageEdit({
ref,
}: ReportActionItemMessageEditProps) {
const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true});
const {email} = useCurrentUserPersonalDetails();
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand Down Expand Up @@ -314,9 +316,30 @@ function ReportActionItemMessageEdit({
ReportActionContextMenu.showDeleteModal(originalReportID ?? reportID, action, true, deleteDraft, () => focusEditAfterCancelDelete(textInputRef.current));
return;
}
editReportComment(originalReport, action, ancestors, trimmedNewDraft, isOriginalReportArchived, isOriginalParentReportArchived, Object.fromEntries(draftMessageVideoAttributeCache));
editReportComment(
originalReport,
action,
ancestors,
trimmedNewDraft,
isOriginalReportArchived,
isOriginalParentReportArchived,
email ?? '',
Object.fromEntries(draftMessageVideoAttributeCache),
);
deleteDraft();
}, [reportID, action, ancestors, deleteDraft, draft, originalReportID, isOriginalReportArchived, originalReport, isOriginalParentReportArchived, debouncedValidateCommentMaxLength]);
}, [
reportID,
action,
ancestors,
deleteDraft,
draft,
originalReportID,
isOriginalReportArchived,
originalReport,
isOriginalParentReportArchived,
debouncedValidateCommentMaxLength,
email,
]);

/**
* @param emoji
Expand Down
38 changes: 20 additions & 18 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ describe('actions/Report', () => {
.then(() => {
rerender(report);
// If the user deletes a comment that is before the last read
Report.deleteReportComment(REPORT_ID, {...reportActions[200]}, ancestors.current, undefined, undefined);
Report.deleteReportComment(REPORT_ID, {...reportActions[200]}, ancestors.current, undefined, undefined, '');
Report.deleteReportComment(REPORT_ID, {...reportActions[300]}, ancestors.current, undefined, undefined, '');
return waitForBatchedUpdates();
})
.then(() => {
Expand All @@ -528,7 +529,8 @@ describe('actions/Report', () => {

rerender(report);
// If the user deletes the last comment after the lastReadTime the lastMessageText will reflect the new last comment
Report.deleteReportComment(REPORT_ID, {...reportActions[400]}, ancestors.current, undefined, undefined);
Report.deleteReportComment(REPORT_ID, {...reportActions[400]}, ancestors.current, undefined, undefined, USER_1_LOGIN);
Report.deleteReportComment(REPORT_ID, {...reportActions[300]}, ancestors.current, undefined, undefined, USER_1_LOGIN);
return waitForBatchedUpdates();
})
.then(() => {
Expand Down Expand Up @@ -998,7 +1000,7 @@ describe('actions/Report', () => {
};

const {result: ancestors, rerender} = renderHook(() => useAncestors(originalReport));
Report.editReportComment(originalReport, newReportAction, ancestors.current, 'Testing an edited comment', undefined, undefined);
Report.editReportComment(originalReport, newReportAction, ancestors.current, 'Testing an edited comment', undefined, undefined, '');

await waitForBatchedUpdates();

Expand Down Expand Up @@ -1032,7 +1034,7 @@ describe('actions/Report', () => {
});

rerender(originalReport);
Report.deleteReportComment(REPORT_ID, newReportAction, ancestors.current, undefined, undefined);
Report.deleteReportComment(REPORT_ID, newReportAction, ancestors.current, undefined, undefined, '');

await waitForBatchedUpdates();
expect(PersistedRequests.getAll().length).toBe(0);
Expand Down Expand Up @@ -1080,7 +1082,7 @@ describe('actions/Report', () => {
};
const {result: ancestors, rerender} = renderHook(() => useAncestors(originalReport));

Report.editReportComment(originalReport, reportAction, ancestors.current, 'Testing an edited comment', undefined, undefined);
Report.editReportComment(originalReport, reportAction, ancestors.current, 'Testing an edited comment', undefined, undefined, '');

await waitForBatchedUpdates();

Expand All @@ -1096,7 +1098,7 @@ describe('actions/Report', () => {
});

rerender(originalReport);
Report.deleteReportComment(REPORT_ID, reportAction, ancestors.current, undefined, undefined);
Report.deleteReportComment(REPORT_ID, reportAction, ancestors.current, undefined, undefined, '');

await waitForBatchedUpdates();
expect(PersistedRequests.getAll().length).toBe(1);
Expand Down Expand Up @@ -1145,7 +1147,7 @@ describe('actions/Report', () => {
}),
);

Report.deleteReportComment(REPORT_ID, reportAction, [], undefined, undefined);
Report.deleteReportComment(REPORT_ID, reportAction, [], undefined, undefined, '');

jest.runOnlyPendingTimers();
await waitForBatchedUpdates();
Expand Down Expand Up @@ -1207,7 +1209,7 @@ describe('actions/Report', () => {
});
});

Report.deleteReportComment(REPORT_ID, newReportAction, [], undefined, undefined);
Report.deleteReportComment(REPORT_ID, newReportAction, [], undefined, undefined, '');

await waitForBatchedUpdates();
expect(PersistedRequests.getAll().length).toBe(0);
Expand Down Expand Up @@ -1276,7 +1278,7 @@ describe('actions/Report', () => {
});
});

Report.deleteReportComment(REPORT_ID, newReportAction, [], undefined, undefined);
Report.deleteReportComment(REPORT_ID, newReportAction, [], undefined, undefined, '');

await waitForBatchedUpdates();
expect(PersistedRequests.getAll().length).toBe(0);
Expand Down Expand Up @@ -1472,7 +1474,7 @@ describe('actions/Report', () => {
});
});

Report.deleteReportComment(REPORT_ID, newReportAction, [], undefined, undefined);
Report.deleteReportComment(REPORT_ID, newReportAction, [], undefined, undefined, '');

await waitForBatchedUpdates();
expect(PersistedRequests.getAll().length).toBe(0);
Expand Down Expand Up @@ -1556,7 +1558,7 @@ describe('actions/Report', () => {
});
});

Report.deleteReportComment(REPORT_ID, reportAction, [], undefined, undefined);
Report.deleteReportComment(REPORT_ID, reportAction, [], undefined, undefined, '');

await waitForBatchedUpdates();
expect(PersistedRequests.getAll().length).toBe(1);
Expand Down Expand Up @@ -1604,7 +1606,7 @@ describe('actions/Report', () => {

const {result: ancestors} = renderHook(() => useAncestors({reportID: REPORT_ID}));

Report.deleteReportComment(REPORT_ID, reportAction, ancestors.current, undefined, undefined);
Report.deleteReportComment(REPORT_ID, reportAction, ancestors.current, undefined, undefined, '');

expect(PersistedRequests.getAll().length).toBe(3);

Expand Down Expand Up @@ -1642,7 +1644,7 @@ describe('actions/Report', () => {
const originalReport = {
reportID: REPORT_ID,
};
Report.editReportComment(originalReport, reportAction, [], 'Testing an edited comment', undefined, undefined);
Report.editReportComment(originalReport, reportAction, [], 'Testing an edited comment', undefined, undefined, '');

await waitForBatchedUpdates();

Expand Down Expand Up @@ -1680,9 +1682,9 @@ describe('actions/Report', () => {

const {result: ancestors} = renderHook(() => useAncestors(originalReport));

Report.editReportComment(originalReport, action, ancestors.current, 'value1', undefined, undefined);
Report.editReportComment(originalReport, action, ancestors.current, 'value2', undefined, undefined);
Report.editReportComment(originalReport, action, ancestors.current, 'value3', undefined, undefined);
Report.editReportComment(originalReport, action, ancestors.current, 'value1', undefined, undefined, '');
Report.editReportComment(originalReport, action, ancestors.current, 'value2', undefined, undefined, '');
Report.editReportComment(originalReport, action, ancestors.current, 'value3', undefined, undefined, '');

const requests = PersistedRequests?.getAll();

Expand Down Expand Up @@ -1733,8 +1735,8 @@ describe('actions/Report', () => {

const {result: ancestors} = renderHook(() => useAncestors(report));

Report.deleteReportComment(reportID, mentionAction, ancestors.current, undefined, undefined);
Report.deleteReportComment(reportID, mentionAction2, ancestors.current, undefined, undefined);
Report.deleteReportComment(reportID, mentionAction, ancestors.current, undefined, undefined, '');
Report.deleteReportComment(reportID, mentionAction2, ancestors.current, undefined, undefined, '');

await waitForBatchedUpdates();

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/UnreadIndicatorsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ describe('Unread Indicators', () => {
expect(screen.getAllByText('Current User Comment 1').at(0)).toBeOnTheScreen();

if (lastReportAction) {
deleteReportComment(REPORT_ID, lastReportAction, [], undefined, undefined);
deleteReportComment(REPORT_ID, lastReportAction, [], undefined, undefined, '');
}
return waitForBatchedUpdates();
})
Expand Down Expand Up @@ -616,7 +616,7 @@ describe('Unread Indicators', () => {

await waitForBatchedUpdates();

deleteReportComment(REPORT_ID, firstNewReportAction, [], undefined, undefined);
deleteReportComment(REPORT_ID, firstNewReportAction, [], undefined, undefined, '');

await waitForBatchedUpdates();
}
Expand Down
Loading
Loading