fix(protocol): collapse ark/card messages structurally, not by string match (#146)
Follow-up to the previous #146 fix, which dropped QQ's compat fallback text by content-matching the "版本不支持 … 升级" family. RE of the QQ kernel (wrapper.linux.node) showed that is not how QQ does it: - the receiver binary contains NONE of these fallback strings, so QQ cannot be matching by content; - the on-target wire is [lightApp, text(compat), generalFlags, extraInfo] and the text element has no distinguishing marker (no pbReserve / attr6Buf); - QQ NT's kernel codec (msg_codec_mgr) collapses the message to a single ark element — the sibling text is never emitted. NapCat maps kernel elements 1:1 with no ark-aware skip yet still surfaces only the card, confirming the kernel drops it upstream. Switch to that structural rule: when a lightApp/richMsg card is present, drop sibling plain text outright. It is version/locale-proof (won't break when Tencent rewords the string) and matches QQ NT + NapCat output exactly. @ mentions / replies / faces are not plain text and survive; QQ clients can't attach a caption to a card anyway, so no QQ-origin message loses real text. Verified live on a logged-in build: get_msg returns a single json segment.
This commit is contained in:
2 files changed
+39
-23
No files matched your search
@@ -30,27 +30,22 @@ 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.
|
||||
// [#146] A QQ mini-program / ark share (B站 video, QQ 小程序, …) arrives as a
|
||||
// `lightApp`/`richMsg` card element plus a plain `text` element carrying QQ's
|
||||
// graceful-degradation compat string ("当前QQ版本不支持此应用,请升级") — the text
|
||||
// protocol-old clients render instead of the card. The text element has NO wire
|
||||
// marker distinguishing it (confirmed on-target: no pbReserve / attr6Buf), and
|
||||
// the receiver binary contains none of these strings, so QQ does NOT match by
|
||||
// content. Instead QQ NT's kernel codec (msg_codec_mgr) collapses the message
|
||||
// to a single ark element — the sibling text is never emitted (verified by RE:
|
||||
// wrapper.linux.node has no fallback strings; NapCat maps kernel elements 1:1
|
||||
// with no ark-aware skip yet surfaces only the card). We mirror that structural
|
||||
// rule: when a card is present, drop sibling plain `text`. `@`/reply/face etc.
|
||||
// are not plain text and survive. `richMsg` covers json (svc=1) and xml (svc=35)
|
||||
// cards alike.
|
||||
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
|
||||
@@ -150,8 +145,9 @@ 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;
|
||||
// [#146] drop QQ's ark-compat fallback text — structurally, like the
|
||||
// kernel codec: a card message collapses to just the card element.
|
||||
if (text && hasCard) continue;
|
||||
if (text) result.push({ type: 'text', text });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,13 @@ describe('decodeRichBody / forward LightApp', () => {
|
||||
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)', () => {
|
||||
// RE of wrapper.linux.node confirmed QQ's kernel codec (msg_codec_mgr) has no
|
||||
// fallback strings and collapses a card message to a single ark element —
|
||||
// ANY sibling plain text is dropped, not just the known compat string. We
|
||||
// mirror that structural rule rather than content-matching (which would break
|
||||
// when Tencent reworded the string). NapCat shows the same: it maps kernel
|
||||
// elements 1:1, and the kernel already dropped the text.
|
||||
it('[#146] drops any sibling plain text beside a card (structural, matches QQ kernel)', () => {
|
||||
const body: MessageBody = {
|
||||
richText: {
|
||||
elems: [
|
||||
@@ -121,8 +127,22 @@ describe('decodeRichBody / forward LightApp', () => {
|
||||
},
|
||||
};
|
||||
const out = decodeRichBody(body, true);
|
||||
expect(out.map((e) => e.type)).toEqual(['json', 'text']);
|
||||
expect((out[1] as any).text).toBe('快看这个视频');
|
||||
expect(out.map((e) => e.type)).toEqual(['json']);
|
||||
});
|
||||
|
||||
// Scope guard: only PLAIN text is dropped beside a card. A real @ mention
|
||||
// (non-zero uin) is not plain text and must survive.
|
||||
it('[#146] keeps a genuine @ mention beside a card', () => {
|
||||
const body: MessageBody = {
|
||||
richText: {
|
||||
elems: [
|
||||
{ lightApp: { data: lightAppBytes({ app: 'com.tencent.miniapp_01', meta: {} }) } } as any,
|
||||
{ text: { str: '@someone', attr6Buf: new Uint8Array([0, 1, 0, 0, 0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78, 0]) } } as any,
|
||||
],
|
||||
},
|
||||
};
|
||||
const out = decodeRichBody(body, true);
|
||||
expect(out.map((e) => e.type)).toEqual(['json', 'at']);
|
||||
});
|
||||
|
||||
it('falls back to {type:"json"} when com.tencent.multimsg is missing resid (malformed)', () => {
|
||||
|
||||
Reference in new issue
Block a user