fix(onebot): align private quote ids with send receipts

Quotes of bot-sent private messages used a different sequence than
the send receipt, so reply.id and send_private_msg disagreed. Resolve
those quotes to the stored send id by send time when the quoted
sequence does not match.

Fixes #433
This commit is contained in:
DrSmoothl committed 2026-09-03 17:04:46 +08:00
1 parent 47af79f9ac
commit 83606270d8
4 files changed
+148 -35

No files matched your search

@@ -867,6 +867,41 @@ describe('MessageStore', () => {
});
});
describe('resolvePrivateReplyMessageId', () => {
const peerId = 2705892349;
const sendId = -12721351;
const sentAt = 1_788_102_428;
function storeOutgoing(clientSequence: number, direction: 'incoming' | 'outgoing' = 'outgoing') {
store.storeMeta(sendId, {
isGroup: false,
targetId: peerId,
sequence: 682,
sequenceAuthoritative: true,
eventName: PRIVATE_MESSAGE_EVENT,
clientSequence,
privateDirection: direction,
random: 1,
timestamp: sentAt,
});
}
it('returns the send id when the quote sequence matches the stored client sequence', () => {
storeOutgoing(27_892);
expect(store.resolvePrivateReplyMessageId(peerId, 27_892, true, sentAt)).toBe(sendId);
});
it('returns the send id by timestamp when the quote sequence is not the local client sequence', () => {
storeOutgoing(201_616_628);
expect(store.resolvePrivateReplyMessageId(peerId, 27_892, true, sentAt)).toBe(sendId);
});
it('does not use timestamp fallback for incoming quotes', () => {
storeOutgoing(201_616_628, 'incoming');
expect(store.resolvePrivateReplyMessageId(peerId, 27_892, false, sentAt)).toBeNull();
});
});
it('lets a real group event replace an older non-authoritative placeholder', () => {
const groupId = 123456;
store.storeEvent(123, true, groupId, 99, GROUP_MESSAGE_EVENT, {