From cf9d0af1e45cdb39b471e147bc857aa62bb79e2b Mon Sep 17 00:00:00 2001
From: Sobit Neupane <073bct543.sobit@pcampus.edu.np>
Date: Thu, 3 Feb 2022 21:40:43 +0545
Subject: [PATCH 1/4] Translate alternate text to Spanish

---
 src/components/OptionsList/BaseOptionsList.js | 7 ++++++-
 src/libs/OptionsListUtils.js                  | 1 +
 src/libs/actions/Report.js                    | 9 +++++++--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/components/OptionsList/BaseOptionsList.js b/src/components/OptionsList/BaseOptionsList.js
index e65b0034035a..65953c6417bd 100644
--- a/src/components/OptionsList/BaseOptionsList.js
+++ b/src/components/OptionsList/BaseOptionsList.js
@@ -7,6 +7,7 @@ import styles from '../../styles/styles';
 import OptionRow from '../../pages/home/sidebar/OptionRow';
 import SectionList from '../SectionList';
 import Text from '../Text';
+import * as Localize from '../../libs/Localize';
 import {propTypes as optionsListPropTypes, defaultProps as optionsListDefaultProps} from './optionsListPropTypes';
 
 const propTypes = {
@@ -97,9 +98,13 @@ class BaseOptionsList extends Component {
      * @return {Component}
      */
     renderItem({item, index, section}) {
+        const updatedItem = item;
+        if (item.isLastMessageAttachment) {
+            updatedItem.alternateText = `[${Localize.translateLocal('common.attachment')}]`;
+        }
         return (
             <OptionRow
-                option={item}
+                option={updatedItem}
                 mode={this.props.optionMode}
                 showTitleTooltip={this.props.showTitleTooltip}
                 backgroundColor={this.props.optionBackgroundColor}
diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js
index 17984bdbe36e..7daaace6e679 100644
--- a/src/libs/OptionsListUtils.js
+++ b/src/libs/OptionsListUtils.js
@@ -281,6 +281,7 @@ function createOption(personalDetailList, report, {
         iouReportAmount: lodashGet(iouReport, 'total', 0),
         isChatRoom,
         isArchivedRoom: ReportUtils.isArchivedRoom(report),
+        isLastMessageAttachment: showChatPreviewLine ? lodashGet(report, 'isLastMessageAttachment', false) : false,
     };
 }
 
diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js
index aff30887392d..cc0a5f3be9ce 100644
--- a/src/libs/actions/Report.js
+++ b/src/libs/actions/Report.js
@@ -216,7 +216,7 @@ function getSimplifiedReportObject(report) {
             'timestamp',
         ], 0),
         lastMessageTimestamp,
-        lastMessageText: isLastMessageAttachment ? '[Attachment]' : lastMessageText,
+        lastMessageText: isLastMessageAttachment ? Localize.translateLocal('common.attachment') : lastMessageText,
         lastActorEmail,
         hasOutstandingIOU: false,
         notificationPreference,
@@ -224,6 +224,7 @@ function getSimplifiedReportObject(report) {
         statusNum: report.status,
         oldPolicyName,
         visibility,
+        isLastMessageAttachment,
     };
 }
 
@@ -1106,12 +1107,16 @@ function addAction(reportID, text, file) {
     const textForNewComment = isAttachment ? '[Attachment]'
         : htmlForNewComment.replace(/((<br[^>]*>)+)/gi, ' ').replace(/<[^>]*>?/gm, '');
 
+    // Remove HTML from text when applying optimistic offline comment
+    const lastMessageText = isAttachment ? Localize.translateLocal('common.attachment') : htmlForNewComment.replace(/((<br[^>]*>)+)/gi, ' ').replace(/<[^>]*>?/gm, '');
+
     // Update the report in Onyx to have the new sequence number
     Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
         maxSequenceNumber: newSequenceNumber,
         lastMessageTimestamp: moment().unix(),
-        lastMessageText: ReportUtils.formatReportLastMessageText(textForNewComment),
+        lastMessageText: ReportUtils.formatReportLastMessageText(lastMessageText),
         lastActorEmail: currentUserEmail,
+        isLastMessageAttachment: isAttachment,
     });
 
     // Generate a clientID so we can save the optimistic action to storage with the clientID as key. Later, we will

From 64dab20a609f61fd8b606647eb249a712eeb0f78 Mon Sep 17 00:00:00 2001
From: Sobit Neupane <073bct543.sobit@pcampus.edu.np>
Date: Sun, 6 Feb 2022 19:22:59 +0545
Subject: [PATCH 2/4] Set alternateText to Attachment from OptionsListUtils if
 Attachment

---
 src/components/OptionsList/BaseOptionsList.js | 7 +------
 src/libs/OptionsListUtils.js                  | 4 ++--
 src/libs/actions/Report.js                    | 9 ++-------
 3 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/src/components/OptionsList/BaseOptionsList.js b/src/components/OptionsList/BaseOptionsList.js
index 65953c6417bd..e65b0034035a 100644
--- a/src/components/OptionsList/BaseOptionsList.js
+++ b/src/components/OptionsList/BaseOptionsList.js
@@ -7,7 +7,6 @@ import styles from '../../styles/styles';
 import OptionRow from '../../pages/home/sidebar/OptionRow';
 import SectionList from '../SectionList';
 import Text from '../Text';
-import * as Localize from '../../libs/Localize';
 import {propTypes as optionsListPropTypes, defaultProps as optionsListDefaultProps} from './optionsListPropTypes';
 
 const propTypes = {
@@ -98,13 +97,9 @@ class BaseOptionsList extends Component {
      * @return {Component}
      */
     renderItem({item, index, section}) {
-        const updatedItem = item;
-        if (item.isLastMessageAttachment) {
-            updatedItem.alternateText = `[${Localize.translateLocal('common.attachment')}]`;
-        }
         return (
             <OptionRow
-                option={updatedItem}
+                option={item}
                 mode={this.props.optionMode}
                 showTitleTooltip={this.props.showTitleTooltip}
                 backgroundColor={this.props.optionBackgroundColor}
diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js
index 7daaace6e679..2a2efd34e2e4 100644
--- a/src/libs/OptionsListUtils.js
+++ b/src/libs/OptionsListUtils.js
@@ -221,6 +221,7 @@ function createOption(personalDetailList, report, {
     const personalDetail = personalDetailList[0];
     const hasDraftComment = hasReportDraftComment(report);
     const hasOutstandingIOU = lodashGet(report, 'hasOutstandingIOU', false);
+    const isLastMessageAttachment = report ? ReportUtils.isReportMessageAttachment(report.lastMessageText) : false;
     const iouReport = hasOutstandingIOU
         ? lodashGet(iouReports, `${ONYXKEYS.COLLECTION.REPORT_IOUS}${report.iouReportID}`, {})
         : {};
@@ -230,7 +231,7 @@ function createOption(personalDetailList, report, {
         ? (hasMultipleParticipants && lastActorDetails
             ? `${lastActorDetails.displayName}: `
             : '')
-        + Str.htmlDecode(report.lastMessageText)
+        + (isLastMessageAttachment ? `[${Localize.translateLocal('common.attachment')}]` : Str.htmlDecode(report.lastMessageText))
         : '';
 
     const tooltipText = ReportUtils.getReportParticipantsTitle(lodashGet(report, ['participants'], []));
@@ -281,7 +282,6 @@ function createOption(personalDetailList, report, {
         iouReportAmount: lodashGet(iouReport, 'total', 0),
         isChatRoom,
         isArchivedRoom: ReportUtils.isArchivedRoom(report),
-        isLastMessageAttachment: showChatPreviewLine ? lodashGet(report, 'isLastMessageAttachment', false) : false,
     };
 }
 
diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js
index cc0a5f3be9ce..aff30887392d 100644
--- a/src/libs/actions/Report.js
+++ b/src/libs/actions/Report.js
@@ -216,7 +216,7 @@ function getSimplifiedReportObject(report) {
             'timestamp',
         ], 0),
         lastMessageTimestamp,
-        lastMessageText: isLastMessageAttachment ? Localize.translateLocal('common.attachment') : lastMessageText,
+        lastMessageText: isLastMessageAttachment ? '[Attachment]' : lastMessageText,
         lastActorEmail,
         hasOutstandingIOU: false,
         notificationPreference,
@@ -224,7 +224,6 @@ function getSimplifiedReportObject(report) {
         statusNum: report.status,
         oldPolicyName,
         visibility,
-        isLastMessageAttachment,
     };
 }
 
@@ -1107,16 +1106,12 @@ function addAction(reportID, text, file) {
     const textForNewComment = isAttachment ? '[Attachment]'
         : htmlForNewComment.replace(/((<br[^>]*>)+)/gi, ' ').replace(/<[^>]*>?/gm, '');
 
-    // Remove HTML from text when applying optimistic offline comment
-    const lastMessageText = isAttachment ? Localize.translateLocal('common.attachment') : htmlForNewComment.replace(/((<br[^>]*>)+)/gi, ' ').replace(/<[^>]*>?/gm, '');
-
     // Update the report in Onyx to have the new sequence number
     Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
         maxSequenceNumber: newSequenceNumber,
         lastMessageTimestamp: moment().unix(),
-        lastMessageText: ReportUtils.formatReportLastMessageText(lastMessageText),
+        lastMessageText: ReportUtils.formatReportLastMessageText(textForNewComment),
         lastActorEmail: currentUserEmail,
-        isLastMessageAttachment: isAttachment,
     });
 
     // Generate a clientID so we can save the optimistic action to storage with the clientID as key. Later, we will

From 6188268df7723dc8c2bb68b500717b2a653c60b7 Mon Sep 17 00:00:00 2001
From: sobitneupane <073bct543.sobit@pcampus.edu.np>
Date: Wed, 9 Feb 2022 19:14:49 +0545
Subject: [PATCH 3/4] Simplify ternary operator in lastMessageText

---
 src/libs/OptionsListUtils.js | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js
index 2a2efd34e2e4..f28cf96ed957 100644
--- a/src/libs/OptionsListUtils.js
+++ b/src/libs/OptionsListUtils.js
@@ -227,12 +227,11 @@ function createOption(personalDetailList, report, {
         : {};
 
     const lastActorDetails = report ? _.find(personalDetailList, {login: report.lastActorEmail}) : null;
-    const lastMessageText = report
-        ? (hasMultipleParticipants && lastActorDetails
-            ? `${lastActorDetails.displayName}: `
-            : '')
-        + (isLastMessageAttachment ? `[${Localize.translateLocal('common.attachment')}]` : Str.htmlDecode(report.lastMessageText))
+    const lastMessageTextFromReport = report && (isLastMessageAttachment ? `[${Localize.translateLocal('common.attachment')}]` : Str.htmlDecode(report.lastMessageText));
+    let lastMessageText = report && hasMultipleParticipants && lastActorDetails
+        ? `${lastActorDetails.displayName}: `
         : '';
+    lastMessageText += report ? lastMessageTextFromReport : '';
 
     const tooltipText = ReportUtils.getReportParticipantsTitle(lodashGet(report, ['participants'], []));
 

From 8ff224dd95b6b836b90e4138541708d17e933d0f Mon Sep 17 00:00:00 2001
From: sobitneupane <073bct543.sobit@pcampus.edu.np>
Date: Wed, 9 Feb 2022 20:55:16 +0545
Subject: [PATCH 4/4] Syntatic Change in lastMessageTextFromReport

---
 src/libs/OptionsListUtils.js | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js
index f28cf96ed957..f7a9e3441fbd 100644
--- a/src/libs/OptionsListUtils.js
+++ b/src/libs/OptionsListUtils.js
@@ -221,13 +221,14 @@ function createOption(personalDetailList, report, {
     const personalDetail = personalDetailList[0];
     const hasDraftComment = hasReportDraftComment(report);
     const hasOutstandingIOU = lodashGet(report, 'hasOutstandingIOU', false);
-    const isLastMessageAttachment = report ? ReportUtils.isReportMessageAttachment(report.lastMessageText) : false;
     const iouReport = hasOutstandingIOU
         ? lodashGet(iouReports, `${ONYXKEYS.COLLECTION.REPORT_IOUS}${report.iouReportID}`, {})
         : {};
 
     const lastActorDetails = report ? _.find(personalDetailList, {login: report.lastActorEmail}) : null;
-    const lastMessageTextFromReport = report && (isLastMessageAttachment ? `[${Localize.translateLocal('common.attachment')}]` : Str.htmlDecode(report.lastMessageText));
+    const lastMessageTextFromReport = ReportUtils.isReportMessageAttachment(lodashGet(report, 'lastMessageText', ''))
+        ? `[${Localize.translateLocal('common.attachment')}]`
+        : Str.htmlDecode(lodashGet(report, 'lastMessageText', ''));
     let lastMessageText = report && hasMultipleParticipants && lastActorDetails
         ? `${lastActorDetails.displayName}: `
         : '';
