diff --git a/packages/protocol/src/msg-push/rich-body-decoder.ts b/packages/protocol/src/msg-push/rich-body-decoder.ts index b93d5133..935e7514 100644 --- a/packages/protocol/src/msg-push/rich-body-decoder.ts +++ b/packages/protocol/src/msg-push/rich-body-decoder.ts @@ -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 }); } } diff --git a/packages/protocol/tests/msg-push/rich-body-decoder.test.ts b/packages/protocol/tests/msg-push/rich-body-decoder.test.ts index d304aa2d..43200ece 100644 --- a/packages/protocol/tests/msg-push/rich-body-decoder.test.ts +++ b/packages/protocol/tests/msg-push/rich-body-decoder.test.ts @@ -82,6 +82,49 @@ describe('decodeRichBody / forward LightApp', () => { expect(typeof (out[0] as any).text).toBe('string'); }); + // [#146] A QQ mini-program / ark share (e.g. a B站 video card) arrives as a + // `lightApp` ark element followed by a plain `text` element carrying QQ's + // graceful-degradation compat string ("当前QQ版本不支持此应用,请升级") — the + // text the protocol attaches for clients too old to render the ark. QQ NT and + // the kernel-backed bridges (NapCat) drop it and surface only the card. The + // captured wire is exactly: [lightApp, text(fallback), generalFlags, {}, extraInfo]. + it('[#146] drops QQ ark-compat fallback text sibling of a mini-app card', () => { + const ark = { + app: 'com.tencent.miniapp_01', + prompt: '[QQ小程序]【危机合约】平民3人50', + meta: { detail_1: { appid: '1109937557', title: '哔哩哔哩', desc: '【危机合约】平民3人50' } }, + }; + const body: MessageBody = { + richText: { + elems: [ + { lightApp: { data: lightAppBytes(ark) } } as any, + { text: { str: '当前QQ版本不支持此应用,请升级' } } as any, + { generalFlags: {} } as any, + {} as any, + { extraInfo: {} } as any, + ], + }, + }; + const out = decodeRichBody(body, true); + expect(out).toHaveLength(1); + expect(out[0]!.type).toBe('json'); + expect(JSON.parse((out[0] as any).text).meta.detail_1.title).toBe('哔哩哔哩'); + }); + + it('[#146] keeps genuine user text alongside a card (only the compat string is dropped)', () => { + const body: MessageBody = { + richText: { + elems: [ + { lightApp: { data: lightAppBytes({ app: 'com.tencent.miniapp_01', meta: {} }) } } as any, + { text: { str: '快看这个视频' } } as any, + ], + }, + }; + const out = decodeRichBody(body, true); + expect(out.map((e) => e.type)).toEqual(['json', 'text']); + expect((out[1] as any).text).toBe('快看这个视频'); + }); + it('falls back to {type:"json"} when com.tencent.multimsg is missing resid (malformed)', () => { const body: MessageBody = { richText: {