fix(protocol): restore flat forward card compatibility (#467)
Restore ordinary forwarded-message cards while preserving nested forward navigation. Refs #467
This commit is contained in:
1 parent
89275ae279
commit
12afae0632
2 files changed
+81
-31
No files matched your search
@@ -347,26 +347,25 @@ describe('element-builder / file element is no longer carried in elems[]', () =>
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('element-builder / forward preview (com.tencent.multimsg LightApp)', () => {
|
describe('element-builder / forward preview', () => {
|
||||||
// The forward preview is the bubble the recipient renders in chat
|
// Flat outer forwards use the serviceID=35 RichMsg shape accepted by NTQQ.
|
||||||
// before tapping to expand. It MUST be the modern LightApp /
|
// Nested previews keep the modern LightApp JSON because their
|
||||||
// `com.tencent.multimsg` JSON (not the older `richMsg serviceID=35`
|
// meta.detail.uniseq must match an actionCommand piggyback in the outer
|
||||||
// XML) because nested forwards rely on `meta.detail.uniseq` to link
|
// LongMsgResult.
|
||||||
// each inner preview to the matching `actionCommand` piggyback on
|
|
||||||
// the outer's LongMsgResult — without uniseq the QQ-NT client has
|
|
||||||
// no way to walk the tree and has to re-fetch each inner resId.
|
|
||||||
function decodeLightApp(elem: any): unknown {
|
function decodeLightApp(elem: any): unknown {
|
||||||
return JSON.parse(inflatePrefixedPayload(elem.lightApp.data));
|
return JSON.parse(inflatePrefixedPayload(elem.lightApp.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
it('emits a lightApp.data blob with prefix=0x01 (deflated JSON, not XML/serviceID=35)', async () => {
|
it('emits a serviceID=35 richMsg XML for a flat outer forward', async () => {
|
||||||
const [elem] = await buildSendElems(
|
const [elem] = await buildSendElems(
|
||||||
[{ type: 'forward', resId: 'res-XYZ' } as any],
|
[{ type: 'forward', resId: 'res-XYZ' } as any],
|
||||||
{ bridge: fakeBridge, groupId: 12345 },
|
{ bridge: fakeBridge, groupId: 12345 },
|
||||||
);
|
);
|
||||||
expect(elem.lightApp).toBeDefined();
|
expect(elem.richMsg?.serviceId).toBe(35);
|
||||||
expect((elem as any).richMsg).toBeUndefined();
|
expect(elem.lightApp).toBeUndefined();
|
||||||
expect(elem.lightApp!.data![0]).toBe(0x01);
|
const xml = inflatePrefixedPayload(elem.richMsg!.template1!);
|
||||||
|
expect(xml).toContain('action="viewMultiMsg"');
|
||||||
|
expect(xml).toContain('m_resid="res-XYZ"');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('places resid + uniseq inside meta.detail (and uniseq matches extra.filename)', async () => {
|
it('places resid + uniseq inside meta.detail (and uniseq matches extra.filename)', async () => {
|
||||||
@@ -374,6 +373,8 @@ describe('element-builder / forward preview (com.tencent.multimsg LightApp)', ()
|
|||||||
[{ type: 'forward', resId: 'res-XYZ', forwardUuid: 'fixed-uuid-1234' } as any],
|
[{ type: 'forward', resId: 'res-XYZ', forwardUuid: 'fixed-uuid-1234' } as any],
|
||||||
{ bridge: fakeBridge, groupId: 12345 },
|
{ bridge: fakeBridge, groupId: 12345 },
|
||||||
);
|
);
|
||||||
|
expect(elem.lightApp).toBeDefined();
|
||||||
|
expect(elem.richMsg).toBeUndefined();
|
||||||
const json = decodeLightApp(elem) as any;
|
const json = decodeLightApp(elem) as any;
|
||||||
expect(json.app).toBe('com.tencent.multimsg');
|
expect(json.app).toBe('com.tencent.multimsg');
|
||||||
expect(json.meta.detail.resid).toBe('res-XYZ');
|
expect(json.meta.detail.resid).toBe('res-XYZ');
|
||||||
@@ -384,17 +385,40 @@ describe('element-builder / forward preview (com.tencent.multimsg LightApp)', ()
|
|||||||
expect(extra.filename).toBe('fixed-uuid-1234');
|
expect(extra.filename).toBe('fixed-uuid-1234');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('autogenerates a uniseq when the element omits forwardUuid (flat forward — cosmetic)', async () => {
|
it('autogenerates m_fileName for a flat outer forward', async () => {
|
||||||
const [elem] = await buildSendElems(
|
const [elem] = await buildSendElems(
|
||||||
[{ type: 'forward', resId: 'res-flat' } as any],
|
[{ type: 'forward', resId: 'res-flat' } as any],
|
||||||
{ bridge: fakeBridge, groupId: 12345 },
|
{ bridge: fakeBridge, groupId: 12345 },
|
||||||
);
|
);
|
||||||
const json = decodeLightApp(elem) as any;
|
const xml = inflatePrefixedPayload(elem.richMsg!.template1!);
|
||||||
expect(json.meta.detail.resid).toBe('res-flat');
|
expect(xml).toContain('m_resid="res-flat"');
|
||||||
// Auto-generated UUID — non-empty, non-trivial.
|
expect(xml).toMatch(/m_fileName="[0-9a-f-]{36}"/i);
|
||||||
expect(json.meta.detail.uniseq).toMatch(/^[0-9a-f-]{36}$/i);
|
});
|
||||||
const extra = JSON.parse(json.extra);
|
|
||||||
expect(extra.filename).toBe(json.meta.detail.uniseq);
|
it('escapes dynamic XML fields in a flat outer forward', async () => {
|
||||||
|
const [elem] = await buildSendElems(
|
||||||
|
[{
|
||||||
|
type: 'forward',
|
||||||
|
resId: 'res&<>"\'',
|
||||||
|
forwardSource: 'Alice & <Bob>',
|
||||||
|
forwardSummary: 'summary "quoted" & more',
|
||||||
|
forwardPrompt: '[A & B]',
|
||||||
|
forwardNews: [
|
||||||
|
{ text: 'Alice: <hello>' },
|
||||||
|
{ text: 'Bob: it\'s "ok"' },
|
||||||
|
],
|
||||||
|
forwardTSum: 2,
|
||||||
|
} as any],
|
||||||
|
{ bridge: fakeBridge, groupId: 12345 },
|
||||||
|
);
|
||||||
|
const xml = inflatePrefixedPayload(elem.richMsg!.template1!);
|
||||||
|
expect(xml).toContain('m_resid="res&<>"'"');
|
||||||
|
expect(xml).toContain('brief="[A & B]"');
|
||||||
|
expect(xml).toContain('Alice & <Bob>');
|
||||||
|
expect(xml).toContain('summary "quoted" & more');
|
||||||
|
expect(xml).toContain('Alice: <hello>');
|
||||||
|
expect(xml).toContain('Bob: it's "ok"');
|
||||||
|
expect(xml).toContain('tSum="2"');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threads forwardSource / forwardSummary / forwardPrompt / forwardNews / forwardTSum verbatim', async () => {
|
it('threads forwardSource / forwardSummary / forwardPrompt / forwardNews / forwardTSum verbatim', async () => {
|
||||||
|
|||||||
@@ -265,16 +265,24 @@ function makeMarketFaceElem(element: MessageElement): ProtoElem {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeXml(value: string): string {
|
||||||
|
return value
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, ''');
|
||||||
|
}
|
||||||
|
|
||||||
function makeForwardElem(element: MessageElement): ProtoElem {
|
function makeForwardElem(element: MessageElement): ProtoElem {
|
||||||
const resId = (element.resId ?? '').trim();
|
const resId = (element.resId ?? '').trim();
|
||||||
if (!resId) {
|
if (!resId) {
|
||||||
throw new Error('forward resId is required');
|
throw new Error('forward resId is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
// `uniseq` MUST round-trip between the preview JSON and the outer
|
// Nested forwards must round-trip this value between the LightApp preview
|
||||||
// upload's piggyback `actionCommand` for nested forwards to resolve
|
// and the outer upload's piggyback `actionCommand`. Flat forwards have no
|
||||||
// without an extra server hit. Generate one fresh if absent (flat
|
// piggyback entry and use the generated value as the RichMsg `m_fileName`.
|
||||||
// forwards don't piggyback anyway, so the value is cosmetic there).
|
|
||||||
const uniseq = (element.forwardUuid ?? '').trim() || randomUUID();
|
const uniseq = (element.forwardUuid ?? '').trim() || randomUUID();
|
||||||
|
|
||||||
const source = element.forwardSource && element.forwardSource.length > 0
|
const source = element.forwardSource && element.forwardSource.length > 0
|
||||||
@@ -291,14 +299,32 @@ function makeForwardElem(element: MessageElement): ProtoElem {
|
|||||||
? element.forwardTSum
|
? element.forwardTSum
|
||||||
: Math.max(news.length, 1);
|
: Math.max(news.length, 1);
|
||||||
|
|
||||||
// LightApp / `com.tencent.multimsg` is the modern wire shape both
|
// Flat outer forwards use serviceID=35 RichMsg. Nested previews keep
|
||||||
// QQ-NT, Lagrange.Core, and NapCat emit and decode. The older
|
// LightApp because their forwardUuid must match a piggyback actionCommand
|
||||||
// `richMsg serviceID=35 m_resid=…` XML still renders on mobile QQ
|
// in the outer long-message body.
|
||||||
// but it doesn't carry `uniseq`, so nested forwards lose the link
|
if (!element.forwardUuid) {
|
||||||
// between the inner preview and the piggybacked actions on the
|
const titles = news.map((item) =>
|
||||||
// outer's LongMsgResult — cross-checked against
|
'<title color="#777777" size="26">' + escapeXml(item.text ?? '') + '</title>',
|
||||||
// `dev/Lagrange.Core/.../Message/Entity/MultiMsgEntity.cs:43-115`
|
).join('');
|
||||||
// and `dev/NapCatQQ/.../helper/forward-msg-builder.ts:52-122`.
|
const xml = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?> "
|
||||||
|
+ '<msg serviceID="35" templateID="1" action="viewMultiMsg"'
|
||||||
|
+ ' brief="' + escapeXml(prompt) + '"'
|
||||||
|
+ ' m_fileName="' + escapeXml(uniseq) + '"'
|
||||||
|
+ ' m_resid="' + escapeXml(resId) + '"'
|
||||||
|
+ ' tSum="' + tSum + '" flag="3">'
|
||||||
|
+ '<item layout="1"> '
|
||||||
|
+ '<title color="#000000" size="34">' + escapeXml(source) + '</title>'
|
||||||
|
+ titles
|
||||||
|
+ ' <hr></hr> <summary color="#808080">' + escapeXml(summary) + '</summary>'
|
||||||
|
+ '</item> <source name="' + escapeXml(source) + '"></source> </msg>';
|
||||||
|
return {
|
||||||
|
richMsg: {
|
||||||
|
template1: makeDeflatedPayload(xml),
|
||||||
|
serviceId: 35,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const lightApp = {
|
const lightApp = {
|
||||||
app: 'com.tencent.multimsg',
|
app: 'com.tencent.multimsg',
|
||||||
config: {
|
config: {
|
||||||
|
|||||||
Reference in new issue
Block a user