diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 5bed8780c10a..58e7c0191f3f 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -362,7 +362,7 @@ function isPersonalDetailsReady(personalDetails: OnyxEntry) * Get the participant option for a report. */ function getParticipantsOption(participant: ReportUtils.OptionData | Participant, personalDetails: OnyxEntry): Participant { - const detail = getPersonalDetailsForAccountIDs([participant.accountID ?? -1], personalDetails)[participant.accountID ?? -1]; + const detail = participant.accountID ? getPersonalDetailsForAccountIDs([participant.accountID], personalDetails)[participant.accountID] : undefined; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const login = detail?.login || participant.login || ''; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -371,7 +371,7 @@ function getParticipantsOption(participant: ReportUtils.OptionData | Participant return { keyForList: String(detail?.accountID), login, - accountID: detail?.accountID ?? -1, + accountID: detail?.accountID, text: displayName, // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing firstName: (detail?.firstName || ('firstName' in participant ? participant.firstName : '')) ?? '', @@ -501,11 +501,11 @@ function getIOUReportIDOfLastAction(report: OnyxEntry): string | undefin * Get the last message text from the report directly or from other sources for special cases. */ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails: Partial | null, policy?: OnyxEntry): string { - const reportID = report?.reportID ?? '-1'; - const lastReportAction = lastVisibleReportActions[reportID] ?? null; + const reportID = report?.reportID; + const lastReportAction = reportID ? lastVisibleReportActions[reportID] : undefined; // some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action - const lastOriginalReportAction = lastReportActions[reportID] ?? null; + const lastOriginalReportAction = reportID ? lastReportActions[reportID] : undefined; let lastMessageTextFromReport = ''; if (report?.private_isArchived) { @@ -535,12 +535,12 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(properSchemaForMoneyRequestMessage); } else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) { const iouReport = ReportUtils.getReportOrDraftReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction)); - const lastIOUMoneyReportAction = allSortedReportActions[iouReport?.reportID ?? '-1']?.find( + const lastIOUMoneyReportAction = iouReport?.reportID ? allSortedReportActions[iouReport.reportID]?.find( (reportAction, key): reportAction is ReportAction => ReportActionUtils.shouldReportActionBeVisible(reportAction, key, ReportUtils.canUserPerformWriteAction(report)) && reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && ReportActionUtils.isMoneyRequestAction(reportAction), - ); + ) : undefined; const reportPreviewMessage = ReportUtils.getReportPreviewMessage( !isEmptyObject(iouReport) ? iouReport : null, lastIOUMoneyReportAction, @@ -557,7 +557,7 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails lastMessageTextFromReport = ReportUtils.getReimbursementDeQueuedActionMessage(lastReportAction, report, true); } else if (ReportActionUtils.isDeletedParentAction(lastReportAction) && ReportUtils.isChatReport(report)) { lastMessageTextFromReport = ReportUtils.getDeletedParentActionMessageForChatReport(lastReportAction); - } else if (ReportActionUtils.isPendingRemove(lastReportAction) && ReportActionUtils.isThreadParentMessage(lastReportAction, report?.reportID ?? '-1')) { + } else if (ReportActionUtils.isPendingRemove(lastReportAction) && report?.reportID && ReportActionUtils.isThreadParentMessage(lastReportAction, report.reportID)) { lastMessageTextFromReport = Localize.translateLocal('parentReportAction.hiddenMessage'); } else if (ReportUtils.isReportMessageAttachment({text: report?.lastMessageText ?? '-1', html: report?.lastMessageHtml, translationKey: report?.lastMessageTranslationKey, type: ''})) { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -700,7 +700,7 @@ function createOption( hasMultipleParticipants = personalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat || ReportUtils.isGroupChat(report); subtitle = ReportUtils.getChatRoomSubtitle(report); - const lastActorDetails = personalDetailMap[report.lastActorAccountID ?? -1] ?? null; + const lastActorDetails = report.lastActorAccountID ? personalDetailMap[report.lastActorAccountID] : null; const lastActorDisplayName = getLastActorDisplayName(lastActorDetails, hasMultipleParticipants); const lastMessageTextFromReport = getLastMessageTextForReport(report, lastActorDetails); let lastMessageText = lastMessageTextFromReport; @@ -915,7 +915,7 @@ function createOptionList(personalDetails: OnyxEntry, repor const allPersonalDetailsOptions = Object.values(personalDetails ?? {}).map((personalDetail) => ({ item: personalDetail, - ...createOption([personalDetail?.accountID ?? -1], personalDetails, reportMapForAccountIDs[personalDetail?.accountID ?? -1], {}, {showPersonalDetails: true}), + ...createOption([personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID], personalDetails, reportMapForAccountIDs[personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID], {}, {showPersonalDetails: true}), })); return {