fix(onebot): keep synthetic sequences out of history

Distinguish QQ-authoritative message sequences from local message IDs so group files and reply placeholders cannot become history anchors or be reused by protocol actions.

Filter QQ null roam records and migrate previously stored synthetic rows.

Fixes #254
This commit is contained in:
DrSmoothl committed 2026-07-20 15:33:28 +08:00
1 parent 2c8a8af514
commit 4ba2b27398
17 files changed
+758 -45

No files matched your search

@@ -188,6 +188,7 @@ export const ELEMENT_CODECS = {
async fromSegment(data, options) {
const id = intOr(data.id, 0);
if (id === 0) return null;
const meta = options?.resolveReplyMeta?.(id) ?? null;
if (options?.resolveReplySequence) {
const resolved = options.resolveReplySequence(id);
@@ -199,19 +200,27 @@ export const ELEMENT_CODECS = {
};
// Try to get additional meta info for better reply display
if (options?.resolveReplyMeta) {
const meta = options.resolveReplyMeta(id);
if (meta) {
element.replySenderUin = meta.senderUin;
element.replyTime = meta.time;
element.replyRandom = meta.random;
}
if (meta) {
element.replySenderUin = meta.senderUin;
element.replyTime = meta.time;
element.replyRandom = meta.random;
}
return element;
}
}
// The id is known locally, but it came from an OIDB-only/synthetic
// message and therefore has no QQ server sequence. Treating the opaque
// OneBot id as a direct sequence would publish a malformed reply.
if (meta?.sequenceAuthoritative === false) {
throw new MessageElementValidationError(
'INVALID_FIELD',
`reply target ${id} has no authoritative QQ sequence`,
'reply',
);
}
// Backward-compatible path: allow direct seq reply IDs.
return id > 0 ? { type: 'reply', replySeq: id } : null;
},