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

[CP Staging] Use whisperedTo instead of whisperedToAccountIDs #41856

Merged
merged 8 commits into from
May 8, 2024
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
30 changes: 25 additions & 5 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
OriginalMessageReimbursementDequeued,
} from '@src/types/onyx/OriginalMessage';
import type Report from '@src/types/onyx/Report';
import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/ReportAction';
import type {Message, ReportActionBase, ReportActionMessageJSON, ReportActions} from '@src/types/onyx/ReportAction';
import type ReportAction from '@src/types/onyx/ReportAction';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
Expand Down Expand Up @@ -143,8 +143,27 @@ function isModifiedExpenseAction(reportAction: OnyxEntry<ReportAction> | ReportA
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE;
}

/**
* We are in the process of deprecating reportAction.originalMessage and will be setting the db version of "message" to reportAction.message in the future see: https://github.com/Expensify/App/issues/39797
* In the interim, we must check to see if we have an object or array for the reportAction.message, if we have an array we will use the originalMessage as this means we have not yet migrated.
*/
function getWhisperedTo(reportAction: OnyxEntry<ReportAction> | EmptyObject): number[] {
const originalMessage = reportAction?.originalMessage;
const message = reportAction?.message;

if (!Array.isArray(message) && typeof message === 'object') {
return (message as ReportActionMessageJSON)?.whisperedTo ?? [];
}

if (originalMessage) {
return (originalMessage as ReportActionMessageJSON)?.whisperedTo ?? [];
}

return [];
}

function isWhisperAction(reportAction: OnyxEntry<ReportAction> | EmptyObject): boolean {
return (reportAction?.whisperedToAccountIDs ?? []).length > 0;
return getWhisperedTo(reportAction).length > 0;
}

/**
Expand All @@ -154,7 +173,7 @@ function isWhisperActionTargetedToOthers(reportAction: OnyxEntry<ReportAction>):
if (!isWhisperAction(reportAction)) {
return false;
}
return !reportAction?.whisperedToAccountIDs?.includes(currentUserAccountID ?? 0);
return !getWhisperedTo(reportAction).includes(currentUserAccountID ?? 0);
}

function isReimbursementQueuedAction(reportAction: OnyxEntry<ReportAction>) {
Expand Down Expand Up @@ -278,8 +297,8 @@ function shouldIgnoreGap(currentReportAction: ReportAction | undefined, nextRepo
return (
isOptimisticAction(currentReportAction) ||
isOptimisticAction(nextReportAction) ||
!!currentReportAction.whisperedToAccountIDs?.length ||
!!nextReportAction.whisperedToAccountIDs?.length ||
!!getWhisperedTo(currentReportAction).length ||
!!getWhisperedTo(nextReportAction).length ||
currentReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.INVITE_TO_ROOM ||
nextReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED ||
nextReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED
Expand Down Expand Up @@ -1196,6 +1215,7 @@ export {
getParentReportAction,
getReportAction,
getReportActionMessageText,
getWhisperedTo,
isApprovedOrSubmittedReportAction,
getReportPreviewAction,
getSortedReportActions,
Expand Down
21 changes: 14 additions & 7 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import type {
} from '@src/types/onyx/OriginalMessage';
import type {Status} from '@src/types/onyx/PersonalDetails';
import type {NotificationPreference, Participants, PendingChatMember, Participant as ReportParticipant} from '@src/types/onyx/Report';
import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/ReportAction';
import type {Message, ReportActionBase, ReportActions, ReportPreviewAction} from '@src/types/onyx/ReportAction';
import type {Comment, Receipt, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
Expand Down Expand Up @@ -148,7 +148,6 @@ type OptimisticAddCommentReportAction = Pick<
| 'childCommenterCount'
| 'childLastVisibleActionCreated'
| 'childOldestFourAccountIDs'
| 'whisperedToAccountIDs'
> & {isOptimisticAction: boolean};

type OptimisticReportAction = {
Expand Down Expand Up @@ -197,7 +196,6 @@ type OptimisticIOUReportAction = Pick<
| 'created'
| 'pendingAction'
| 'receipt'
| 'whisperedToAccountIDs'
| 'childReportID'
| 'childVisibleActionCount'
| 'childCommenterCount'
Expand Down Expand Up @@ -3898,6 +3896,7 @@ function buildOptimisticIOUReportAction(
IOUTransactionID: transactionID,
IOUReportID,
type,
whisperedTo: [CONST.IOU.RECEIPT_STATE.SCANREADY, CONST.IOU.RECEIPT_STATE.SCANNING].some((value) => value === receipt?.state) ? [currentUserAccountID ?? -1] : [],
};

if (type === CONST.IOU.REPORT_ACTION_TYPE.PAY) {
Expand Down Expand Up @@ -3951,7 +3950,6 @@ function buildOptimisticIOUReportAction(
shouldShow: true,
created,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
whisperedToAccountIDs: [CONST.IOU.RECEIPT_STATE.SCANREADY, CONST.IOU.RECEIPT_STATE.SCANNING].some((value) => value === receipt?.state) ? [currentUserAccountID ?? -1] : [],
};
}

Expand Down Expand Up @@ -4083,6 +4081,7 @@ function buildOptimisticReportPreview(chatReport: OnyxEntry<Report>, iouReport:
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
originalMessage: {
linkedReportID: iouReport?.reportID,
whisperedTo: isReceiptBeingScanned ? [currentUserAccountID ?? -1] : [],
},
message: [
{
Expand All @@ -4100,7 +4099,6 @@ function buildOptimisticReportPreview(chatReport: OnyxEntry<Report>, iouReport:
childMoneyRequestCount: 1,
childLastMoneyRequestComment: comment,
childRecentReceiptTransactionIDs: hasReceipt && !isEmptyObject(transaction) ? {[transaction?.transactionID ?? '']: created} : undefined,
whisperedToAccountIDs: isReceiptBeingScanned ? [currentUserAccountID ?? -1] : [],
};
}

Expand Down Expand Up @@ -4190,7 +4188,13 @@ function buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThrea
* @param [transaction] - optimistic newest transaction of a report preview
*
*/
function updateReportPreview(iouReport: OnyxEntry<Report>, reportPreviewAction: ReportAction, isPayRequest = false, comment = '', transaction: OnyxEntry<Transaction> = null): ReportAction {
function updateReportPreview(
iouReport: OnyxEntry<Report>,
reportPreviewAction: ReportPreviewAction,
isPayRequest = false,
comment = '',
transaction: OnyxEntry<Transaction> = null,
): ReportPreviewAction {
const hasReceipt = TransactionUtils.hasReceipt(transaction);
const recentReceiptTransactions = reportPreviewAction?.childRecentReceiptTransactionIDs ?? {};
const transactionsToKeep = TransactionUtils.getRecentTransactions(recentReceiptTransactions);
Expand Down Expand Up @@ -4226,7 +4230,10 @@ function updateReportPreview(iouReport: OnyxEntry<Report>, reportPreviewAction:
: recentReceiptTransactions,
// As soon as we add a transaction without a receipt to the report, it will have ready expenses,
// so we remove the whisper
whisperedToAccountIDs: hasReceipt ? reportPreviewAction?.whisperedToAccountIDs : [],
originalMessage: {
...(reportPreviewAction.originalMessage ?? {}),
whisperedTo: hasReceipt ? reportPreviewAction?.originalMessage?.whisperedTo : [],
},
};
}

Expand Down
35 changes: 24 additions & 11 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import type {Participant, Split} from '@src/types/onyx/IOU';
import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon';
import type {IOUMessage, PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import type ReportAction from '@src/types/onyx/ReportAction';
import type {ReportPreviewAction} from '@src/types/onyx/ReportAction';
import type {OnyxData} from '@src/types/onyx/Request';
import type {Comment, Receipt, ReceiptSource, SplitShares, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
Expand Down Expand Up @@ -1875,7 +1876,7 @@ function getMoneyRequestInformation(
let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID);

if (reportPreviewAction) {
reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction, false, comment, optimisticTransaction);
reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction as ReportPreviewAction, false, comment, optimisticTransaction);
} else {
reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction);

Expand Down Expand Up @@ -2099,7 +2100,7 @@ function getTrackExpenseInformation(
reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID);

if (reportPreviewAction) {
reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction, false, comment, optimisticTransaction);
reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction as ReportPreviewAction, false, comment, optimisticTransaction);
} else {
reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction);
// Generated ReportPreview action is a parent report action of the iou report.
Expand Down Expand Up @@ -2444,7 +2445,9 @@ function getUpdateMoneyRequestParams(
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.reportID}`,
value: {
[transactionThread?.parentReportActionID ?? '']: {
whisperedToAccountIDs: [],
originalMessage: {
whisperedTo: [],
},
},
},
},
Expand All @@ -2453,7 +2456,9 @@ function getUpdateMoneyRequestParams(
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.parentReportID}`,
value: {
[iouReport?.parentReportActionID ?? '']: {
whisperedToAccountIDs: [],
originalMessage: {
whisperedTo: [],
},
},
},
},
Expand Down Expand Up @@ -2687,7 +2692,9 @@ function getUpdateTrackExpenseParams(
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.reportID}`,
value: {
[transactionThread?.parentReportActionID ?? '']: {
whisperedToAccountIDs: [],
originalMessage: {
whisperedTo: [],
},
},
},
});
Expand Down Expand Up @@ -3949,7 +3956,7 @@ function createSplitsAndOnyxData(

let oneOnOneReportPreviewAction = getReportPreviewAction(oneOnOneChatReport.reportID, oneOnOneIOUReport.reportID);
if (oneOnOneReportPreviewAction) {
oneOnOneReportPreviewAction = ReportUtils.updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction);
oneOnOneReportPreviewAction = ReportUtils.updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction as ReportPreviewAction);
} else {
oneOnOneReportPreviewAction = ReportUtils.buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport);
}
Expand Down Expand Up @@ -4509,7 +4516,9 @@ function completeSplitBill(chatReportID: string, reportAction: OnyxTypes.ReportA
value: {
[reportAction.reportActionID]: {
lastModified: DateUtils.getDBTime(),
whisperedToAccountIDs: [],
originalMessage: {
whisperedTo: [],
},
},
},
},
Expand Down Expand Up @@ -4636,7 +4645,7 @@ function completeSplitBill(chatReportID: string, reportAction: OnyxTypes.ReportA

let oneOnOneReportPreviewAction = getReportPreviewAction(oneOnOneChatReport?.reportID ?? '', oneOnOneIOUReport?.reportID ?? '');
if (oneOnOneReportPreviewAction) {
oneOnOneReportPreviewAction = ReportUtils.updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction);
oneOnOneReportPreviewAction = ReportUtils.updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction as ReportPreviewAction);
} else {
oneOnOneReportPreviewAction = ReportUtils.buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport, '', oneOnOneTransaction);
}
Expand Down Expand Up @@ -4825,7 +4834,9 @@ function editRegularMoneyRequest(
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.reportID}`,
value: {
[transactionThread?.parentReportActionID ?? '']: {
whisperedToAccountIDs: [],
originalMessage: {
whisperedTo: [],
},
},
},
},
Expand All @@ -4834,7 +4845,9 @@ function editRegularMoneyRequest(
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.parentReportID}`,
value: {
[iouReport?.parentReportActionID ?? '']: {
whisperedToAccountIDs: [],
originalMessage: {
whisperedTo: [],
},
},
},
},
Expand Down Expand Up @@ -5673,7 +5686,7 @@ function getPayMoneyRequestParams(
let optimisticReportPreviewAction = null;
const reportPreviewAction = getReportPreviewAction(chatReport.reportID, iouReport.reportID);
if (reportPreviewAction) {
optimisticReportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction, true);
optimisticReportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction as ReportPreviewAction, true);
}

const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport.reportID}`] ?? null;
Expand Down
12 changes: 6 additions & 6 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -918,12 +918,12 @@ function ReportActionItem({
}

const hasErrors = !isEmptyObject(action.errors);
const whisperedToAccountIDs = action.whisperedToAccountIDs ?? [];
const isWhisper = whisperedToAccountIDs.length > 0;
const isMultipleParticipant = whisperedToAccountIDs.length > 1;
const isWhisperOnlyVisibleByUser = isWhisper && ReportUtils.isCurrentUserTheOnlyParticipant(whisperedToAccountIDs);
const whisperedTo = ReportActionsUtils.getWhisperedTo(action);
const isWhisper = whisperedTo.length > 0;
const isMultipleParticipant = whisperedTo.length > 1;
const isWhisperOnlyVisibleByUser = isWhisper && ReportUtils.isCurrentUserTheOnlyParticipant(whisperedTo);
const whisperedToPersonalDetails = isWhisper
? (Object.values(personalDetails ?? {}).filter((details) => whisperedToAccountIDs.includes(details?.accountID ?? -1)) as OnyxTypes.PersonalDetails[])
? (Object.values(personalDetails ?? {}).filter((details) => whisperedTo.includes(details?.accountID ?? -1)) as OnyxTypes.PersonalDetails[])
: [];
const displayNamesWithTooltips = isWhisper ? ReportUtils.getDisplayNamesWithTooltips(whisperedToPersonalDetails, isMultipleParticipant) : [];

Expand Down Expand Up @@ -993,7 +993,7 @@ function ReportActionItem({
&nbsp;
</Text>
<DisplayNames
fullTitle={ReportUtils.getWhisperDisplayNames(whisperedToAccountIDs) ?? ''}
fullTitle={ReportUtils.getWhisperDisplayNames(whisperedTo) ?? ''}
displayNamesWithTooltips={displayNamesWithTooltips}
tooltipEnabled
numberOfLines={1}
Expand Down
2 changes: 0 additions & 2 deletions src/pages/home/report/ReportActionsListItemRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ function ReportActionsListItemRenderer({
linkMetadata: reportAction.linkMetadata,
childReportID: reportAction.childReportID,
childLastVisibleActionCreated: reportAction.childLastVisibleActionCreated,
whisperedToAccountIDs: reportAction.whisperedToAccountIDs,
error: reportAction.error,
created: reportAction.created,
actorAccountID: reportAction.actorAccountID,
Expand Down Expand Up @@ -121,7 +120,6 @@ function ReportActionsListItemRenderer({
reportAction.linkMetadata,
reportAction.childReportID,
reportAction.childLastVisibleActionCreated,
reportAction.whisperedToAccountIDs,
reportAction.error,
reportAction.created,
reportAction.actorAccountID,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/home/report/reportActionPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export default {
originalMessage: PropTypes.shape({
// The ID of the iou transaction
IOUTransactionID: PropTypes.string,

/** accountIDs of the people to which the whisper was sent to (if any). Returns empty array if it is not a whisper */
whisperedTo: PropTypes.arrayOf(PropTypes.number),
}),

/** Error message that's come back from the server. */
error: PropTypes.string,

/** accountIDs of the people to which the whisper was sent to (if any). Returns empty array if it is not a whisper */
whisperedToAccountIDs: PropTypes.arrayOf(PropTypes.number),
};
5 changes: 5 additions & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type IOUMessage = {
deleted?: string;
/** Only exists when we are sending money */
IOUDetails?: IOUDetails;
whisperedTo?: number[];
};

type ReimbursementDeQueuedMessage = {
Expand Down Expand Up @@ -233,6 +234,7 @@ type OriginalMessageReportPreview = {
originalMessage: {
linkedReportID: string;
lastModified?: string;
whisperedTo?: number[];
};
};

Expand Down Expand Up @@ -290,6 +292,7 @@ type OriginalMessageModifiedExpense = {
taxRate?: string;
oldBillable?: string;
billable?: string;
whisperedTo?: number[];
};
};

Expand Down Expand Up @@ -385,6 +388,8 @@ export type {
OriginalMessageJoinPolicyChangeLog,
OriginalMessageActionableMentionWhisper,
OriginalMessageActionableReportMentionWhisper,
OriginalMessageReportPreview,
OriginalMessageModifiedExpense,
OriginalMessageChronosOOOList,
OriginalMessageRoomChangeLog,
OriginalMessageSource,
Expand Down
Loading
Loading