Skip to content

Commit

Permalink
Merge pull request #12968 from Expensify/aldo_lastMessageText
Browse files Browse the repository at this point in the history
Message html to text and last message (LHN) fixes
  • Loading branch information
MariaHCD authored Dec 2, 2022
2 parents c34e64c + efbc91d commit 7fd49bd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ const CONST = {
NON_NUMERIC: /\D/g,
EMOJI_NAME: /:[\w+-]+:/g,
EMOJI_SUGGESTIONS: /:[a-zA-Z]{1,20}(\s[a-zA-Z]{0,20})?$/,
AFTER_FIRST_LINE_BREAK: /\n.*/g,
},

PRONOUNS: {
Expand Down
4 changes: 3 additions & 1 deletion src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,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.AFTER_FIRST_LINE_BREAK, '')
.substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH);
}

/**
Expand Down
13 changes: 4 additions & 9 deletions src/pages/home/report/ReportActionItemFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <br /> 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, '<br />', ' ') === props.fragment.text;
if (differByLineBreaksOnly) {
const textWithLineBreaks = Str.replaceAll(props.fragment.html, '<br />', '\n');
html = textWithLineBreaks;
text = textWithLineBreaks;
}
const differByLineBreaksOnly = Str.replaceAll(html, '<br />', '\n') === text;

// Only render HTML if we have html in the fragment
if (html !== text) {
if (!differByLineBreaksOnly) {
const editedTag = props.fragment.isEdited ? '<edited></edited>' : '';
const htmlContent = html + editedTag;
return (
Expand Down

0 comments on commit 7fd49bd

Please sign in to comment.