Skip to content

Commit 988ae03

Browse files
authored
Merge pull request Expensify#86672 from dukenv0307/fix/66412-part-5
Refactor buildOptimisticChatReport to use currentUserAccountID from useOnyx
2 parents 7c72dff + cb7b6e0 commit 988ae03

16 files changed

Lines changed: 263 additions & 12 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7945,6 +7945,8 @@ type BuildOptimisticChatReportParams = {
79457945
optimisticReportID?: string;
79467946
isPinned?: boolean;
79477947
chatReportID?: string;
7948+
// TODO: This'll be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66412
7949+
currentUserAccountID?: number;
79487950
};
79497951

79507952
function buildOptimisticChatReport({
@@ -7965,12 +7967,13 @@ function buildOptimisticChatReport({
79657967
optimisticReportID = '',
79667968
isPinned = false,
79677969
chatReportID = undefined,
7970+
currentUserAccountID = deprecatedCurrentUserAccountID,
79687971
}: BuildOptimisticChatReportParams): OptimisticChatReport {
79697972
const isWorkspaceChatType = chatType && isWorkspaceChat(chatType);
79707973
const participants = participantList.reduce((reportParticipants: Participants, accountID: number) => {
79717974
const participant: ReportParticipant = {
79727975
notificationPreference,
7973-
...(!isWorkspaceChatType && {role: accountID === deprecatedCurrentUserAccountID ? CONST.REPORT.ROLE.ADMIN : CONST.REPORT.ROLE.MEMBER}),
7976+
...(!isWorkspaceChatType && {role: accountID === currentUserAccountID ? CONST.REPORT.ROLE.ADMIN : CONST.REPORT.ROLE.MEMBER}),
79747977
};
79757978
// eslint-disable-next-line no-param-reassign
79767979
reportParticipants[accountID] = participant;

src/libs/actions/IOU/PerDiem.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI
340340
isNewChatReport = true;
341341
chatReport = buildOptimisticChatReport({
342342
participantList: [payerAccountID, payeeAccountID],
343+
currentUserAccountID: currentUserAccountIDParam,
343344
});
344345
}
345346

src/libs/actions/IOU/SendInvoice.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ function getSendInvoiceInformation({
620620
participantList: [receiverAccountID, currentUserAccountID],
621621
chatType: CONST.REPORT.CHAT_TYPE.INVOICE,
622622
policyID: senderWorkspaceID,
623+
currentUserAccountID,
623624
});
624625
}
625626

src/libs/actions/IOU/SendMoney.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function getSendMoneyParams({
7272
created,
7373
merchant,
7474
receipt,
75+
currentUserAccountID,
7576
}: {
7677
report: OnyxEntry<OnyxTypes.Report>;
7778
quickAction: OnyxEntry<OnyxTypes.QuickAction>;
@@ -84,6 +85,7 @@ function getSendMoneyParams({
8485
created?: string;
8586
merchant?: string;
8687
receipt?: Receipt;
88+
currentUserAccountID: number;
8789
}): SendMoneyParamsData {
8890
const recipientEmail = addSMSDomainIfPhoneNumber(recipient.login ?? '');
8991
const recipientAccountID = Number(recipient.accountID);
@@ -104,6 +106,7 @@ function getSendMoneyParams({
104106
if (!chatReport) {
105107
chatReport = buildOptimisticChatReport({
106108
participantList: [recipientAccountID, managerID],
109+
currentUserAccountID,
107110
});
108111
isNewChat = true;
109112
}
@@ -503,6 +506,7 @@ function sendMoneyElsewhere(
503506
created,
504507
merchant,
505508
receipt,
509+
currentUserAccountID,
506510
});
507511
startSpan(CONST.TELEMETRY.SPAN_SUBMIT_TO_DESTINATION_VISIBLE, {
508512
name: 'submit-to-destination-visible',
@@ -550,6 +554,7 @@ function sendMoneyWithWallet(
550554
created,
551555
merchant,
552556
receipt,
557+
currentUserAccountID,
553558
});
554559
startSpan(CONST.TELEMETRY.SPAN_SUBMIT_TO_DESTINATION_VISIBLE, {
555560
name: 'submit-to-destination-visible',

src/libs/actions/IOU/Split.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ function completeSplitBill(
878878
existingChatReport ??
879879
buildOptimisticChatReport({
880880
participantList: participant.accountID ? [participant.accountID, sessionAccountID] : [],
881+
currentUserAccountID: sessionAccountID,
881882
});
882883
}
883884

src/libs/actions/IOU/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,6 +2502,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma
25022502
chatReport = buildOptimisticChatReport({
25032503
participantList: [payerAccountID, payeeAccountID],
25042504
optimisticReportID: optimisticChatReportID,
2505+
currentUserAccountID: currentUserAccountIDParam,
25052506
});
25062507
}
25072508

@@ -4416,6 +4417,7 @@ function getOrCreateOptimisticSplitChatReport(existingSplitChatReportID: string
44164417
reportName: '',
44174418
chatType: CONST.REPORT.CHAT_TYPE.GROUP,
44184419
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
4420+
currentUserAccountID,
44194421
});
44204422

44214423
return {existingSplitChatReport: null, splitChatReport};
@@ -4424,6 +4426,7 @@ function getOrCreateOptimisticSplitChatReport(existingSplitChatReportID: string
44244426
// Otherwise, create a new 1:1 chat report
44254427
const splitChatReport = buildOptimisticChatReport({
44264428
participantList: participantAccountIDs,
4429+
currentUserAccountID,
44274430
});
44284431
return {existingSplitChatReport: null, splitChatReport};
44294432
}
@@ -4743,6 +4746,7 @@ function createSplitsAndOnyxData({
47434746
existingChatReport ??
47444747
buildOptimisticChatReport({
47454748
participantList: [accountID, currentUserAccountID],
4749+
currentUserAccountID,
47464750
});
47474751
}
47484752

src/libs/actions/Policy/Policy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,7 @@ function createPolicyExpenseChats(
16051605
policyID,
16061606
ownerAccountID: cleanAccountID,
16071607
notificationPreference,
1608+
currentUserAccountID: deprecatedSessionAccountID,
16081609
});
16091610

16101611
// Set correct notification preferences: visible for the submitter, hidden for others until there's activity

src/libs/actions/Report/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,7 @@ function getOptimisticChatReport(accountID: number, currentUserAccountID: number
18731873
return buildOptimisticChatReport({
18741874
participantList: [accountID, currentUserAccountID],
18751875
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
1876+
currentUserAccountID,
18761877
});
18771878
}
18781879

@@ -1986,6 +1987,7 @@ function navigateToAndOpenReport(
19861987
newChat = buildOptimisticChatReport({
19871988
participantList: [...participantAccountIDs, currentUserAccountID],
19881989
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
1990+
currentUserAccountID,
19891991
});
19901992
// We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server
19911993
openReport({reportID: newChat?.reportID, introSelected, reportActionID: '', participantLoginList: userLogins, newReportObject: newChat, isSelfTourViewed, betas});
@@ -2026,6 +2028,7 @@ function navigateToAndOpenReportWithAccountIDs(participantAccountIDs: number[],
20262028
if (!chat) {
20272029
newChat = buildOptimisticChatReport({
20282030
participantList: [...participantAccountIDs, currentUserAccountID],
2031+
currentUserAccountID,
20292032
});
20302033
// We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server
20312034
openReport({
@@ -2091,6 +2094,7 @@ function createChildReport(
20912094
parentReportActionID: parentReportAction.reportActionID,
20922095
parentReportID: parentReport?.reportID,
20932096
optimisticReportID: parentReportAction.childReportID,
2097+
currentUserAccountID,
20942098
});
20952099

20962100
const childReportID = childReport?.reportID ?? parentReportAction.childReportID;
@@ -3001,6 +3005,7 @@ function toggleSubscribeToChildReport(
30013005
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
30023006
parentReportActionID: parentReportAction.reportActionID,
30033007
parentReportID: parentReport?.reportID,
3008+
currentUserAccountID,
30043009
});
30053010

30063011
const participantLogins = PersonalDetailsUtils.getLoginsByAccountIDs(participantAccountIDs);

src/libs/actions/Task.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ function setNewOptimisticAssignee(currentUserAccountID: number, assigneePersonal
935935
policyID: CONST.POLICY.OWNER_EMAIL_FAKE,
936936
ownerAccountID: CONST.POLICY.OWNER_ACCOUNT_ID_FAKE,
937937
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
938+
currentUserAccountID,
938939
});
939940

940941
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);

src/libs/actions/TeachersUnite.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ type ExpenseReportActionData = Record<string, OptimisticCreatedReportAction>;
2323
/**
2424
* @param publicRoomReportID - This is the global reportID for the public room, we'll ignore the optimistic one
2525
*/
26-
function referTeachersUniteVolunteer(partnerUserID: string, firstName: string, lastName: string, policyID: string, publicRoomReportID: string) {
26+
function referTeachersUniteVolunteer(partnerUserID: string, firstName: string, lastName: string, policyID: string, publicRoomReportID: string, currentUserAccountID: number) {
2727
const optimisticPublicRoom = buildOptimisticChatReport({
2828
participantList: [],
2929
reportName: CONST.TEACHERS_UNITE.PUBLIC_ROOM_NAME,
3030
chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
3131
policyID,
32+
currentUserAccountID,
3233
});
3334
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.REPORT_METADATA>> = [
3435
{
@@ -86,6 +87,7 @@ function addSchoolPrincipal(
8687
isOwnPolicyExpenseChat: true,
8788
oldPolicyName: policyName,
8889
optimisticReportID,
90+
currentUserAccountID: sessionAccountID,
8991
});
9092
const expenseChatReportID = expenseChatData.reportID;
9193
const expenseReportCreatedAction = buildOptimisticCreatedReportAction(sessionEmail);

0 commit comments

Comments
 (0)