Properly hide embeds for links in reply previews

This commit is contained in:
Cadence Ember
2025-12-11 12:46:28 +13:00
parent 653e38a9d2
commit 2563a47e78
3 changed files with 4 additions and 1 deletions

View File

@@ -370,6 +370,7 @@ async function messageToEvent(message, guild, options = {}, di) {
return `https://matrix.to/#/${oldestRow.room_id}/${event_id}?${via}`
} catch (e) {
// M_NOT_FOUND: Unable to find event from <ts> in direction Direction.FORWARDS
// not supported in Conduit and descendants
return `[unknown event, timestamp resolution failed, in room: https://matrix.to/#/${oldestRow.room_id}?${via}]`
}
}

View File

@@ -739,11 +739,11 @@ async function eventToMessage(event, guild, di) {
return convertEmoji(mxcUrlMatch?.[1], titleTextMatch?.[1], false, false)
})
repliedToContent = repliedToContent.replace(/<[^:>][^>]*>/g, "") // Completely strip all HTML tags and formatting.
repliedToContent = repliedToContent.replace(/\bhttps?:\/\/[^ )]*/g, "<$&>")
repliedToContent = entities.decodeHTML5Strict(repliedToContent) // Remove entities like &amp; &quot;
const contentPreviewChunks = chunk(repliedToContent, 50)
if (contentPreviewChunks.length) {
contentPreview = ": " + contentPreviewChunks[0]
contentPreview = contentPreview.replace(/\bhttps?:\/\/[^ )]*/g, "<$&>")
if (contentPreviewChunks.length > 1) contentPreview = contentPreview.replace(/[,.']$/, "") + "..."
} else {
contentPreview = ""

2
src/types.d.ts vendored
View File

@@ -221,6 +221,7 @@ export namespace Event {
filename?: string
url: string
info?: any
"page.codeberg.everypizza.msc4193.spoiler"?: boolean
"m.relates_to"?: {
"m.in_reply_to": {
event_id: string
@@ -238,6 +239,7 @@ export namespace Event {
format?: "org.matrix.custom.html"
formatted_body?: string
filename?: string
"page.codeberg.everypizza.msc4193.spoiler"?: boolean
file: {
url: string
iv: string