feat(m2d): strip per-message profile fallbacks from message content

Remove data-mx-profile-fallback elements from formatted_body and
displayname prefix from plain body when per-message profile is used.
This commit is contained in:
Bea
2026-03-25 03:10:54 +00:00
committed by cadence
parent 41692b11ff
commit a8b7d64e91
2 changed files with 77 additions and 0 deletions
+8
View File
@@ -803,6 +803,10 @@ async function eventToMessage(event, guild, channel, di) {
if (shouldProcessTextEvent) {
if (event.content.format === "org.matrix.custom.html" && event.content.formatted_body) {
let input = event.content.formatted_body
if (perMessageProfile?.has_fallback) {
// Strip fallback elements added for clients that don't support per-message profiles
input = input.replace(/<(\w+)[^>]*\bdata-mx-profile-fallback\b[^>]*>[^<]*<\/\1>/g, "")
}
if (event.content.msgtype === "m.emote") {
input = `* ${displayName} ${input}`
}
@@ -948,6 +952,10 @@ async function eventToMessage(event, guild, channel, di) {
} else {
// Looks like we're using the plaintext body!
content = event.content.body
if (perMessageProfile?.has_fallback && perMessageProfile.displayname && content.startsWith(perMessageProfile.displayname + ": ")) {
// Strip the display name prefix fallback added for clients that don't support per-message profiles
content = content.slice(perMessageProfile.displayname.length + 2)
}
if (event.content.msgtype === "m.emote") {
content = `* ${displayName} ${content}`