feat(onebot): implement mark all as read

Replace the compatibility no-op with a real batched read action for current groups and observed incoming private conversations.

Exclude stale groups, group temporary sessions, and sent-message echoes from private targets, then expose the functional action through the generated MCP catalog.

Add action and message-store regressions for target selection and delegation.
This commit is contained in:
DrSmoothl committed 2026-07-13 23:02:08 +08:00
1 parent 4d93c727bb
commit defe15694b
8 files changed
+93 -14

No files matched your search

+12 -7
View File
@@ -101,6 +101,7 @@ function fakeCtx(bridge: BridgeInterface, overrides: Partial<ApiActionContext> =
bridge,
getMessageMeta: () => null,
getMessage: () => null,
listReadSessions: () => ({ groupIds: [], privateUserIds: [] }),
getLoginInfo: () => ({ userId: 1, nickname: '' }),
isOnline: () => true,
canSendImage: () => true,
@@ -891,10 +892,8 @@ describe('extended-actions / ocr_image', () => {
});
});
// ─── TierB Phase 1: compat stubs (model_show / online_clients / mark_all_as_read) ───
// These are kernel-only in NapCat (mock/no-op), so SnowLuma ships honest
// compat shapes rather than RE-ing a wire that doesn't exist. We pin the
// response *shape* of each. NOTE two deliberate divergences from NapCat:
// ─── TierB Phase 1: compatibility actions ───
// NOTE two deliberate divergences from NapCat:
// • _get_model_show reuses NapCat's array/variants shape but ECHOES the
// requested model instead of NapCat's hardcoded 'napcat'.
// • get_online_clients returns the OneBot-v11/go-cqhttp { clients: [] }
@@ -931,9 +930,15 @@ describe('extended-actions / TierB compat stubs', () => {
expect(res.data).toMatchObject({ clients: [] });
});
it('_mark_all_as_read is an accepted no-op', async () => {
const res = await makeHandler(fakeCtx(fakeBridge())).handle('_mark_all_as_read', {});
expect(res).toMatchObject({ status: 'ok', retcode: 0 });
it('_mark_all_as_read passes every observed session to the batched SSO implementation', async () => {
const markAllRead = vi.fn(async () => undefined);
const bridge = fakeBridge({ apis: { message: { markAllRead } } });
const res = await makeHandler(fakeCtx(bridge, {
listReadSessions: () => ({ groupIds: [101, 102], privateUserIds: [201] }),
})).handle('_mark_all_as_read', {});
expect(markAllRead).toHaveBeenCalledWith([101, 102], [201]);
expect(res).toMatchObject({ status: 'ok', retcode: 0, data: null });
});
});
@@ -187,4 +187,28 @@ describe('MessageStore', () => {
expect(retrieved).toBeNull();
});
});
describe('listReadSessions', () => {
it('uses current groups and only genuine incoming friend sessions', () => {
const event = (postType: string, subType: string) => ({
time: 1700000000,
post_type: postType,
message_type: 'private',
sub_type: subType,
});
store.storeEvent(1001, false, 40001, 1, PRIVATE_MESSAGE_EVENT, event('message', 'friend'));
store.storeEvent(1002, false, 40001, 2, PRIVATE_MESSAGE_EVENT, event('message', 'friend'));
store.storeEvent(1003, false, 40002, 3, PRIVATE_MESSAGE_EVENT, event('message', 'group'));
store.storeEvent(1004, false, 40003, 4, PRIVATE_MESSAGE_EVENT, event('message_sent', 'friend'));
expect(store.listReadSessions([30002, 30001, 30002])).toEqual({
groupIds: [30002, 30001],
privateUserIds: [40001],
});
});
it('fails on a corrupt current group target', () => {
expect(() => store.listReadSessions([0])).toThrow('invalid group id 0');
});
});
});