Skip to content

Commit

Permalink
Merge pull request Expensify#49038 from tsa321/supportEmptyInlineCode
Browse files Browse the repository at this point in the history
Add support for inline code with space only characters
  • Loading branch information
deetergp authored Sep 26, 2024
2 parents 2e21203 + 81c3fbc commit b5a0a29
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
8 changes: 4 additions & 4 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 @@ -107,7 +107,7 @@
"date-fns-tz": "^2.0.0",
"dom-serializer": "^0.2.2",
"domhandler": "^4.3.0",
"expensify-common": "2.0.84",
"expensify-common": "2.0.88",
"expo": "51.0.31",
"expo-av": "14.0.7",
"expo-image": "1.12.15",
Expand Down
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ const CONST = {
MAX_PREVIEW_AVATARS: 4,
MAX_ROOM_NAME_LENGTH: 99,
LAST_MESSAGE_TEXT_MAX_LENGTH: 200,
MIN_LENGTH_LAST_MESSAGE_WITH_ELLIPSIS: 20,
OWNER_EMAIL_FAKE: '__FAKE__',
OWNER_ACCOUNT_ID_FAKE: 0,
DEFAULT_REPORT_NAME: 'Chat Report',
Expand Down
20 changes: 19 additions & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,11 @@ function isActionOfType<T extends ReportActionName[]>(

function getOriginalMessage<T extends ReportActionName>(reportAction: OnyxInputOrEntry<ReportAction<T>>): OriginalMessage<T> | undefined {
if (!Array.isArray(reportAction?.message)) {
// eslint-disable-next-line
return reportAction?.message ?? reportAction?.originalMessage;
}

// eslint-disable-next-line
return reportAction.originalMessage;
}

Expand Down Expand Up @@ -593,6 +596,7 @@ function isReportActionDeprecated(reportAction: OnyxEntry<ReportAction>, key: st

// HACK ALERT: We're temporarily filtering out any reportActions keyed by sequenceNumber
// to prevent bugs during the migration from sequenceNumber -> reportActionID
// eslint-disable-next-line
if (String(reportAction.sequenceNumber) === key) {
Log.info('Front-end filtered out reportAction keyed by sequenceNumber!', false, reportAction);
return true;
Expand Down Expand Up @@ -753,6 +757,18 @@ function getLastVisibleAction(reportID: string, actionsToMerge: Record<string, N
return sortedReportActions[0];
}

function formatLastMessageText(lastMessageText: string) {
const trimmedMessage = String(lastMessageText).trim();

// Add support for inline code containing only space characters
// The message will appear as a blank space in the LHN
if ((trimmedMessage === '' && lastMessageText.length > 0) || (trimmedMessage === '?\u2026' && lastMessageText.length > CONST.REPORT.MIN_LENGTH_LAST_MESSAGE_WITH_ELLIPSIS)) {
return ' ';
}

return StringUtils.lineBreaksToSpaces(trimmedMessage).substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim();
}

function getLastVisibleMessage(
reportID: string,
actionsToMerge: Record<string, NullishDeep<ReportAction> | null> = {},
Expand All @@ -777,7 +793,7 @@ function getLastVisibleMessage(

let messageText = getReportActionMessageText(lastVisibleAction) ?? '';
if (messageText) {
messageText = StringUtils.lineBreaksToSpaces(String(messageText)).substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim();
messageText = formatLastMessageText(messageText);
}
return {
lastMessageText: messageText,
Expand Down Expand Up @@ -1762,6 +1778,7 @@ function getCardIssuedMessage(reportAction: OnyxEntry<ReportAction>, shouldRende
export {
doesReportHaveVisibleActions,
extractLinksFromMessageHtml,
formatLastMessageText,
getActionableMentionWhisperMessage,
getAllReportActions,
getCombinedReportActions,
Expand All @@ -1784,6 +1801,7 @@ export {
getNumberOfMoneyRequests,
getOneTransactionThreadReportID,
getOriginalMessage,
// eslint-disable-next-line
getParentReportAction,
getRemovedFromApprovalChainMessage,
getReportAction,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ import * as PolicyUtils from './PolicyUtils';
import type {LastVisibleMessage} from './ReportActionsUtils';
import * as ReportActionsUtils from './ReportActionsUtils';
import * as ReportConnection from './ReportConnection';
import StringUtils from './StringUtils';
import * as TransactionUtils from './TransactionUtils';
import * as Url from './Url';
import type {AvatarSource} from './UserUtils';
Expand Down Expand Up @@ -1839,7 +1838,8 @@ function formatReportLastMessageText(lastMessageText: string, isModifiedExpenseM
if (isModifiedExpenseMessage) {
return String(lastMessageText).trim().replace(CONST.REGEX.LINE_BREAK, '').trim();
}
return StringUtils.lineBreaksToSpaces(String(lastMessageText).trim()).substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim();

return ReportActionsUtils.formatLastMessageText(lastMessageText);
}

/**
Expand Down

0 comments on commit b5a0a29

Please sign in to comment.