fix(onebot): resolve c2c reply target by srcMsg friendSequence, not origSeqs

Replying to a bot self-sent private message still failed get_msg on the quoted
id ("无法解析申请信息"). Root cause is the reply DECODE, not the keying: for a
c2c (friend) reply the canonical replied-to sequence is carried in
srcMsg.pbReserve.friendSequence (tag 8), while origSeqs[0] holds the per-sender
clientSequence. The decoder read origSeqs[0], so the reply resolved to a
sequence that never matches how the original message is keyed (by its server /
private sequence) — get_msg missed. Mirrors Lagrange's incoming-reply rule
`Sequence = reserve.FriendSequence ?? OrigSeqs[0]` (ForwardEntity.cs +
SourceMsg.PbPreserve.cs ProtoMember(8)).

- proto-defs: +SrcMsgPbReserve { receiverUid@7, friendSequence@8 }
- protocol: decodeRichBody reads friendSequence for c2c replies (group keeps
  origSeqs[0], the shared group seq); fall back to origSeqs[0] when absent
- tests: c2c→friendSequence, group→origSeqs[0], no-reserve→fallback

This supersedes the keying approach in 4571864 (self-sent c2c keyed by
clientSequence), which is fully reverted here: the message is keyed by its
private sequence as before, and the fix is purely on the decode side so it also
covers replies to *received* old c2c messages, not just self-sent ones.
This commit is contained in:
DrSmoothl committed 2026-06-15 11:58:28 +08:00
1 parent 457186419f
commit cf8e62d2ac
5 files changed
+70 -98

No files matched your search

@@ -15,6 +15,7 @@ import { decodeRichBody } from '../../src/msg-push/rich-body-decoder';
import { buildSendElems } from '../../src/element-builder';
import type { MessageElement } from '../../src/events';
import type { MessageBody } from '@snowluma/proto-defs/message';
import type { SrcMsgPbReserve } from '@snowluma/proto-defs/element';
function lightAppBytes(json: unknown): Uint8Array {
const buf = deflateSync(Buffer.from(JSON.stringify(json), 'utf8'));
@@ -163,3 +164,42 @@ describe('decodeRichBody / market face', () => {
expect(decodeRichBody(decoded, true)).toEqual([el]);
});
});
// Reply identity for c2c: a friend's reply carries the per-sender
// clientSequence in srcMsg.origSeqs[0], but the *canonical* replied-to sequence
// (the one the original message is keyed by) is srcMsg.pbReserve.friendSequence.
// Reading origSeqs[0] made get_msg on the quoted message miss ("无法解析申请信息").
describe('decodeRichBody / reply uses friendSequence for c2c', () => {
const CLIENT_SEQ = 23188; // origSeqs[0] — per-sender clientSequence
const FRIEND_SEQ = 888; // pbReserve.friendSequence — canonical replied-to seq
function replyBody(): MessageBody {
return {
richText: {
elems: [
{
srcMsg: {
origSeqs: [CLIENT_SEQ],
pbReserve: protobuf_encode<SrcMsgPbReserve>({ friendSequence: FRIEND_SEQ }),
},
} as any,
],
},
};
}
it('c2c: replySeq = friendSequence, not origSeqs[0]', () => {
expect(decodeRichBody(replyBody(), false)).toContainEqual({ type: 'reply', replySeq: FRIEND_SEQ });
});
it('group: replySeq = origSeqs[0] (friendSequence ignored)', () => {
expect(decodeRichBody(replyBody(), true)).toContainEqual({ type: 'reply', replySeq: CLIENT_SEQ });
});
it('c2c without a reserve: falls back to origSeqs[0]', () => {
const body: MessageBody = {
richText: { elems: [{ srcMsg: { origSeqs: [CLIENT_SEQ] } } as any] },
};
expect(decodeRichBody(body, false)).toContainEqual({ type: 'reply', replySeq: CLIENT_SEQ });
});
});