From 813adaa7c8ad185a5383494609ff77ab279202e7 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Tue, 17 Dec 2024 14:17:14 +0100 Subject: [PATCH 1/3] remove lastMessageTranslationKey from report --- src/libs/DebugUtils.ts | 2 -- src/libs/OptionsListUtils.ts | 6 ++---- src/libs/ReportUtils.ts | 6 +----- src/libs/actions/IOU.ts | 2 -- src/libs/actions/Report.ts | 17 ++++------------- src/types/onyx/Report.ts | 3 --- 6 files changed, 7 insertions(+), 29 deletions(-) diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 9343164db1e8..efcdad08072f 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -460,7 +460,6 @@ function validateReportDraftProperty(key: keyof Report, value: string) { case 'reportID': case 'chatReportID': case 'type': - case 'lastMessageTranslationKey': case 'parentReportID': case 'parentReportActionID': case 'lastVisibleActionLastModified': @@ -600,7 +599,6 @@ function validateReportDraftProperty(key: keyof Report, value: string) { writeCapability: CONST.RED_BRICK_ROAD_PENDING_ACTION, visibility: CONST.RED_BRICK_ROAD_PENDING_ACTION, invoiceReceiver: CONST.RED_BRICK_ROAD_PENDING_ACTION, - lastMessageTranslationKey: CONST.RED_BRICK_ROAD_PENDING_ACTION, parentReportID: CONST.RED_BRICK_ROAD_PENDING_ACTION, parentReportActionID: CONST.RED_BRICK_ROAD_PENDING_ACTION, managerID: CONST.RED_BRICK_ROAD_PENDING_ACTION, diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index a7f738790f92..cd2f914146de 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -7,7 +7,6 @@ import type {SetNonNullable} from 'type-fest'; import {FallbackAvatar} from '@components/Icon/Expensicons'; import type {IOUAction} from '@src/CONST'; import CONST from '@src/CONST'; -import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import type { Beta, @@ -541,9 +540,8 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails lastMessageTextFromReport = ReportUtils.getDeletedParentActionMessageForChatReport(lastReportAction); } else if (ReportActionUtils.isPendingRemove(lastReportAction) && ReportActionUtils.isThreadParentMessage(lastReportAction, report?.reportID ?? '-1')) { 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 - lastMessageTextFromReport = `[${Localize.translateLocal((report?.lastMessageTranslationKey || 'common.attachment') as TranslationPaths)}]`; + } else if (ReportUtils.isReportMessageAttachment({text: report?.lastMessageText ?? '-1', html: report?.lastMessageHtml, type: ''})) { + lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; } else if (ReportActionUtils.isModifiedExpenseAction(lastReportAction)) { const properSchemaForModifiedExpenseMessage = ModifiedExpenseMessage.getForReportAction(report?.reportID, lastReportAction); lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(properSchemaForModifiedExpenseMessage, true); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index eb728586f8f2..5a7c131fffa1 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -314,7 +314,6 @@ type OptimisticChatReport = Pick< | 'isOwnPolicyExpenseChat' | 'isPinned' | 'lastActorAccountID' - | 'lastMessageTranslationKey' | 'lastMessageHtml' | 'lastMessageText' | 'lastReadTime' @@ -5492,7 +5491,6 @@ function buildOptimisticChatReport( isOwnPolicyExpenseChat, isPinned: isNewlyCreatedWorkspaceChat, lastActorAccountID: 0, - lastMessageTranslationKey: '', lastMessageHtml: '', lastMessageText: undefined, lastReadTime: currentTime, @@ -6287,7 +6285,7 @@ function isEmptyReport(report: OnyxEntry): boolean { return true; } - if (report.lastMessageText ?? report.lastMessageTranslationKey) { + if (report.lastMessageText) { return false; } @@ -8407,7 +8405,6 @@ function findPolicyExpenseChatByPolicyID(policyID: string): OnyxEntry { */ function getReportLastMessage(reportID: string, actionsToMerge?: ReportActions) { let result: Partial = { - lastMessageTranslationKey: '', lastMessageText: '', lastVisibleActionCreated: '', }; @@ -8420,7 +8417,6 @@ function getReportLastMessage(reportID: string, actionsToMerge?: ReportActions) const lastVisibleActionCreated = lastVisibleAction?.created; const lastActorAccountID = lastVisibleAction?.actorAccountID; result = { - lastMessageTranslationKey, lastMessageText, lastVisibleActionCreated, lastActorAccountID, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 696853f49fd7..decc08f7b8c7 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -702,7 +702,6 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR value: { ...chat.report, lastReadTime: DateUtils.getDBTime(), - lastMessageTranslationKey: '', iouReportID: iou.report.reportID, ...outstandingChildRequest, ...(isNewChatReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}), @@ -1174,7 +1173,6 @@ function buildOnyxDataForInvoice( value: { ...chatReport, lastReadTime: DateUtils.getDBTime(), - lastMessageTranslationKey: '', iouReportID: iouReport.reportID, ...(isNewChatReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}), }, diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 7baf66adc5c5..00c49caae910 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -537,7 +537,6 @@ function addActions(reportID: string, text = '', file?: FileObject) { const optimisticReport: Partial = { lastVisibleActionCreated: lastAction?.created, - lastMessageTranslationKey: lastComment?.translationKey ?? '', lastMessageText: lastCommentText, lastMessageHtml: lastCommentText, lastActorAccountID: currentUserAccountID, @@ -606,7 +605,6 @@ function addActions(reportID: string, text = '', file?: FileObject) { ]; let failureReport: Partial = { - lastMessageTranslationKey: '', lastMessageText: '', lastVisibleActionCreated: '', }; @@ -616,7 +614,6 @@ function addActions(reportID: string, text = '', file?: FileObject) { const lastVisibleActionCreated = lastVisibleAction?.created; const lastActorAccountID = lastVisibleAction?.actorAccountID; failureReport = { - lastMessageTranslationKey, lastMessageText, lastVisibleActionCreated, lastActorAccountID, @@ -1548,19 +1545,17 @@ function deleteReportComment(reportID: string, reportAction: ReportAction) { // If we are deleting the last visible message, let's find the previous visible one (or set an empty one if there are none) and update the lastMessageText in the LHN. // Similarly, if we are deleting the last read comment we will want to update the lastVisibleActionCreated to use the previous visible message. let optimisticReport: Partial = { - lastMessageTranslationKey: '', lastMessageText: '', lastVisibleActionCreated: '', }; - const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportUtils.getLastVisibleMessage(originalReportID, optimisticReportActions as ReportActions); + const {lastMessageText = ''} = ReportUtils.getLastVisibleMessage(originalReportID, optimisticReportActions as ReportActions); const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(report); - if (lastMessageText || lastMessageTranslationKey) { + if (lastMessageText) { const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(originalReportID, canUserPerformWriteAction, optimisticReportActions as ReportActions); const lastVisibleActionCreated = lastVisibleAction?.created; const lastActorAccountID = lastVisibleAction?.actorAccountID; optimisticReport = { - lastMessageTranslationKey, lastMessageText, lastVisibleActionCreated, lastActorAccountID, @@ -3849,20 +3844,18 @@ function prepareOnboardingOptimisticData( } let failureReport: Partial = { - lastMessageTranslationKey: '', lastMessageText: '', lastVisibleActionCreated: '', hasOutstandingChildTask: false, }; const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${targetChatReportID}`]; const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(report); - const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportActionsUtils.getLastVisibleMessage(targetChatReportID, canUserPerformWriteAction); - if (lastMessageText || lastMessageTranslationKey) { + const {lastMessageText = ''} = ReportActionsUtils.getLastVisibleMessage(targetChatReportID, canUserPerformWriteAction); + if (lastMessageText) { const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(targetChatReportID, canUserPerformWriteAction); const prevLastVisibleActionCreated = lastVisibleAction?.created; const lastActorAccountID = lastVisibleAction?.actorAccountID; failureReport = { - lastMessageTranslationKey, lastMessageText, lastVisibleActionCreated: prevLastVisibleActionCreated, lastActorAccountID, @@ -4164,7 +4157,6 @@ function resolveActionableMentionWhisper(reportId: string, reportAction: OnyxEnt const reportUpdateDataWithPreviousLastMessage = ReportUtils.getReportLastMessage(reportId, optimisticReportActions as ReportActions); const reportUpdateDataWithCurrentLastMessage = { - lastMessageTranslationKey: report?.lastMessageTranslationKey, lastMessageText: report?.lastMessageText, lastVisibleActionCreated: report?.lastVisibleActionCreated, lastActorAccountID: report?.lastActorAccountID, @@ -4239,7 +4231,6 @@ function resolveActionableReportMentionWhisper( const reportUpdateDataWithPreviousLastMessage = ReportUtils.getReportLastMessage(reportId, optimisticReportActions as ReportActions); const reportUpdateDataWithCurrentLastMessage = { - lastMessageTranslationKey: report?.lastMessageTranslationKey, lastMessageText: report?.lastMessageText, lastVisibleActionCreated: report?.lastVisibleActionCreated, lastActorAccountID: report?.lastActorAccountID, diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index b89b6c8e0777..4c7909169fc4 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -148,9 +148,6 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< /** Invoice room receiver data */ invoiceReceiver?: InvoiceReceiver; - /** Translation key of the last message in the report */ - lastMessageTranslationKey?: string; - /** ID of the parent report of the current report, if it exists */ parentReportID?: string; From 2d070ad67b821bdea17f80d6d0074dcd51508f43 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Thu, 19 Dec 2024 14:18:28 +0100 Subject: [PATCH 2/3] remove key from whitelisted keys --- src/types/utils/whitelistedReportKeys.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types/utils/whitelistedReportKeys.ts b/src/types/utils/whitelistedReportKeys.ts index 015420683925..059453be47ba 100644 --- a/src/types/utils/whitelistedReportKeys.ts +++ b/src/types/utils/whitelistedReportKeys.ts @@ -33,7 +33,6 @@ type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback< type: unknown; visibility: unknown; invoiceReceiver: unknown; - lastMessageTranslationKey: unknown; parentReportID: unknown; parentReportActionID: unknown; managerID: unknown; From 38ad8c1c390ed27b88c2d672b10c20497c644271 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 20 Dec 2024 11:16:41 +0100 Subject: [PATCH 3/3] fix linter and remove appeared occurencies of a key --- src/libs/DebugUtils.ts | 2 +- src/libs/ReportActionsUtils.ts | 2 -- src/libs/ReportUtils.ts | 6 +++--- src/libs/TransactionUtils/index.ts | 6 +++++- src/libs/actions/Report.ts | 5 ++--- src/libs/actions/Task.ts | 1 - 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 011683b7af57..45ee00ac7823 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -1367,7 +1367,7 @@ function getReasonAndReportActionForRBRInLHNRow(report: Report, reportActions: O } function getTransactionID(report: OnyxEntry, reportActions: OnyxEntry) { - const transactionID = TransactionUtils.getTransactionID(report?.reportID ?? '-1'); + const transactionID = TransactionUtils.getTransactionID(report?.reportID); return Number(transactionID) > 0 ? transactionID diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index dd17adbda338..302ef2d6e478 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -33,7 +33,6 @@ import StringUtils from './StringUtils'; import * as TransactionUtils from './TransactionUtils'; type LastVisibleMessage = { - lastMessageTranslationKey?: string; lastMessageText: string; lastMessageHtml?: string; }; @@ -812,7 +811,6 @@ function getLastVisibleMessage( if (message && isReportMessageAttachment(message)) { return { - lastMessageTranslationKey: CONST.TRANSLATION_KEYS.ATTACHMENT, lastMessageText: CONST.ATTACHMENT_MESSAGE_TEXT, lastMessageHtml: CONST.TRANSLATION_KEYS.ATTACHMENT, }; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 22ad5749bcfa..7e0f983b3e9e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6304,7 +6304,7 @@ function isEmptyReport(report: OnyxEntry): boolean { } const lastVisibleMessage = getLastVisibleMessage(report.reportID); - return !lastVisibleMessage.lastMessageText && !lastVisibleMessage.lastMessageTranslationKey; + return !lastVisibleMessage.lastMessageText; } function isUnread(report: OnyxEntry): boolean { @@ -8423,9 +8423,9 @@ function getReportLastMessage(reportID: string, actionsToMerge?: ReportActions) lastVisibleActionCreated: '', }; - const {lastMessageText = '', lastMessageTranslationKey = ''} = getLastVisibleMessage(reportID, actionsToMerge); + const {lastMessageText = ''} = getLastVisibleMessage(reportID, actionsToMerge); - if (lastMessageText || lastMessageTranslationKey) { + if (lastMessageText) { const report = getReport(reportID); const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(reportID, canUserPerformWriteAction(report), actionsToMerge); const lastVisibleActionCreated = lastVisibleAction?.created; diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index 6643cd721d45..8bc1dd7356cb 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -1210,7 +1210,11 @@ function compareDuplicateTransactionFields( return {keep, change}; } -function getTransactionID(threadReportID: string): string | undefined { +function getTransactionID(threadReportID: string | undefined): string | undefined { + if (!threadReportID) { + return; + } + const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${threadReportID}`]; const parentReportAction = ReportUtils.isThread(report) ? ReportActionsUtils.getReportAction(report.parentReportID, report.parentReportActionID) : undefined; const IOUTransactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID : undefined; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 9af38f8a20e0..9f6081b8b330 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -607,8 +607,8 @@ function addActions(reportID: string, text = '', file?: FileObject) { lastMessageText: '', lastVisibleActionCreated: '', }; - const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportActionsUtils.getLastVisibleMessage(reportID); - if (lastMessageText || lastMessageTranslationKey) { + const {lastMessageText = ''} = ReportActionsUtils.getLastVisibleMessage(reportID); + if (lastMessageText) { const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(reportID); const lastVisibleActionCreated = lastVisibleAction?.created; const lastActorAccountID = lastVisibleAction?.actorAccountID; @@ -1761,7 +1761,6 @@ function editReportComment(reportID: string, originalReportAction: OnyxEntry