Integrate markdown unfurl policy into embed queue and edit flows.

Skips hub and emoji-only layouts, refreshes embeds when edit changes URL,
filters linkEmbedsByMessage by layout, and logs markdown-embed suppressions.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-06-02 20:22:26 -04:00
co-authored by Cursor
parent 743f6bfb37
commit 295f233bfb
2 changed files with 28 additions and 6 deletions
+26 -6
View File
@@ -259,6 +259,7 @@ const {
contentHasChannelMention,
extractFirstUrl,
extractUrls,
shouldUnfurlMessageLayout,
parsePearcordDeepLink,
ALLOWED_DEEP_LINK_KINDS,
validatePastedNavigationInput,
@@ -17429,9 +17430,20 @@ class PearcordPlatform extends EventEmitter {
if (prefs && (prefs.showLinkPreviews === false || prefs.linkPreviewsEnabled === false)) return
if (opts.composerPrefetch && this._composerImeComposing) return
if (this._readOnly) return
if (enrichMessageHubMirror(msg).hubMirror) return
if (!shouldUnfurlMessageLayout(messageLayoutKind(enrichMessageStickerNames(msg)))) return
const plain = this._messagePlaintext(msg)
const url = extractFirstUrl(plain)
if (!url) return
if (!url) {
if (/https?:\/\//i.test(plain)) {
this.log.debug('markdown-embed suppressed', {
spanKind: 'markdown-embed',
messageId: msg.id,
channelId: msg.channelId || this.activeChannelId || null
})
}
return
}
if (this._embedPrefetchCoalesce.has(url)) {
return this._embedPrefetchCoalesce.get(url)
}
@@ -21573,9 +21585,9 @@ class PearcordPlatform extends EventEmitter {
const priorLength = String(prior?.content || '').length
const msg = await this.messages.edit(messageId, content)
const nextPlain = this._messagePlaintext(msg)
const hadUrl = !!extractFirstUrl(priorPlain)
const hasUrl = !!extractFirstUrl(nextPlain)
if (hadUrl && !hasUrl && this.embeds?.clearForMessageContent) {
const priorUrl = extractFirstUrl(priorPlain)
const nextUrl = extractFirstUrl(nextPlain)
if (priorUrl && !nextUrl && this.embeds?.clearForMessageContent) {
const cleared = await this.embeds.clearForMessageContent(priorPlain).catch(() => null)
if (cleared?.hadUrl) {
this.log.debug('embed.clear on edit', {
@@ -21584,7 +21596,12 @@ class PearcordPlatform extends EventEmitter {
url: cleared.url
})
}
} else if (hasUrl && !hadUrl) {
} else if (nextUrl && priorUrl !== nextUrl) {
if (priorUrl && this.embeds?.clearForMessageContent) {
await this.embeds.clearForMessageContent(priorPlain).catch(() => null)
}
this._queueLinkEmbed(msg, { force: true }).catch(() => {})
} else if (nextUrl && !priorUrl) {
this._queueLinkEmbed(msg).catch(() => {})
}
if (this.mode === 'dm' && this.dm) this.dm.gossipMessageUpdate(msg)
@@ -23148,7 +23165,10 @@ class PearcordPlatform extends EventEmitter {
const linkEmbedsByMessage = {}
const embedResolveLatencyByMessage = {}
for (const m of messages) {
const plain = this._messagePlaintext(m)
const enrichedRow = enrichMessageRow(m)
if (!shouldUnfurlMessageLayout(messageLayoutKind(enrichedRow))) continue
if (enrichedRow.hubMirror) continue
const plain = this._messagePlaintext(enrichedRow)
const urls = extractUrls(plain, 3)
if (!urls.length || !this.embeds) continue
const rows = []