Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, {
reportName = ReportUtils.getReportName(report);
} else {
reportName = ReportUtils.getDisplayNameForParticipant(accountIDs[0]);
result.keyForList = accountIDs[0];
result.keyForList = String(accountIDs[0]);
Comment thread
mountiny marked this conversation as resolved.
result.alternateText = '';
}

Expand Down
62 changes: 62 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as OptionsListUtils from '../OptionsListUtils';
import DateUtils from '../DateUtils';
import TransactionUtils from '../TransactionUtils';
import * as ErrorUtils from '../ErrorUtils';
import * as UserUtils from '../UserUtils';

const chatReports = {};
const iouReports = {};
Expand Down Expand Up @@ -51,6 +52,7 @@ function buildOnyxDataForMoneyRequest(
chatCreatedAction,
iouCreatedAction,
iouAction,
optimisticPersonalDetailListAction,
reportPreviewAction,
isNewChatReport,
isNewIOUReport,
Expand Down Expand Up @@ -104,6 +106,14 @@ function buildOnyxDataForMoneyRequest(
},
];

if (isNewChatReport && !_.isEmpty(optimisticPersonalDetailListAction)) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: optimisticPersonalDetailListAction,
});
}
Comment on lines +109 to +115

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This caused a regression. Merging the personal data should only be done only if it's not in Onyx already. Otherwise we would overwrite the existing user data e.g. displayName.


const successData = [
...(isNewChatReport
? [
Expand Down Expand Up @@ -327,6 +337,16 @@ function requestMoney(report, amount, currency, payeeEmail, payeeAccountID, part
iouReport.reportID,
);

// Add optimistic personal details for participant
Comment thread
BeeMargarida marked this conversation as resolved.
const optimisticPersonalDetailListAction = {
[payerAccountID]: {
accountID: payerAccountID,
avatar: UserUtils.getDefaultAvatarURL(payerAccountID),
displayName: participant.displayName || payerEmail,
login: participant.login,
},
};

let isNewReportPreviewAction = false;
let reportPreviewAction = isNewIOUReport ? null : ReportActionsUtils.getReportPreviewAction(chatReport.reportID, iouReport.reportID);
if (!reportPreviewAction) {
Expand All @@ -342,6 +362,7 @@ function requestMoney(report, amount, currency, payeeEmail, payeeAccountID, part
optimisticCreatedActionForChat,
optimisticCreatedActionForIOU,
optimisticIOUAction,
optimisticPersonalDetailListAction,
reportPreviewAction,
isNewChatReport,
isNewIOUReport,
Expand Down Expand Up @@ -564,6 +585,16 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco
oneOnOneIOUReport.reportID,
);

// Add optimistic personal details for new participants
Comment thread
BeeMargarida marked this conversation as resolved.
const oneOnOnePersonalDetailListAction = {
[accountID]: {
accountID,
Comment thread
mountiny marked this conversation as resolved.
avatar: UserUtils.getDefaultAvatarURL(accountID),
displayName: participant.displayName || email,
login: participant.login,
},
};

let isNewOneOnOneReportPreviewAction = false;
let oneOnOneReportPreviewAction = ReportActionsUtils.getReportPreviewAction(oneOnOneChatReport.reportID, oneOnOneIOUReport.reportID);
if (!oneOnOneReportPreviewAction) {
Expand All @@ -579,6 +610,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco
oneOnOneCreatedActionForChat,
oneOnOneCreatedActionForIOU,
oneOnOneIOUAction,
oneOnOnePersonalDetailListAction,
oneOnOneReportPreviewAction,
isNewOneOnOneChatReport,
isNewOneOnOneIOUReport,
Expand Down Expand Up @@ -937,6 +969,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
},
];

let optimisticPersonalDetailListData = {};

// Now, let's add the data we need just when we are creating a new chat report
if (isNewChat) {
// Change the method to set for new reports because it doesn't exist yet, is faster,
Expand All @@ -962,6 +996,20 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
},
});

// Add optimistic personal details for recipient
optimisticPersonalDetailListData = {
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[recipientAccountID]: {
accountID: recipientAccountID,
avatar: UserUtils.getDefaultAvatarURL(recipient.accountID),
displayName: recipient.displayName || recipient.login,
login: recipient.login,
},
},
};

// Add an optimistic created action to the optimistic reportActions data
optimisticReportActionsData.value[optimisticCreatedAction.reportActionID] = optimisticCreatedAction;

Expand All @@ -970,6 +1018,9 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
}

const optimisticData = [optimisticChatReportData, optimisticIOUReportData, optimisticReportActionsData, optimisticTransactionData];
if (!_.isEmpty(optimisticPersonalDetailListData)) {
optimisticData.push(optimisticPersonalDetailListData);
}

return {
params: {
Expand Down Expand Up @@ -1007,6 +1058,12 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho
iouReport.reportID,
true,
);
const optimisticPersonalDetailsListAction = {
accountID: Number(recipient.accountID),
avatar: UserUtils.getDefaultAvatarURL(Number(recipient.accountID)),
displayName: recipient.displayName || recipient.login,
login: recipient.login,
};
Comment on lines +1061 to +1066

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There was a copy/paste mistake here. This data itself (without accountID key) is added in ONYXKEYS.PERSONAL_DETAILS_LIST. Luckily, this didn't cause any issue but just console error.
More details: #23645 (comment)


const optimisticData = [
{
Expand Down Expand Up @@ -1053,6 +1110,11 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho
key: ONYXKEYS.NVP_LAST_PAYMENT_METHOD,
value: {[iouReport.policyID]: paymentMethodType},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: optimisticPersonalDetailsListAction,
},
];

const successData = [
Expand Down