feat(onebot): tiered reply backfill + quoted-file recovery for get_msg (#128)
Harvests the sound ideas from PR #128 while KEEPING origSeqs[0] as the c2c reply sequence (on-target capture in #114/#124 proved origSeqs[0] == the quoted message's head.sequence; pbReserve.friendSequence is a small unrelated counter that makes reply.id miss). The PR's friendSequence override is intentionally NOT taken. - rich-body-decoder: enrich the reply element with replySenderUin/replyTime and the quoted message's own decoded elements (SrcMsg.elems, field 5); recover a c2c quoted FILE from sourceMsg (field 9 -> RichText.notOnlineFile) when elems carried none, so a quoted file survives into get_msg (#124). - backfillReplyTarget: tiered fallback — Tier 0 local store, Tier 1 server fetch (correct seq = origSeqs[0]), Tier 2 reconstruct from the embedded quoted elements (no round-trip), Tier 3 minimal '[引用消息]' placeholder so get_msg never returns 'message not found'. - to-segment: per-element try/catch (logged, not silent) so one bad element doesn't drop the whole message. - actions/message: log get_msg misses. - tests: fix request-actions getGroupInviteCardSequence mock (gap from #125); cover backfill Tier 2 (reconstruct) + Tier 3 (placeholder); flip the stale c2c reply test to assert origSeqs[0] (was asserting the disproven friendSequence). Validated on-target (Docker): get_msg on group reply, private text reply, and a private quoted FILE all return correct content (file with name/size/id); full onebot + protocol suites green.
This commit is contained in:
8 files changed
+189
-34
No files matched your search
@@ -145,7 +145,30 @@ describe('backfillReplyTarget', () => {
|
||||
expect(store.storeEvent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not store when the server has nothing at that sequence', async () => {
|
||||
it('reconstructs from replyElements when the server has nothing (tier 2)', async () => {
|
||||
const store = fakeStore(false);
|
||||
const getGroupMessageBySeq = vi.fn(async () => null);
|
||||
const ref = {
|
||||
selfId: SELF, converterCtx, messageStore: store,
|
||||
bridge: { apis: { message: { getGroupMessageBySeq } }, resolveUserUid: vi.fn() },
|
||||
} as any;
|
||||
const event = {
|
||||
kind: 'group_message', time: 1, selfUin: SELF, groupId: 700, senderUin: 900,
|
||||
senderNick: '', senderCard: '', senderRole: 'member', msgSeq: 999, msgId: 2,
|
||||
elements: [{ type: 'reply', replySeq: 123, replySenderUin: 800, replyElements: [{ type: 'text', text: 'quoted' }] }],
|
||||
} as any;
|
||||
|
||||
await backfillReplyTarget(ref, event);
|
||||
|
||||
const targetId = hashMessageIdInt32(123, 700, GROUP_MESSAGE_EVENT);
|
||||
expect(store.storeEvent).toHaveBeenCalledOnce();
|
||||
expect(store.storeEvent).toHaveBeenCalledWith(
|
||||
targetId, true, 700, 123, GROUP_MESSAGE_EVENT,
|
||||
expect.objectContaining({ message_id: targetId, message_type: 'group', user_id: 800 }),
|
||||
);
|
||||
});
|
||||
|
||||
it('stores a [引用消息] placeholder when server fetch and replyElements both miss (tier 3)', async () => {
|
||||
const store = fakeStore(false);
|
||||
const getGroupMessageBySeq = vi.fn(async () => null);
|
||||
const ref = {
|
||||
@@ -156,6 +179,11 @@ describe('backfillReplyTarget', () => {
|
||||
await backfillReplyTarget(ref, groupEvent(123));
|
||||
|
||||
expect(getGroupMessageBySeq).toHaveBeenCalledOnce();
|
||||
expect(store.storeEvent).not.toHaveBeenCalled();
|
||||
const targetId = hashMessageIdInt32(123, 700, GROUP_MESSAGE_EVENT);
|
||||
expect(store.storeEvent).toHaveBeenCalledOnce();
|
||||
expect(store.storeEvent).toHaveBeenCalledWith(
|
||||
targetId, true, 700, 123, GROUP_MESSAGE_EVENT,
|
||||
expect.objectContaining({ message_id: targetId, message_type: 'group' }),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -8,6 +8,7 @@ const APIS_ROUTING: Record<string, string> = {
|
||||
fetchFriendList: 'contacts', fetchGroupList: 'contacts',
|
||||
fetchGroupMemberList: 'contacts', fetchUserProfile: 'contacts',
|
||||
fetchGroupRequests: 'contacts', fetchDownloadRKeys: 'contacts',
|
||||
getGroupInviteCardSequence: 'contacts',
|
||||
};
|
||||
|
||||
function fakeBridge(overrides: Record<string, any> = {}): BridgeInterface {
|
||||
@@ -72,6 +73,7 @@ describe('onebot/modules/request-actions / handleGroupAddRequest', () => {
|
||||
fetchGroupRequests: vi.fn(async () => [
|
||||
fakeRequest({ groupId: 999, invitorUid: 'u_i', sequence: 97, eventType: 8, filtered: false }),
|
||||
]),
|
||||
getGroupInviteCardSequence: vi.fn(() => null),
|
||||
apis: { groupAdmin: { setAddRequest } } as any,
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user