Skip to content

Commit

Permalink
Merge pull request #21780 from tienifr/fix/19449-lhn-attachment-wrong…
Browse files Browse the repository at this point in the history
…-spanish-translation

Fix: Translation for system message
  • Loading branch information
yuwenmemon authored Jul 11, 2023
2 parents 746c0f4 + 4927f4b commit 12d54e8
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -2525,6 +2525,9 @@ const CONST = {
SETTINGS_LOUNGE_ACCESS: {
HEADER_IMAGE_ASPECT_RATIO: 0.64,
},
TRANSLATION_KEYS: {
ATTACHMENT: 'common.attachment',
},
};

export default CONST;
4 changes: 2 additions & 2 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 12 additions & 6 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
}

/**
Expand Down Expand Up @@ -535,7 +541,7 @@ function isWhisperAction(action) {
export {
getSortedReportActions,
getLastVisibleAction,
getLastVisibleMessageText,
getLastVisibleMessage,
getMostRecentIOURequestActionID,
extractLinksFromMessageHtml,
isDeletedAction,
Expand Down
2 changes: 2 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1660,6 +1661,7 @@ function buildOptimisticChatReport(
isOwnPolicyExpenseChat,
isPinned: reportName === CONST.REPORT.WORKSPACE_CHAT_ROOMS.ADMINS,
lastActorAccountID: 0,
lastMessageTranslationKey: '',
lastMessageHtml: '',
lastMessageText: null,
lastReadTime: currentTime,
Expand Down
9 changes: 7 additions & 2 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -841,6 +842,7 @@ function deleteReportComment(reportID, reportAction) {
const reportActionID = reportAction.reportActionID;
const deletedMessage = [
{
translationKey: '',
type: 'COMMENT',
html: '',
text: '',
Expand All @@ -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,
};
Expand Down Expand Up @@ -1026,6 +1030,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) {
if (reportActionID === lastVisibleAction.reportActionID) {
const lastMessageText = ReportUtils.formatReportLastMessageText(reportComment);
const optimisticReport = {
lastMessageTranslationKey: '',
lastMessageText,
};
optimisticData.push({
Expand Down
8 changes: 6 additions & 2 deletions src/libs/isReportMessageAttachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/actions/ReportTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down

0 comments on commit 12d54e8

Please sign in to comment.