Skip to content
Closed
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
8 changes: 8 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ const ONYXKEYS = {
/** Whether the user is a member of a policy other than their personal */
HAS_NON_PERSONAL_POLICY: 'hasNonPersonalPolicy',

/** Key under which selfDM id is stored. Returned by OpenApp */
SELF_DM_REPORT_ID: 'selfDMReportID',

/** Key under which selfDM created action id is stored. Returned by OpenApp */
SELF_DM_REPORT_CREATED_ACTION_ID: 'selfDMReportCreatedActionID',

/** NVP keys */

/** This NVP contains list of at most 5 recent attendees */
Expand Down Expand Up @@ -1308,6 +1314,8 @@ type OnyxValuesMapping = {
[ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE]: DistanceExpenseType;
[ONYXKEYS.NVP_REPORT_LAYOUT_GROUP_BY]: string;
[ONYXKEYS.HAS_DENIED_CONTACT_IMPORT_PROMPT]: boolean | undefined;
[ONYXKEYS.SELF_DM_REPORT_ID]: string | undefined;
[ONYXKEYS.SELF_DM_REPORT_CREATED_ACTION_ID]: string | undefined;
[ONYXKEYS.IS_OPEN_CONFIRM_NAVIGATE_EXPENSIFY_CLASSIC_MODAL_OPEN]: boolean;
};

Expand Down
36 changes: 34 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,28 @@ Onyx.connectWithoutView({
},
});

let existingSelfDMReportID: string | undefined;
Onyx.connectWithoutView({
key: ONYXKEYS.SELF_DM_REPORT_ID,
callback: (value) => {
if (!value) {
return;
}
existingSelfDMReportID = value;
},
});

let existingSelfDMReportCreatedActionID: string | undefined;
Onyx.connectWithoutView({
key: ONYXKEYS.SELF_DM_REPORT_CREATED_ACTION_ID,
callback: (value) => {
if (!value) {
return;
}
existingSelfDMReportCreatedActionID = value;
},
});

function getCurrentUserAvatar(): AvatarSource | undefined {
return currentUserPersonalDetails?.avatar;
}
Expand Down Expand Up @@ -1859,10 +1881,18 @@ function findSelfDMReportID(): string | undefined {
return;
}

if (existingSelfDMReportID) {
return existingSelfDMReportID;
}

const selfDMReport = Object.values(allReports).find((report) => isSelfDM(report) && !isThread(report));
return selfDMReport?.reportID;
}

function getSelfDMReportCreatedActionID(): string | undefined {
return existingSelfDMReportCreatedActionID;
}

/**
* Checks if the supplied report is from a policy or is an invoice report from a policy
*/
Expand Down Expand Up @@ -6598,7 +6628,7 @@ function buildOptimisticTaskCommentReportAction(

function buildOptimisticSelfDMReport(created: string): Report {
return {
reportID: generateReportID(),
reportID: existingSelfDMReportID ?? generateReportID(),
participants: {
[currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID]: {
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE,
Expand Down Expand Up @@ -11968,7 +11998,8 @@ function prepareOnboardingOnyxData({
if (!selfDMReport) {
const currentTime = DateUtils.getDBTime();
selfDMReport = buildOptimisticSelfDMReport(currentTime);
createdAction = buildOptimisticCreatedReportAction(currentUserEmail ?? '', currentTime);
const selfDMCreatedReportActionID = getSelfDMReportCreatedActionID();
createdAction = buildOptimisticCreatedReportAction(currentUserEmail ?? '', currentTime, selfDMCreatedReportActionID);
selfDMParameters = {reportID: selfDMReport.reportID, createdReportActionID: createdAction.reportActionID};
optimisticData.push(
{
Expand Down Expand Up @@ -13411,6 +13442,7 @@ export {
shouldBlockSubmitDueToStrictPolicyRules,
isWorkspaceChat,
isOneTransactionReport,
getSelfDMReportCreatedActionID,
};
export type {
Ancestor,
Expand Down
4 changes: 3 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ import {
getReportOrDraftReport,
getReportRecipientAccountIDs,
getReportTransactions,
getSelfDMReportCreatedActionID,
getTransactionDetails,
hasHeldExpenses as hasHeldExpensesReportUtils,
hasNonReimbursableTransactions as hasNonReimbursableTransactionsReportUtils,
Expand Down Expand Up @@ -4083,7 +4084,8 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T
if (!chatReport) {
const currentTime = DateUtils.getDBTime();
const selfDMReport = buildOptimisticSelfDMReport(currentTime);
const selfDMCreatedReportAction = buildOptimisticCreatedReportAction(currentUserEmail ?? '', currentTime);
const selfDMCreatedReportActionID = getSelfDMReportCreatedActionID();
const selfDMCreatedReportAction = buildOptimisticCreatedReportAction(currentUserEmail ?? '', currentTime, selfDMCreatedReportActionID);
optimisticReportID = selfDMReport.reportID;
optimisticReportActionID = selfDMCreatedReportAction.reportActionID;
chatReport = selfDMReport;
Expand Down
4 changes: 3 additions & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ import {
getReportPreviewMessage,
getReportTransactions,
getReportViolations,
getSelfDMReportCreatedActionID,
getTitleReportField,
hasOutstandingChildRequest,
isChatThread as isChatThreadReportUtils,
Expand Down Expand Up @@ -4914,7 +4915,8 @@ function deleteAppReport(reportID: string | undefined, currentUserEmailParam: st
const currentTime = DateUtils.getDBTime();
selfDMReport = buildOptimisticSelfDMReport(currentTime);
selfDMReportID = selfDMReport.reportID;
createdAction = buildOptimisticCreatedReportAction(currentUserEmailParam ?? '', currentTime);
const selfDMCreatedReportActionID = getSelfDMReportCreatedActionID();
createdAction = buildOptimisticCreatedReportAction(currentUserEmailParam ?? '', currentTime, selfDMCreatedReportActionID);
selfDMParameters = {reportID: selfDMReport.reportID, createdReportActionID: createdAction.reportActionID};
optimisticData.push(
{
Expand Down
8 changes: 5 additions & 3 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
buildTransactionThread,
findSelfDMReportID,
getReportTransactions,
getSelfDMReportCreatedActionID,
getTransactionDetails,
hasViolations as hasViolationsReportUtils,
shouldEnableNegative,
Expand Down Expand Up @@ -721,14 +722,15 @@ function changeTransactionsReport(
const successData: OnyxUpdate[] = [];

const existingSelfDMReportID = findSelfDMReportID();
let selfDMReport: Report | undefined;
let selfDMReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${existingSelfDMReportID}`];
let selfDMCreatedReportAction: ReportAction | undefined;
const currentUserAccountID = getCurrentUserAccountID();

if (!existingSelfDMReportID && reportID === CONST.REPORT.UNREPORTED_REPORT_ID) {
if (!selfDMReport && reportID === CONST.REPORT.UNREPORTED_REPORT_ID) {
const currentTime = DateUtils.getDBTime();
selfDMReport = buildOptimisticSelfDMReport(currentTime);
selfDMCreatedReportAction = buildOptimisticCreatedReportAction(email ?? '', currentTime);
const selfDMCreatedReportActionID = getSelfDMReportCreatedActionID();
selfDMCreatedReportAction = buildOptimisticCreatedReportAction(email ?? '', currentTime, selfDMCreatedReportActionID);

// Add optimistic updates for self DM report
optimisticData.push(
Expand Down