diff --git a/package-lock.json b/package-lock.json index b74e16153c26..256780e74aad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -59,7 +59,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "^2.0.12", + "expensify-common": "2.0.17", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", @@ -20770,9 +20770,9 @@ } }, "node_modules/expensify-common": { - "version": "2.0.12", - "resolved": "https://registry.npmjs.org/expensify-common/-/expensify-common-2.0.12.tgz", - "integrity": "sha512-idIm9mAGDX1qyfA2Ky/1ZJZVMbGydtpIdwl6zl1Yc7FO11IGvAYLh2cH9VsQk98AapRTiJu7QUaRWLLGDaHIcQ==", + "version": "2.0.17", + "resolved": "https://registry.npmjs.org/expensify-common/-/expensify-common-2.0.17.tgz", + "integrity": "sha512-W7xO10/bYF/p0/cUOtzejXJDiLCB/U6JTXVltzOE70xjGgzTSyRotPkEtEItHTvXOS2Wz8jJ262nrGfFMpfisA==", "dependencies": { "awesome-phonenumber": "^5.4.0", "classnames": "2.5.0", @@ -20786,8 +20786,7 @@ "react-dom": "16.12.0", "semver": "^7.6.0", "simply-deferred": "git+https://github.com/Expensify/simply-deferred.git#77a08a95754660c7bd6e0b6979fdf84e8e831bf5", - "ua-parser-js": "^1.0.37", - "underscore": "1.13.6" + "ua-parser-js": "^1.0.37" } }, "node_modules/expensify-common/node_modules/react": { diff --git a/package.json b/package.json index 3d18e0318dff..8f3b4d938168 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "^2.0.12", + "expensify-common": "2.0.17", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", diff --git a/src/libs/OnyxAwareParser.ts b/src/libs/OnyxAwareParser.ts index a202118bdf5f..c058775341c2 100644 --- a/src/libs/OnyxAwareParser.ts +++ b/src/libs/OnyxAwareParser.ts @@ -31,12 +31,22 @@ Onyx.connect({ }, }); -function parseHtmlToMarkdown(html: string, reportIDToName?: Record, accountIDToName?: Record): string { - return parser.htmlToMarkdown(html, {reportIDToName: reportIDToName ?? reportIDToNameMap, accountIDToName: accountIDToName ?? accountIDToNameMap}); +function parseHtmlToMarkdown( + html: string, + reportIDToName?: Record, + accountIDToName?: Record, + cacheVideoAttributes?: (videoSource: string, videoAttrs: string) => void, +): string { + return parser.htmlToMarkdown(html, {reportIDToName: reportIDToName ?? reportIDToNameMap, accountIDToName: accountIDToName ?? accountIDToNameMap, cacheVideoAttributes}); } -function parseHtmlToText(html: string, reportIDToName?: Record, accountIDToName?: Record): string { - return parser.htmlToText(html, {reportIDToName: reportIDToName ?? reportIDToNameMap, accountIDToName: accountIDToName ?? accountIDToNameMap}); +function parseHtmlToText( + html: string, + reportIDToName?: Record, + accountIDToName?: Record, + cacheVideoAttributes?: (videoSource: string, videoAttrs: string) => void, +): string { + return parser.htmlToText(html, {reportIDToName: reportIDToName ?? reportIDToNameMap, accountIDToName: accountIDToName ?? accountIDToNameMap, cacheVideoAttributes}); } export {parseHtmlToMarkdown, parseHtmlToText}; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 2349c9ae0d1e..d874933220a6 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1452,19 +1452,23 @@ function removeLinksFromHtml(html: string, links: string[]): string { * * @param newCommentText text of the comment after editing. * @param originalCommentMarkdown original markdown of the comment before editing. + * @param videoAttributeCache cache of video attributes ([videoSource]: videoAttributes) */ -function handleUserDeletedLinksInHtml(newCommentText: string, originalCommentMarkdown: string): string { +function handleUserDeletedLinksInHtml(newCommentText: string, originalCommentMarkdown: string, videoAttributeCache?: Record): string { const parser = new ExpensiMark(); if (newCommentText.length > CONST.MAX_MARKUP_LENGTH) { return newCommentText; } - const htmlForNewComment = parser.replace(newCommentText); + + const htmlForNewComment = parser.replace(newCommentText, { + extras: {videoAttributeCache}, + }); const removedLinks = parser.getRemovedMarkdownLinks(originalCommentMarkdown, newCommentText); return removeLinksFromHtml(htmlForNewComment, removedLinks); } /** Saves a new message for a comment. Marks the comment as edited, which will be reflected in the UI. */ -function editReportComment(reportID: string, originalReportAction: OnyxEntry, textForNewComment: string) { +function editReportComment(reportID: string, originalReportAction: OnyxEntry, textForNewComment: string, videoAttributeCache?: Record) { const parser = new ExpensiMark(); const originalReportID = ReportUtils.getOriginalReportID(reportID, originalReportAction); @@ -1482,8 +1486,8 @@ function editReportComment(reportID: string, originalReportAction: OnyxEntry video attributes +const draftMessageVideoAttributeCache = new Map(); + function ReportActionItemMessageEdit( {action, draftMessage, reportID, index, shouldDisableEmojiPicker = false}: ReportActionItemMessageEditProps, forwardedRef: ForwardedRef, @@ -105,7 +108,11 @@ function ReportActionItemMessageEdit( const isCommentPendingSaved = useRef(false); useEffect(() => { - const originalMessage = parseHtmlToMarkdown(action.message?.[0]?.html ?? ''); + draftMessageVideoAttributeCache.clear(); + + const originalMessage = parseHtmlToMarkdown(action.message?.[0]?.html ?? '', undefined, undefined, (videoSource, attrs) => { + draftMessageVideoAttributeCache.set(videoSource, attrs); + }); if (ReportActionsUtils.isDeletedAction(action) || !!(action.message && draftMessage === originalMessage) || !!(prevDraftMessage === draftMessage || isCommentPendingSaved.current)) { return; } @@ -296,7 +303,7 @@ function ReportActionItemMessageEdit( ReportActionContextMenu.showDeleteModal(reportID, action, true, deleteDraft, () => focusEditAfterCancelDelete(textInputRef.current)); return; } - Report.editReportComment(reportID, action, trimmedNewDraft); + Report.editReportComment(reportID, action, trimmedNewDraft, Object.fromEntries(draftMessageVideoAttributeCache)); deleteDraft(); }, [action, deleteDraft, draft, reportID]);