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 split bill in dm #57224

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ import {
isInvoiceReport as isInvoiceReportReportUtils,
isInvoiceRoom,
isMoneyRequestReport as isMoneyRequestReportReportUtils,
isOneOnOneChat,
isOpenExpenseReport as isOpenExpenseReportReportUtils,
isOpenInvoiceReport as isOpenInvoiceReportReportUtils,
isOptimisticPersonalDetail,
Expand Down Expand Up @@ -5280,7 +5281,7 @@ function createSplitsAndOnyxData(
// or, if the split is being made from the workspace chat, then the oneOnOneChatReport is the same as the splitChatReport
// in this case existingSplitChatReport will belong to the policy expense chat and we won't be
// entering code that creates optimistic personal details
if ((!hasMultipleParticipants && !existingSplitChatReportID) || isOwnPolicyExpenseChat) {
if ((!hasMultipleParticipants && !existingSplitChatReportID) || isOwnPolicyExpenseChat || isOneOnOneChat(splitChatReport)) {
oneOnOneChatReport = splitChatReport;
shouldCreateOptimisticPersonalDetails = !existingSplitChatReport && !personalDetailExists;
} else {
Expand Down
61 changes: 61 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,67 @@ describe('actions/IOU', () => {
});
});
});

it('should update split chat report lastVisibleActionCreated to the latest IOU action when split bill in a DM', async () => {
// Given a DM chat with no expenses
const reportID = '1';
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
reportID,
type: CONST.REPORT.TYPE.CHAT,
participants: {[RORY_ACCOUNT_ID]: RORY_PARTICIPANT, [CARLOS_ACCOUNT_ID]: CARLOS_PARTICIPANT},
});

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

await waitForBatchedUpdates();

splitBill({
participants: [{accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}],
currentUserLogin: RORY_EMAIL,
currentUserAccountID: RORY_ACCOUNT_ID,
comment: '',
amount: 200,
currency: CONST.CURRENCY.USD,
merchant: 'test',
created: '',
existingSplitChatReportID: reportID,
});

await waitForBatchedUpdates();

// Then the DM lastVisibleActionCreated should be updated to the second IOU action created
const iouAction = await new Promise<OnyxEntry<ReportAction>>((resolve) => {
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
callback: (reportActions) => {
Onyx.disconnect(connection);
resolve(Object.values(reportActions ?? {}).find((action) => isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.IOU) && getOriginalMessage(action)?.amount === 200));
},
});
});

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

describe('payMoneyRequestElsewhere', () => {
Expand Down