Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last message text in LHN includes text and no space above quoted text #8814

Merged
merged 6 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -158,10 +157,8 @@ 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(/((<br[^>]*>)+)/gi, ' ')
.replace(/(<([^>]+)>)/gi, '');
const parser = new ExpensiMark();
lastMessageText = parser.htmlToText(lastActionMessage);
lastMessageText = ReportUtils.formatReportLastMessageText(lastMessageText);
}

Expand Down Expand Up @@ -548,9 +545,12 @@ function updateReportWithNewAction(
reportAction,
notificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
) {
const 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, 'text'], '');
: lodashGet(reportAction, ['message', 0, 'html'], '');

const parser = new ExpensiMark();
const messageText = parser.htmlToText(messageHtml);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Luke9389 thoughts on what changes we need to make now on the API side? I am removing this entire function in #9350... 🙃


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
Expand Down Expand Up @@ -948,7 +948,7 @@ function addAction(reportID, text, file) {

// Remove HTML from text when applying optimistic offline comment
const textForNewComment = isAttachment ? '[Attachment]'
: htmlForNewComment.replace(/((<br[^>]*>)+)/gi, ' ').replace(/<[^>]*>?/gm, '');
: parser.htmlToText(htmlForNewComment);

// Update the report in Onyx to have the new sequence number
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
Expand Down Expand Up @@ -1261,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(/((<br[^>]*>)+)/gi, ' '));
newReportAction.message[0].text = parser.htmlToText(htmlForNewComment);
actionToMerge[sequenceNumber] = newReportAction;
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, actionToMerge);

Expand Down
8 changes: 5 additions & 3 deletions src/libs/actions/ReportActions.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -103,13 +104,14 @@ function getDeletedCommentsCount(reportID, sequenceNumber) {
* @return {String}
*/
function getLastVisibleMessageText(reportID) {
const parser = new ExpensiMark();
const lastMessageIndex = _.findLastIndex(reportActions[reportID], action => (
!ReportActionsUtils.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 {
Expand Down