fix(onebot): restore nested chat record forwarding
Restore expansion and cross-chat forwarding for nested chat records that use preview-only cards. Return an error when nested content cannot be retrieved instead of producing an unusable message. Refs #589
This commit is contained in:
4 files changed
+231
-3
No files matched your search
@@ -107,6 +107,9 @@ function decodeCardData(data: Uint8Array, remainingOutputBytes: number) {
|
||||
return { ...decoded, budgetBytes: decoded.outputBytes };
|
||||
}
|
||||
|
||||
const MULTI_MSG_FILE_NAME_PATTERN =
|
||||
/^MultiMsg_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
|
||||
function isXmlCardContent(content: string): boolean {
|
||||
const trimmed = content.trim();
|
||||
return trimmed.startsWith('<') && trimmed.endsWith('>');
|
||||
@@ -143,9 +146,18 @@ function decodeRichMsgCard(
|
||||
// XML forwards link bundled inner messages by m_fileName, just as
|
||||
// LightApp forwards use uniseq. Keep it for the outer payload lookup.
|
||||
const fileName = rootAttributes?.get('m_fileName') || undefined;
|
||||
// Some nested previews have no downloadable resId. Their stable
|
||||
// MultiMsg_<UUID> filename identifies the bundled inner layer instead.
|
||||
const forwardId =
|
||||
resId ||
|
||||
(rootAttributes?.get('action') === 'viewMultiMsg' &&
|
||||
fileName &&
|
||||
MULTI_MSG_FILE_NAME_PATTERN.test(fileName)
|
||||
? fileName
|
||||
: undefined);
|
||||
return {
|
||||
element: resId
|
||||
? { type: 'forward', resId, forwardUuid: fileName }
|
||||
element: forwardId
|
||||
? { type: 'forward', resId: forwardId, forwardUuid: fileName }
|
||||
: { type: 'xml', text: content, subType: svcId },
|
||||
error: null,
|
||||
inputBytes: data.length,
|
||||
|
||||
@@ -106,6 +106,30 @@ describe('decodeRichBody / XML forward attributes', () => {
|
||||
},
|
||||
);
|
||||
|
||||
it.each([0, 35])(
|
||||
'uses a MultiMsg filename as the forward id when m_resid is absent (service=%s)',
|
||||
(serviceId) => {
|
||||
const uuid = 'C125CE25-AE7E-4E1A-ABDC-9750918162EB';
|
||||
const fileName = `MultiMsg_${uuid}`;
|
||||
const xml =
|
||||
'<msg serviceID="35" templateID="1" action="viewMultiMsg" ' +
|
||||
`m_fileName="${fileName}" tSum="2" flag="3" />`;
|
||||
expect(decodeRichBody(xmlCardBody(xml, serviceId), true)).toEqual([
|
||||
{ type: 'forward', resId: fileName, forwardUuid: fileName },
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
'<msg serviceID="35" action="viewMultiMsg" m_fileName="C125CE25-AE7E-4E1A-ABDC-9750918162EB" />',
|
||||
'<msg serviceID="35" action="viewMultiMsg" m_fileName="MultiMsg_not-a-uuid" />',
|
||||
'<msg serviceID="35" action="share" m_fileName="MultiMsg_C125CE25-AE7E-4E1A-ABDC-9750918162EB" />',
|
||||
])('preserves an unrecognised resid-less XML card: %s', (xml) => {
|
||||
expect(decodeRichBody(xmlCardBody(xml), true)).toEqual([
|
||||
{ type: 'xml', text: xml, subType: 0 },
|
||||
]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'<msg><title>serviceID="35" m_resid="fake"</title></msg>',
|
||||
'<msg><!-- serviceID="35" m_resid="fake" --></msg>',
|
||||
|
||||
Reference in new issue
Block a user