fix(forward): piggyback every nested level onto the outermost long-msg upload (NapCat model)
Cross-referenced `dev/NapCatQQ/.../SendMsg.uploadForwardedNodesPacket`
(208-347): every layer of a nested forward attaches its own msgBody to
the *outer* long-msg upload under a uuid `actionCommand` slot. Receiver
walks the whole tree from one server fetch instead of resolving each
layer's res_id separately.
`dev/Lagrange.Core` (V2 branch on `linwenxuan04/v2`,
`MultiMsgUploadService.cs:23-31`) only writes a single MultiMsg action
— that's why NapCat-style receivers couldn't follow our previous
nested-forward sends past the first level.
Refactor:
1. `ForwardNodePayload` gets an optional `innerForward?:
ForwardNodePayload[]` field. `parseForwardNodes` no longer eagerly
uploads inner chains — it just attaches them here.
2. `uploadForwardNodes` now drives the whole recursion. The new
`uploadForwardNodesRecursive`:
- walks each node, recursively uploads any `innerForward` first
- replaces that node's `elements` with a real `{type:'forward'}`
preview pointing at the inner res_id
- piggybacks the inner level's `{uuid, msgBody}` + every deeper
level it surfaced into this level's `myInnerActions`
- encodes the long-msg payload as
`[{MultiMsg, ownMsgBody}, ...innerActions.map(uuid+msgBody)]`
- returns `{resId, msgBody, uuid, innerActions}` so an outer call
can keep climbing
Top-level public signature unchanged: `Promise<string>`.
3. New `deriveInnerSource` / `previewLinesFromNodes` /
`previewFromElements` helpers synthesise the ARK preview metadata
the inner bubble shows before the user taps to expand. They handle
text/image/record/video/file/forward/face element previews.
4. `parseForwardNodes`: when `content` is an all-node array, attach
the parsed inner chain to `node.innerForward` and let the upload
pipeline take over. `elements = []` placeholder is replaced by
`uploadForwardNodes` once it has the real res_id.
Tests:
- `actions/forward.test.ts`:
- `uploadForwardNodes recursively uploads nested innerForward chains
(NapCat piggyback model)` — asserts two SsoSendLongMsg roundtrips
(inner first, then outer) and the outer res_id propagates up
- `flat sends still take a single roundtrip` — backwards-compat
- `onebot/forward-nested.test.ts`: rewritten — mock now sees exactly
one `uploadForwardNodes` call with `innerForward` attached, instead
of two sequential calls; depth-limit + mixed-content tests
unchanged.
This commit is contained in:
5 files changed
+289
-86
No files matched your search
@@ -83,6 +83,18 @@ export interface ForwardNodePayload {
|
||||
groupId?: number;
|
||||
senderCard?: string;
|
||||
messageType?: 'group' | 'private';
|
||||
// When set, this node's `content` is a nested forward chain. The
|
||||
// upload pipeline (see `actions/forward.ts::uploadForwardNodes`)
|
||||
// recursively uploads the inner chain and replaces this node's
|
||||
// `elements` with an ARK preview element pointing at the inner
|
||||
// res_id. We also piggyback the inner chain's msgBody onto the
|
||||
// outer long-msg upload as an extra `actionCommand` slot so the
|
||||
// NapCat-compatible receiver can walk the whole tree from one
|
||||
// server fetch without resolving each layer's res_id separately
|
||||
// (modelled after `dev/NapCatQQ/.../SendMsg.uploadForwardedNodesPacket`).
|
||||
// Caller never sets this on top-level OneBot input — `parseForward
|
||||
// Nodes` synthesises it when it detects a nested-node array.
|
||||
innerForward?: ForwardNodePayload[];
|
||||
}
|
||||
|
||||
export interface QQEvent {
|
||||
|
||||
Reference in new issue
Block a user