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:
5 files changed
+70
-98
No files matched your search
@@ -12,29 +12,6 @@ import type { JsonArray, JsonObject, JsonValue, MessageMeta } from '../types';
|
||||
|
||||
const log = createLogger('OneBot');
|
||||
|
||||
/**
|
||||
* message_id for a self-sent **c2c (private)** message.
|
||||
*
|
||||
* QQ-NT/Lagrange reference a c2c message in replies by the sender's
|
||||
* `clientSequence`, NOT the server sequence — Lagrange builds the reply source
|
||||
* as `OrigSeqs = ClientSequence != 0 ? ClientSequence : Sequence`
|
||||
* (`dev/Lagrange.Core/.../Message/Entity/ForwardEntity.cs`). So a self-sent
|
||||
* message MUST be keyed by `clientSequence`; otherwise an incoming reply's
|
||||
* resolved id (`hash(clientSequence, peer, private)`) never matches the stored
|
||||
* event and `get_msg` on the quoted message fails ("引用消息" can't be read,
|
||||
* even though replying still works because it only needs the meta row).
|
||||
*
|
||||
* Falls back to the server sequence when `clientSequence` is 0 (e.g. the c2c
|
||||
* file-send receipt), mirroring Lagrange's `||` exactly. Group messages do NOT
|
||||
* use this — their replies reference the (shared) group sequence.
|
||||
*/
|
||||
function c2cSelfMessageId(
|
||||
receipt: { sequence: number; clientSequence: number },
|
||||
userId: number,
|
||||
): number {
|
||||
return hashMessageIdInt32(receipt.clientSequence || receipt.sequence, userId, PRIVATE_MESSAGE_EVENT);
|
||||
}
|
||||
|
||||
export async function getGroupMsgHistory(
|
||||
messageStore: MessageStore,
|
||||
groupId: number,
|
||||
@@ -442,7 +419,7 @@ export async function sendPrivateMessage(
|
||||
}
|
||||
if (!lastReceipt) throw new Error('message is empty');
|
||||
|
||||
const messageId = c2cSelfMessageId(lastReceipt, userId);
|
||||
const messageId = hashMessageIdInt32(lastReceipt.sequence, userId, PRIVATE_MESSAGE_EVENT);
|
||||
ref.cacheMessageMeta(messageId, {
|
||||
isGroup: false,
|
||||
targetId: userId,
|
||||
@@ -608,7 +585,7 @@ export async function sendPrivateForwardMessage(
|
||||
const forwardId = await ref.bridge.apis.forward.upload(nodes, undefined, userId);
|
||||
const previewElement = buildForwardPreviewElement(forwardId, nodes, false, meta);
|
||||
const receipt = await ref.bridge.apis.message.sendPrivate(userId, [previewElement]);
|
||||
const messageId = c2cSelfMessageId(receipt, userId);
|
||||
const messageId = hashMessageIdInt32(receipt.sequence, userId, PRIVATE_MESSAGE_EVENT);
|
||||
|
||||
ref.cacheMessageMeta(messageId, {
|
||||
isGroup: false,
|
||||
@@ -695,7 +672,7 @@ export async function forwardSingleMessage(
|
||||
});
|
||||
} else {
|
||||
receipt = await ref.bridge.apis.message.sendPrivate(target.userId!, elements);
|
||||
messageIdOut = c2cSelfMessageId(receipt, target.userId!);
|
||||
messageIdOut = hashMessageIdInt32(receipt.sequence, target.userId!, PRIVATE_MESSAGE_EVENT);
|
||||
ref.cacheMessageMeta(messageIdOut, {
|
||||
isGroup: false,
|
||||
targetId: target.userId!,
|
||||
|
||||
Reference in new issue
Block a user