Skip to content

Commit

Permalink
Add ReportActionMessageJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaaron committed May 8, 2024
1 parent 5ab6a0f commit 5bdec60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 7 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,18 +143,20 @@ 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 this is true then we are using the new object version of reportAction.message
if (!Array.isArray(message) && typeof message === 'object') {
return ((message as {whisperedTo?: number[]})?.whisperedTo ?? []);
return ((message as ReportActionMessageJSON)?.whisperedTo ?? []);
}

// We are in the process of deprecating reportAction.originalMessage and will be sending the db version of "message" in the future see: https://github.com/Expensify/App/issues/39797
if (originalMessage) {
return ((originalMessage as {whisperedTo?: number[]})?.whisperedTo ?? []);
return ((originalMessage as ReportActionMessageJSON)?.whisperedTo ?? []);
}

return [];
Expand Down
6 changes: 5 additions & 1 deletion src/types/onyx/ReportAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import type OriginalMessage from './OriginalMessage';
import type {NotificationPreference} from './Report';
import type {Receipt} from './Transaction';

type ReportActionMessageJSON = {
whisperedTo?: number[];
};

type Message = {
/** The type of the action item fragment. Used to render a corresponding component */
type: string;
Expand Down Expand Up @@ -237,4 +241,4 @@ type ReportActions = Record<string, ReportAction>;
type ReportActionsCollectionDataSet = CollectionDataSet<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS>;

export default ReportAction;
export type {ReportActions, ReportActionBase, Message, LinkMetadata, OriginalMessage, ReportActionsCollectionDataSet, ReportPreviewAction, ModifiedExpenseAction};
export type {ReportActions, ReportActionBase, Message, LinkMetadata, OriginalMessage, ReportActionsCollectionDataSet, ReportPreviewAction, ModifiedExpenseAction, ReportActionMessageJSON};

0 comments on commit 5bdec60

Please sign in to comment.