From 29d6837e1d2be5dac9ec10deceb1d94bd282ef3f Mon Sep 17 00:00:00 2001 From: Mohammad Luthfi Fathur Rahman Date: Thu, 28 Apr 2022 01:27:41 +0700 Subject: [PATCH 1/5] update expensify-common --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index aff74f152689..a64603200ddc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23774,8 +23774,8 @@ } }, "expensify-common": { - "version": "git+https://github.com/Expensify/expensify-common.git#15237e012770048e8413dc08d4c36bc12304f3e8", - "from": "git+https://github.com/Expensify/expensify-common.git#15237e012770048e8413dc08d4c36bc12304f3e8", + "version": "git+https://github.com/Expensify/expensify-common.git#ba82405c287890e4e4987ed6333defc78dfcde9b", + "from": "git+https://github.com/Expensify/expensify-common.git#ba82405c287890e4e4987ed6333defc78dfcde9b", "requires": { "classnames": "2.3.1", "clipboard": "2.0.4", diff --git a/package.json b/package.json index 016aafef395c..00c370ebefc7 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", "dotenv": "^8.2.0", - "expensify-common": "git+https://github.com/Expensify/expensify-common.git#15237e012770048e8413dc08d4c36bc12304f3e8", + "expensify-common": "git+https://github.com/Expensify/expensify-common.git#ba82405c287890e4e4987ed6333defc78dfcde9b", "fbjs": "^3.0.2", "file-loader": "^6.0.0", "html-entities": "^1.3.1", From 042bb4619b2fee2852c69b287374cdf7ffcde706 Mon Sep 17 00:00:00 2001 From: Mohammad Luthfi Fathur Rahman Date: Thu, 28 Apr 2022 01:27:57 +0700 Subject: [PATCH 2/5] fix last message text in LHN includes text and no space above quoted text --- src/libs/actions/Report.js | 14 ++++++++------ src/libs/actions/ReportActions.js | 8 +++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 37d4c54cd2a4..849da2c06d11 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -197,10 +197,9 @@ function getSimplifiedReportObject(report) { if (report.reportActionCount > 0) { // We are removing any html tags from the message html since we cannot access the text version of any comments as // the report only has the raw reportActionList and not the processed version returned by Report_GetHistory - // We convert the line-breaks in html to space ' ' before striping the tags - lastMessageText = lastActionMessage - .replace(/((]*>)+)/gi, ' ') - .replace(/(<([^>]+)>)/gi, ''); + // We convert the line-breaks and blockquote closing tag in html to space ' ' before striping the tags + const parser = new ExpensiMark(); + lastMessageText = parser.htmlToText(lastActionMessage); lastMessageText = ReportUtils.formatReportLastMessageText(lastMessageText); } @@ -600,11 +599,14 @@ function updateReportWithNewAction( setLocalLastRead(reportID, newMaxSequenceNumber); } - let messageText = lodashGet(reportAction, ['message', 0, 'text'], ''); + let messageText = lodashGet(reportAction, ['message', 0, 'html'], ''); if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.RENAMED) { messageText = lodashGet(reportAction, 'originalMessage.html', ''); } + const parser = new ExpensiMark(); + messageText = parser.htmlToText(messageText); + // Always merge the reportID into Onyx // If the report doesn't exist in Onyx yet, then all the rest of the data will be filled out // by handleReportChanged @@ -1093,7 +1095,7 @@ function addAction(reportID, text, file) { // Remove HTML from text when applying optimistic offline comment const textForNewComment = isAttachment ? '[Attachment]' - : htmlForNewComment.replace(/((]*>)+)/gi, ' ').replace(/<[^>]*>?/gm, ''); + : parser.htmlToText(htmlForNewComment); // Update the report in Onyx to have the new sequence number Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, { diff --git a/src/libs/actions/ReportActions.js b/src/libs/actions/ReportActions.js index 780fe2f79e4e..90fd926af7fd 100644 --- a/src/libs/actions/ReportActions.js +++ b/src/libs/actions/ReportActions.js @@ -1,6 +1,7 @@ import _ from 'underscore'; import Onyx from 'react-native-onyx'; import lodashGet from 'lodash/get'; +import ExpensiMark from 'expensify-common/lib/ExpensiMark'; import ONYXKEYS from '../../ONYXKEYS'; import * as CollectionUtils from '../CollectionUtils'; import CONST from '../../CONST'; @@ -102,13 +103,14 @@ function getDeletedCommentsCount(reportID, sequenceNumber) { * @return {String} */ function getLastVisibleMessageText(reportID) { + const parser = new ExpensiMark(); const lastMessageIndex = _.findLastIndex(reportActions[reportID], action => ( !ReportUtils.isDeletedAction(action) )); + const htmlText = lodashGet(reportActions, [reportID, lastMessageIndex, 'message', 0, 'html'], ''); + const messageText = parser.htmlToText(htmlText); - return ReportUtils.formatReportLastMessageText( - lodashGet(reportActions, [reportID, lastMessageIndex, 'message', 0, 'text'], ''), - ); + return ReportUtils.formatReportLastMessageText(messageText); } export { From 02f8dccb68b7c200bfb298e042d301a1b181548a Mon Sep 17 00:00:00 2001 From: Mohammad Luthfi Fathur Rahman Date: Thu, 9 Jun 2022 19:50:53 +0700 Subject: [PATCH 3/5] renaming the variable --- src/libs/actions/Report.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 40c241f8be3f..aebc605b4011 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -547,12 +547,12 @@ function updateReportWithNewAction( reportAction, notificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, ) { - let messageText = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.RENAMED + const messageHtml = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.RENAMED ? lodashGet(reportAction, 'originalMessage.html', '') : lodashGet(reportAction, ['message', 0, 'html'], ''); const parser = new ExpensiMark(); - messageText = parser.htmlToText(messageText); + const messageText = parser.htmlToText(messageHtml); const updatedReportObject = { // Always merge the reportID into Onyx. If the report doesn't exist in Onyx yet, then all the rest of the data will be filled out by handleReportChanged From d23dc5fca6450e8c708879d721bf4a278821c941 Mon Sep 17 00:00:00 2001 From: Mohammad Luthfi Fathur Rahman Date: Thu, 9 Jun 2022 19:52:37 +0700 Subject: [PATCH 4/5] removing comment --- src/libs/actions/Report.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index aebc605b4011..227ede1bc952 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -158,7 +158,6 @@ function getSimplifiedReportObject(report) { if (report.reportActionCount > 0) { // We are removing any html tags from the message html since we cannot access the text version of any comments as // the report only has the raw reportActionList and not the processed version returned by Report_GetHistory - // We convert the line-breaks and blockquote closing tag in html to space ' ' before striping the tags const parser = new ExpensiMark(); lastMessageText = parser.htmlToText(lastActionMessage); lastMessageText = ReportUtils.formatReportLastMessageText(lastMessageText); From c6ab05c5d6bb5c0dcf302fcf5aa88108966e783a Mon Sep 17 00:00:00 2001 From: Mohammad Luthfi Fathur Rahman Date: Thu, 9 Jun 2022 20:26:22 +0700 Subject: [PATCH 5/5] replacing the Str.stripHtml --- src/libs/actions/Report.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 227ede1bc952..944dfccc18de 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -3,7 +3,6 @@ import moment from 'moment'; import _ from 'underscore'; import lodashGet from 'lodash/get'; import ExpensiMark from 'expensify-common/lib/ExpensiMark'; -import Str from 'expensify-common/lib/str'; import Onyx from 'react-native-onyx'; import ONYXKEYS from '../../ONYXKEYS'; import * as Pusher from '../Pusher/pusher'; @@ -1262,7 +1261,7 @@ function editReportComment(reportID, originalReportAction, textForNewComment) { const actionToMerge = {}; newReportAction.message[0].isEdited = true; newReportAction.message[0].html = htmlForNewComment; - newReportAction.message[0].text = Str.stripHTML(htmlForNewComment.replace(/((]*>)+)/gi, ' ')); + newReportAction.message[0].text = parser.htmlToText(htmlForNewComment); actionToMerge[sequenceNumber] = newReportAction; Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, actionToMerge);