From b20ed127617ecccebce30d71c386ea68cb81e6cf Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 4 Jul 2026 12:48:06 +0800 Subject: [PATCH] fix(onebot): approve group requests from the filtered inbox too (#197) set_group_add_request could fail with "matching group request not found" for a request SnowLuma had itself just reported. handleGroupAddRequest only fetched the main inbox (0x10C8 subCommand 1); a spam-filtered join/invite lives in the filtered inbox (subCommand 2) and was never searched, so its flag couldn't be resolved to a sequence. Fetch both inboxes and search the union. Each request keeps the `filtered` flag its approval subCommand needs, so a filtered request is approved through subCommand 2. A failing inbox fetch degrades to the other instead of aborting. Regular MSF invite pushes don't carry the approval msgseq (only the private-card path does, #125), so the fetch is the only source. Regression tests: filtered-only request is found + approved via subCommand 2; "not found" only when neither inbox has it. --- .../onebot/src/modules/request-actions.ts | 13 ++++++++- packages/onebot/tests/request-actions.test.ts | 29 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/onebot/src/modules/request-actions.ts b/packages/onebot/src/modules/request-actions.ts index 573179a1..27224c4c 100644 --- a/packages/onebot/src/modules/request-actions.ts +++ b/packages/onebot/src/modules/request-actions.ts @@ -27,7 +27,18 @@ export async function handleGroupAddRequest( } } - const requests = await bridge.apis.contacts.fetchGroupRequests(); + // A join/invite request lands in either the main inbox (0x10c8 subCommand 1) + // or the spam-filtered one (subCommand 2). The old code only fetched the main + // inbox, so a filtered request that SnowLuma had already reported to the + // client couldn't be approved through its own flag — "matching group request + // not found" (#197). Search both; each request keeps the `filtered` flag its + // inbox needs for the approval subCommand. One inbox failing degrades to the + // other rather than aborting. + const [mainInbox, filteredInbox] = await Promise.all([ + bridge.apis.contacts.fetchGroupRequests(false).catch(() => []), + bridge.apis.contacts.fetchGroupRequests(true).catch(() => []), + ]); + const requests = [...mainInbox, ...filteredInbox]; const matching = requests.find((r) => { if (r.groupId !== groupId) return false; if (requestType === 'add') return r.targetUid === targetUid; diff --git a/packages/onebot/tests/request-actions.test.ts b/packages/onebot/tests/request-actions.test.ts index 682dcb1e..0b63f6be 100644 --- a/packages/onebot/tests/request-actions.test.ts +++ b/packages/onebot/tests/request-actions.test.ts @@ -82,4 +82,33 @@ describe('onebot/modules/request-actions / handleGroupAddRequest', () => { expect(setAddRequest).toHaveBeenCalledOnce(); expect(setAddRequest).toHaveBeenCalledWith(999, 97, 8, false, 'no', false); }); + + it('finds a request that only lives in the filtered inbox (#197)', async () => { + const setAddRequest = vi.fn(async () => {}); + const bridge = fakeBridge({ + // Main inbox empty; the invite sits only in the spam-filtered inbox. + fetchGroupRequests: vi.fn(async (filtered: boolean) => + filtered + ? [fakeRequest({ groupId: 999, invitorUid: 'u_i', sequence: 55, eventType: 2, filtered: true })] + : []), + getGroupInviteCardSequence: vi.fn(() => null), + apis: { groupAdmin: { setAddRequest } } as any, + }); + + await handleGroupAddRequest(bridge, 'invite:999:u_i', true, 'ok'); + + // Approved through the filtered inbox (subCommand 2 → last arg true). + expect(setAddRequest).toHaveBeenCalledOnce(); + expect(setAddRequest).toHaveBeenCalledWith(999, 55, 2, true, 'ok', true); + }); + + it('surfaces "not found" only when neither inbox has the request', async () => { + const bridge = fakeBridge({ + fetchGroupRequests: vi.fn(async () => []), + getGroupInviteCardSequence: vi.fn(() => null), + apis: { groupAdmin: { setAddRequest: vi.fn(async () => {}) } } as any, + }); + await expect(handleGroupAddRequest(bridge, 'invite:999:u_i', true, 'ok')) + .rejects.toThrow(/matching group request not found/); + }); });