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

remove lastMessageTranslationKey from report collection #54295

4 changes: 1 addition & 3 deletions src/libs/DebugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1369,7 +1367,7 @@ function getReasonAndReportActionForRBRInLHNRow(report: Report, reportActions: O
}

function getTransactionID(report: OnyxEntry<Report>, reportActions: OnyxEntry<ReportActions>) {
const transactionID = TransactionUtils.getTransactionID(report?.reportID ?? '-1');
const transactionID = TransactionUtils.getTransactionID(report?.reportID);

return Number(transactionID) > 0
? transactionID
Expand Down
6 changes: 2 additions & 4 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -550,9 +549,8 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, 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);
Expand Down
2 changes: 0 additions & 2 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import StringUtils from './StringUtils';
import * as TransactionUtils from './TransactionUtils';

type LastVisibleMessage = {
lastMessageTranslationKey?: string;
lastMessageText: string;
lastMessageHtml?: string;
};
Expand Down Expand Up @@ -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,
};
Expand Down
12 changes: 4 additions & 8 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ type OptimisticChatReport = Pick<
| 'isOwnPolicyExpenseChat'
| 'isPinned'
| 'lastActorAccountID'
| 'lastMessageTranslationKey'
| 'lastMessageHtml'
| 'lastMessageText'
| 'lastReadTime'
Expand Down Expand Up @@ -5506,7 +5505,6 @@ function buildOptimisticChatReport(
isOwnPolicyExpenseChat,
isPinned: isNewlyCreatedWorkspaceChat,
lastActorAccountID: 0,
lastMessageTranslationKey: '',
lastMessageHtml: '',
lastMessageText: undefined,
lastReadTime: currentTime,
Expand Down Expand Up @@ -6301,12 +6299,12 @@ function isEmptyReport(report: OnyxEntry<Report>): boolean {
return true;
}

if (report.lastMessageText ?? report.lastMessageTranslationKey) {
if (report.lastMessageText) {
return false;
}

const lastVisibleMessage = getLastVisibleMessage(report.reportID);
return !lastVisibleMessage.lastMessageText && !lastVisibleMessage.lastMessageTranslationKey;
return !lastVisibleMessage.lastMessageText;
}

function isUnread(report: OnyxEntry<Report>): boolean {
Expand Down Expand Up @@ -8421,20 +8419,18 @@ function findPolicyExpenseChatByPolicyID(policyID: string): OnyxEntry<Report> {
*/
function getReportLastMessage(reportID: string, actionsToMerge?: ReportActions) {
let result: Partial<Report> = {
lastMessageTranslationKey: '',
lastMessageText: '',
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;
const lastActorAccountID = lastVisibleAction?.actorAccountID;
result = {
lastMessageTranslationKey,
lastMessageText,
lastVisibleActionCreated,
lastActorAccountID,
Expand Down
6 changes: 5 additions & 1 deletion src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,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}} : {}),
Expand Down Expand Up @@ -1185,7 +1184,6 @@ function buildOnyxDataForInvoice(
value: {
...chatReport,
lastReadTime: DateUtils.getDBTime(),
lastMessageTranslationKey: '',
iouReportID: iouReport.reportID,
...(isNewChatReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}),
},
Expand Down
22 changes: 6 additions & 16 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ function addActions(reportID: string, text = '', file?: FileObject) {

const optimisticReport: Partial<Report> = {
lastVisibleActionCreated: lastAction?.created,
lastMessageTranslationKey: lastComment?.translationKey ?? '',
lastMessageText: lastCommentText,
lastMessageHtml: lastCommentText,
lastActorAccountID: currentUserAccountID,
Expand Down Expand Up @@ -605,17 +604,15 @@ function addActions(reportID: string, text = '', file?: FileObject) {
];

let failureReport: Partial<Report> = {
lastMessageTranslationKey: '',
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;
failureReport = {
lastMessageTranslationKey,
lastMessageText,
lastVisibleActionCreated,
lastActorAccountID,
Expand Down Expand Up @@ -1555,19 +1552,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<Report> = {
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,
Expand Down Expand Up @@ -1774,7 +1769,6 @@ function editReportComment(reportID: string, originalReportAction: OnyxEntry<Rep
if (reportActionID === lastVisibleAction?.reportActionID) {
const lastMessageText = ReportUtils.formatReportLastMessageText(reportComment);
const optimisticReport = {
lastMessageTranslationKey: '',
lastMessageText,
};
optimisticData.push({
Expand Down Expand Up @@ -3862,20 +3856,18 @@ function prepareOnboardingOptimisticData(
}

let failureReport: Partial<Report> = {
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,
Expand Down Expand Up @@ -4177,7 +4169,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,
Expand Down Expand Up @@ -4252,7 +4243,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,
Expand Down
1 change: 0 additions & 1 deletion src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ function createTaskAndNavigate(
lastMessageText: lastCommentText,
lastActorAccountID: currentUserAccountID,
lastReadTime: currentTime,
lastMessageTranslationKey: '',
hasOutstandingChildTask: assigneeAccountID === currentUserAccountID ? true : parentReport?.hasOutstandingChildTask,
};

Expand Down
3 changes: 0 additions & 3 deletions src/types/onyx/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/types/utils/whitelistedReportKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback<
type: unknown;
visibility: unknown;
invoiceReceiver: unknown;
lastMessageTranslationKey: unknown;
parentReportID: unknown;
parentReportActionID: unknown;
managerID: unknown;
Expand Down
Loading