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
@@ -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