From e9b4d01dfcf1d288f6bb8e5e4693f6aefd5ccbe6 Mon Sep 17 00:00:00 2001 From: Aldo Canepa Date: Wed, 23 Nov 2022 11:47:37 -0800 Subject: [PATCH 1/4] Collapse multiple consecutive spaces into a single space --- src/CONST.js | 1 + src/libs/ReportUtils.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CONST.js b/src/CONST.js index 99ea2aa8b02c..717a7b71a78f 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -752,6 +752,7 @@ const CONST = { NON_NUMERIC: /\D/g, EMOJI_NAME: /:[\w+-]+:/g, EMOJI_SUGGESTIONS: /:[a-zA-Z]{1,20}(\s[a-zA-Z]{0,20})?$/, + CONSECUTIVE_SPACES: /\s+/, }, PRONOUNS: { diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index b0035909d1d4..2b046f379c35 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -394,7 +394,9 @@ function canShowReportRecipientLocalTime(personalDetails, report) { * @returns {String} */ function formatReportLastMessageText(lastMessageText) { - return String(lastMessageText).substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH); + return String(lastMessageText) + .replace(CONST.REGEX.CONSECUTIVE_SPACES, ' ') + .substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH); } /** From 9f790f6b1222116e05b7c57b8e7da0005feb16e0 Mon Sep 17 00:00:00 2001 From: Aldo Canepa Date: Wed, 23 Nov 2022 12:17:24 -0800 Subject: [PATCH 2/4] Add global modifier --- src/CONST.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CONST.js b/src/CONST.js index 717a7b71a78f..fc8b71e953fd 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -752,7 +752,7 @@ const CONST = { NON_NUMERIC: /\D/g, EMOJI_NAME: /:[\w+-]+:/g, EMOJI_SUGGESTIONS: /:[a-zA-Z]{1,20}(\s[a-zA-Z]{0,20})?$/, - CONSECUTIVE_SPACES: /\s+/, + CONSECUTIVE_SPACES: /\s+/g, }, PRONOUNS: { From 79e8dd706f5760f398eaa1b94e2e2be97805fd6a Mon Sep 17 00:00:00 2001 From: Aldo Canepa Date: Tue, 29 Nov 2022 16:47:31 -0800 Subject: [PATCH 3/4] Use only first line for LHN last message. Simplify message rendering code. --- src/CONST.js | 2 +- src/libs/ReportUtils.js | 2 +- src/pages/home/report/ReportActionItemFragment.js | 13 ++++--------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index 63db38c0e444..60f8c05a25ad 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -755,7 +755,7 @@ const CONST = { NON_NUMERIC: /\D/g, EMOJI_NAME: /:[\w+-]+:/g, EMOJI_SUGGESTIONS: /:[a-zA-Z]{1,20}(\s[a-zA-Z]{0,20})?$/, - CONSECUTIVE_SPACES: /\s+/g, + AFTER_FIRST_LINE_BREAK: /\n.*/g, }, PRONOUNS: { diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index cf00b85ac600..cdd6fffac286 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -404,7 +404,7 @@ function canShowReportRecipientLocalTime(personalDetails, report) { */ function formatReportLastMessageText(lastMessageText) { return String(lastMessageText) - .replace(CONST.REGEX.CONSECUTIVE_SPACES, ' ') + .replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '') .substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH); } diff --git a/src/pages/home/report/ReportActionItemFragment.js b/src/pages/home/report/ReportActionItemFragment.js index 3d8fdb9c6e35..1be5c43e90de 100644 --- a/src/pages/home/report/ReportActionItemFragment.js +++ b/src/pages/home/report/ReportActionItemFragment.js @@ -98,20 +98,15 @@ const ReportActionItemFragment = (props) => { ) ); } - let {html, text} = props.fragment; + const {html, text} = props.fragment; // If the only difference between fragment.text and fragment.html is
tags - // we replace them with line breaks and render it as text, not as html. + // we render it as text, not as html. // This is done to render emojis with line breaks between them as text. - const differByLineBreaksOnly = Str.replaceAll(props.fragment.html, '
', ' ') === props.fragment.text; - if (differByLineBreaksOnly) { - const textWithLineBreaks = Str.replaceAll(props.fragment.html, '
', '\n'); - html = textWithLineBreaks; - text = textWithLineBreaks; - } + const differByLineBreaksOnly = Str.replaceAll(html, '
', '\n') === text; // Only render HTML if we have html in the fragment - if (html !== text) { + if (!differByLineBreaksOnly) { const editedTag = props.fragment.isEdited ? '' : ''; const htmlContent = html + editedTag; return ( From efbc91dc270dff5383eaeda6d1e13248f2a3f58c Mon Sep 17 00:00:00 2001 From: Aldo Canepa Date: Wed, 30 Nov 2022 12:03:35 -0800 Subject: [PATCH 4/4] Update expensify-common version --- package-lock.json | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index cba55e1f6f2b..47c2d473376f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,7 +38,7 @@ "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", "dotenv": "^8.2.0", - "expensify-common": "git+https://github.com/Expensify/expensify-common.git#db2c245c1e6b39232092b1415b9235fadda2a529", + "expensify-common": "git+https://github.com/Expensify/expensify-common.git#6bd112f1e7ebbd6679042fa04060104b68beace2", "fbjs": "^3.0.2", "file-loader": "^6.0.0", "html-entities": "^1.3.1", @@ -23861,8 +23861,8 @@ }, "node_modules/expensify-common": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#db2c245c1e6b39232092b1415b9235fadda2a529", - "integrity": "sha512-2FlkWOBJcLxWXUimYFu/Wa/0955YkCM5Wyd1+pwXYSjplQsoH4EHWJISfzHW85OhNbN8eOMmo8SOy3gHgwACAw==", + "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#6bd112f1e7ebbd6679042fa04060104b68beace2", + "integrity": "sha512-9KDdGIiV9aSZloy+lWtaBrZrrEwS+Fp9T8+KoWa6E+nrS+Y9kx55vRHGIPpDeMqFk8hMfaBiYwQ7/wQmc2ijeg==", "license": "MIT", "dependencies": { "classnames": "2.3.1", @@ -60824,9 +60824,9 @@ } }, "expensify-common": { - "version": "git+ssh://git@github.com/Expensify/expensify-common.git#db2c245c1e6b39232092b1415b9235fadda2a529", - "integrity": "sha512-2FlkWOBJcLxWXUimYFu/Wa/0955YkCM5Wyd1+pwXYSjplQsoH4EHWJISfzHW85OhNbN8eOMmo8SOy3gHgwACAw==", - "from": "expensify-common@git+https://github.com/Expensify/expensify-common.git#db2c245c1e6b39232092b1415b9235fadda2a529", + "version": "git+ssh://git@github.com/Expensify/expensify-common.git#6bd112f1e7ebbd6679042fa04060104b68beace2", + "integrity": "sha512-9KDdGIiV9aSZloy+lWtaBrZrrEwS+Fp9T8+KoWa6E+nrS+Y9kx55vRHGIPpDeMqFk8hMfaBiYwQ7/wQmc2ijeg==", + "from": "expensify-common@git+https://github.com/Expensify/expensify-common.git#6bd112f1e7ebbd6679042fa04060104b68beace2", "requires": { "classnames": "2.3.1", "clipboard": "2.0.4", diff --git a/package.json b/package.json index c9362fbaa66f..9602b22d3b70 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", "dotenv": "^8.2.0", - "expensify-common": "git+https://github.com/Expensify/expensify-common.git#db2c245c1e6b39232092b1415b9235fadda2a529", + "expensify-common": "git+https://github.com/Expensify/expensify-common.git#6bd112f1e7ebbd6679042fa04060104b68beace2", "fbjs": "^3.0.2", "file-loader": "^6.0.0", "html-entities": "^1.3.1",