diff --git a/src/CONST.js b/src/CONST.js index 76910d5d8737..b6c6e7f18865 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -2525,6 +2525,9 @@ const CONST = { SETTINGS_LOUNGE_ACCESS: { HEADER_IMAGE_ASPECT_RATIO: 0.64, }, + TRANSLATION_KEYS: { + ATTACHMENT: 'common.attachment', + }, }; export default CONST; diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 82b517b9adbb..a36151fd0808 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -378,8 +378,8 @@ function getLastMessageTextForReport(report) { const lastReportAction = lastReportActions[report.reportID]; let lastMessageTextFromReport = ''; - if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { - lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; + if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml, translationKey: report.lastMessageTranslationKey})) { + lastMessageTextFromReport = `[${Localize.translateLocal(report.lastMessageTranslationKey || 'common.attachment')}]`; } else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) { const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction)); lastMessageTextFromReport = ReportUtils.getReportPreviewMessage(iouReport, lastReportAction); diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 9a280711e947..e83491a0c351 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -288,22 +288,28 @@ function getLastVisibleAction(reportID, actionsToMerge = {}) { /** * @param {String} reportID * @param {Object} [actionsToMerge] - * @return {String} + * @return {Object} */ -function getLastVisibleMessageText(reportID, actionsToMerge = {}) { +function getLastVisibleMessage(reportID, actionsToMerge = {}) { const lastVisibleAction = getLastVisibleAction(reportID, actionsToMerge); const message = lodashGet(lastVisibleAction, ['message', 0], {}); if (isReportMessageAttachment(message)) { - return CONST.ATTACHMENT_MESSAGE_TEXT; + return { + lastMessageTranslationKey: CONST.TRANSLATION_KEYS.ATTACHMENT, + }; } if (isCreatedAction(lastVisibleAction)) { - return ''; + return { + lastMessageText: '', + }; } const messageText = lodashGet(message, 'text', ''); - return String(messageText).replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim(); + return { + lastMessageText: String(messageText).replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim(), + }; } /** @@ -535,7 +541,7 @@ function isWhisperAction(action) { export { getSortedReportActions, getLastVisibleAction, - getLastVisibleMessageText, + getLastVisibleMessage, getMostRecentIOURequestActionID, extractLinksFromMessageHtml, isDeletedAction, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index a4b2e4796859..54c69c630714 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1324,6 +1324,7 @@ function buildOptimisticAddCommentReportAction(text, file) { created: DateUtils.getDBTime(), message: [ { + translationKey: isAttachment ? CONST.TRANSLATION_KEYS.ATTACHMENT : '', type: CONST.REPORT.MESSAGE.TYPE.COMMENT, html: htmlForNewComment, text: textForNewComment, @@ -1660,6 +1661,7 @@ function buildOptimisticChatReport( isOwnPolicyExpenseChat, isPinned: reportName === CONST.REPORT.WORKSPACE_CHAT_ROOMS.ADMINS, lastActorAccountID: 0, + lastMessageTranslationKey: '', lastMessageHtml: '', lastMessageText: null, lastReadTime: currentTime, diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 416597fc0c74..f53e07475aad 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -248,6 +248,7 @@ function addActions(reportID, text = '', file) { const optimisticReport = { lastVisibleActionCreated: currentTime, + lastMessageTranslationKey: lodashGet(lastAction, 'message[0].translationKey', ''), lastMessageText: lastCommentText, lastMessageHtml: lastCommentText, lastActorAccountID: currentUserAccountID, @@ -841,6 +842,7 @@ function deleteReportComment(reportID, reportAction) { const reportActionID = reportAction.reportActionID; const deletedMessage = [ { + translationKey: '', type: 'COMMENT', html: '', text: '', @@ -860,13 +862,15 @@ function deleteReportComment(reportID, 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 = { + lastMessageTranslationKey: '', lastMessageText: '', lastVisibleActionCreated: '', }; - const lastMessageText = ReportActionsUtils.getLastVisibleMessageText(originalReportID, optimisticReportActions); - if (lastMessageText.length > 0) { + const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportActionsUtils.getLastVisibleMessage(originalReportID, optimisticReportActions); + if (lastMessageText || lastMessageTranslationKey) { const lastVisibleActionCreated = ReportActionsUtils.getLastVisibleAction(originalReportID, optimisticReportActions).created; optimisticReport = { + lastMessageTranslationKey, lastMessageText, lastVisibleActionCreated, }; @@ -1026,6 +1030,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) { if (reportActionID === lastVisibleAction.reportActionID) { const lastMessageText = ReportUtils.formatReportLastMessageText(reportComment); const optimisticReport = { + lastMessageTranslationKey: '', lastMessageText, }; optimisticData.push({ diff --git a/src/libs/isReportMessageAttachment.js b/src/libs/isReportMessageAttachment.js index b449c72eaa0d..e107df8ddfaa 100644 --- a/src/libs/isReportMessageAttachment.js +++ b/src/libs/isReportMessageAttachment.js @@ -4,10 +4,14 @@ import CONST from '../CONST'; * Check whether a report action is Attachment or not. * Ignore messages containing [Attachment] as the main content. Attachments are actions with only text as [Attachment]. * - * @param {Object} reportActionMessage report action's message as text and html + * @param {Object} reportActionMessage report action's message as text, html and translationKey * @returns {Boolean} */ -export default function isReportMessageAttachment({text, html}) { +export default function isReportMessageAttachment({text, html, translationKey}) { + if (translationKey) { + return translationKey === CONST.TRANSLATION_KEYS.ATTACHMENT; + } + if (!text || !html) { return false; } diff --git a/tests/actions/ReportTest.js b/tests/actions/ReportTest.js index 88965d729a63..e896f7aca487 100644 --- a/tests/actions/ReportTest.js +++ b/tests/actions/ReportTest.js @@ -49,7 +49,7 @@ describe('actions/Report', () => { actorAccountID: TEST_USER_ACCOUNT_ID, automatic: false, avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_3.png', - message: [{type: 'COMMENT', html: 'Testing a comment', text: 'Testing a comment'}], + message: [{type: 'COMMENT', html: 'Testing a comment', text: 'Testing a comment', translationKey: ''}], person: [{type: 'TEXT', style: 'strong', text: 'Test User'}], shouldShow: true, };