fix(protocol): drop QQ ark-compat fallback text beside mini-app cards (#146)

A QQ mini-program / ark share (B站 video, QQ 小程序, …) arrives on the wire
as a lightApp/richMsg ark element followed by a plain text element carrying
QQ's graceful-degradation compat string "当前QQ版本不支持此应用,请升级". That
text is meant only for protocol-old clients that can't render the card; QQ NT
and the kernel-backed bridges (NapCat) surface just the card.

On-target capture (test group) confirmed the text element has no distinguishing
wire marker (no pbReserve / attr6Buf) — it is a bare text sibling of the ark.
SnowLuma was decoding both, so every mini-app card came through as the card
plus a spurious "当前QQ版本不支持" text segment.

Drop the compat string when it sits beside a card, matched narrowly (the
"版本不支持 … 升级/更新" family, <=40 chars) so genuine user captions sent
alongside a card are preserved.

Verified live on a logged-in build: get_msg now returns a single json segment.
This commit is contained in:
DrSmoothl committed 2026-06-26 18:08:26 +08:00
1 parent 9de12db447
commit 319c7d607d
2 files changed
+64

No files matched your search

@@ -30,9 +30,28 @@ export function decodeRichBody(body: PushMsgBody | undefined, isGroup: boolean):
return elements;
}
// [#146] A QQ mini-program / ark share (B站 video, QQ 小程序, …) is sent as a
// `lightApp`/`richMsg` ark element plus a plain `text` element carrying QQ's
// graceful-degradation compat string ("当前QQ版本不支持此应用,请升级"). That text
// is what protocol-old clients render instead of the card; the text element has
// NO wire marker distinguishing it from real content (confirmed on-target: no
// pbReserve / attr6Buf). QQ NT and the kernel-backed bridges surface only the
// card. We mirror that by dropping the compat string when it sits beside a card,
// matched narrowly (the "版本不支持 … 升级/更新" family) so genuine user captions
// alongside a card are preserved.
const ARK_COMPAT_FALLBACK = /(版本.{0,4}不支持|不支持.{0,6}应用).*(升级|更新)/;
function isArkCompatFallback(s: string): boolean {
const t = s.trim();
return t.length > 0 && t.length <= 40 && ARK_COMPAT_FALLBACK.test(t);
}
function convertElements(elems: ElemDecoded[]): MessageElement[] {
const result: MessageElement[] = [];
let skipNext = false;
// [#146] Whether this message carries an ark/json card — gates dropping the
// QQ compat fallback text below. `richMsg` here covers both the json (svc=1)
// and xml (svc=35) cards; either way a sibling compat string is QQ's.
const hasCard = elems.some((e) => e.lightApp || e.richMsg);
// [#127] A QQ NT reply carries the replied sender as a structural auto-mention
// (MentionExtra.type=2, uin=0) right after srcMsg, followed by a blank
// separator text. Both are part of the reply wire shape, not user content —
@@ -131,6 +150,8 @@ function convertElements(elems: ElemDecoded[]): MessageElement[] {
result.push(me);
} else {
const text = t.str ?? '';
// [#146] drop QQ's ark-compat fallback text when a card is present.
if (text && hasCard && isArkCompatFallback(text)) continue;
if (text) result.push({ type: 'text', text });
}
}