From bdd902cdc95050adff2b132477c28a3398154ffb Mon Sep 17 00:00:00 2001 From: Shea Duma Date: Fri, 24 Apr 2026 08:12:49 +0300 Subject: [PATCH] add changeset --- src/app/components/editor/output.ts | 3 +++ src/app/components/message/MsgTypeRenderers.tsx | 9 ++++++--- src/app/features/room/RoomInput.tsx | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/app/components/editor/output.ts b/src/app/components/editor/output.ts index d6a7f1e0f..30ada92b6 100644 --- a/src/app/components/editor/output.ts +++ b/src/app/components/editor/output.ts @@ -198,6 +198,7 @@ const elementToPlainText = (node: CustomElement, children: string): string => { }; const SPOILERINPUTREGEX = /\|\|.+?\|\|/g; +//very loose link check with the empty text at the end to make sure it doesnt overextend const LINKINPUTREGEX = /?( |$|\))/g; /** @@ -319,7 +320,9 @@ export const getLinks = (editor: Editor): string[] | undefined => { let { text } = node; const urlsMatch = text.match(LINKINPUTREGEX); let urls = urlsMatch ? [...new Set(urlsMatch)] : undefined; + // clear the extra deadspace urls = urls?.map((url) => (url = url.replace(/(.+?)[ |)]/g, '$1'))); + // remove previews when so wanted urls = urls?.filter((url) => !(url.startsWith('<') && url.endsWith('>'))); finalList = finalList.concat(urls ?? []); return; diff --git a/src/app/components/message/MsgTypeRenderers.tsx b/src/app/components/message/MsgTypeRenderers.tsx index 87ad01f3c..29da77024 100644 --- a/src/app/components/message/MsgTypeRenderers.tsx +++ b/src/app/components/message/MsgTypeRenderers.tsx @@ -150,10 +150,13 @@ export function MText({ let urls = urlsMatch ? [...new Set(urlsMatch)] : undefined; bundleContent = content['com.beeper.linkpreviews'] as BundleContent[]; //small "fix" for if someone sends malformed objects (ie not arrays of objects) - try{ + try { bundleContent = bundleContent?.filter((bundle) => !!urls?.includes(bundle.matched_url)); - if (renderUrlsPreview && bundleContent) urls = bundleContent.map((bundle) => bundle.matched_url); - }catch{ urls = [];}; + if (renderUrlsPreview && bundleContent) + urls = bundleContent.map((bundle) => bundle.matched_url); + } catch { + urls = []; + } if ((content['com.beeper.per_message_profile'] as PerMessageProfileBeeperFormat)?.has_fallback) { // unwrap per-message profile fallback if present diff --git a/src/app/features/room/RoomInput.tsx b/src/app/features/room/RoomInput.tsx index 6fdb63266..fe6181868 100644 --- a/src/app/features/room/RoomInput.tsx +++ b/src/app/features/room/RoomInput.tsx @@ -805,8 +805,8 @@ export const RoomInput = forwardRef( content['m.mentions'] = getMentionContent(Array.from(mentionData.users), mentionData.room); - content["com.beeper.linkpreviews"] = []; - links?.forEach(link => content["com.beeper.linkpreviews"].push({'matched_url': link})); + content['com.beeper.linkpreviews'] = []; + links?.forEach((link) => content['com.beeper.linkpreviews'].push({ matched_url: link })); if (replyDraft || !customHtmlEqualsPlainText(formattedBody, body)) { content.format = 'org.matrix.custom.html';