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

Fix chat doesn't scroll when splitting expense #54863

2 changes: 2 additions & 0 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
@@ -1001,6 +1001,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
value: {
...chat.report,
lastReadTime: DateUtils.getDBTime(),
...(shouldCreateNewMoneyRequestReport ? {lastVisibleActionCreated: chat.reportPreviewAction.created} : {}),
iouReportID: iou.report.reportID,
...outstandingChildRequest,
...(isNewChatReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}),
@@ -1268,6 +1269,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
value: {
iouReportID: chat.report?.iouReportID,
lastReadTime: chat.report?.lastReadTime,
lastVisibleActionCreated: chat.report?.lastVisibleActionCreated,
pendingFields: null,
hasOutstandingChildRequest: chat.report?.hasOutstandingChildRequest,
...(isNewChatReport
4 changes: 2 additions & 2 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
@@ -466,7 +466,7 @@ function ReportActionsList({
(isFromCurrentUser: boolean) => {
// If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where
// they are now in the list.
if (!isFromCurrentUser || scrollingVerticalOffset.current === 0 || !isReportScreenTopmostCentralPane()) {
if (!isFromCurrentUser || !isReportScreenTopmostCentralPane()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the condition. It's just for early returns based on this comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rinej Can you help me confirm if it is safe to remove this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can. The previous logic didn't have it.

Screenshot 2025-01-25 at 15 59 48

return;
}
if (!hasNewestReportActionRef.current) {
@@ -485,7 +485,7 @@ function ReportActionsList({
);

useEffect(() => {
if (!pendingBottomScroll || scrollingVerticalOffset.current === 0) {
if (!pendingBottomScroll) {
return;
}

43 changes: 43 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
@@ -1738,6 +1738,49 @@ describe('actions/IOU', () => {
}),
);
});

it('should update split chat report lastVisibleActionCreated to the report preview action', async () => {
// Given a workspace chat with no expenses
const workspaceReportID = '1';
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${workspaceReportID}`, {reportID: workspaceReportID, isOwnPolicyExpenseChat: true});

// When the user split bill on the workspace
splitBill({
participants: [{reportID: workspaceReportID}],
currentUserLogin: RORY_EMAIL,
currentUserAccountID: RORY_ACCOUNT_ID,
comment: '',
amount: 100,
currency: CONST.CURRENCY.USD,
merchant: 'test',
created: '',
existingSplitChatReportID: workspaceReportID,
});

await waitForBatchedUpdates();

// Then the workspace chat lastVisibleActionCreated should be updated to the report preview action created
const reportPreviewAction = await new Promise<OnyxEntry<ReportAction>>((resolve) => {
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceReportID}`,
callback: (reportActions) => {
Onyx.disconnect(connection);
resolve(Object.values(reportActions ?? {}).find((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW));
},
});
});

await new Promise<OnyxEntry<Report>>((resolve) => {
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT}${workspaceReportID}`,
callback: (report) => {
Onyx.disconnect(connection);
expect(report?.lastVisibleActionCreated).toBe(reportPreviewAction?.created);
resolve(report);
},
});
});
});
});

describe('payMoneyRequestElsewhere', () => {