fix(onebot): return categorized friend lists
This commit is contained in:
6 files changed
+202
-5
No files matched your search
@@ -1122,12 +1122,46 @@ export const actions = [
|
||||
name: 'get_friends_with_category',
|
||||
summary: '获取分组好友列表',
|
||||
readOnly: true,
|
||||
returns: '好友分组数组;每组包含 categoryId、categoryName、categoryMbCount 和 buddyList。',
|
||||
returnsSchema: {
|
||||
type: 'array',
|
||||
description: '带分组的好友列表',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
categoryId: { type: 'integer', description: '分组 ID' },
|
||||
categoryName: { type: 'string', description: '分组名称' },
|
||||
categoryMbCount: { type: 'integer', description: '服务端报告的分组好友数' },
|
||||
buddyList: {
|
||||
type: 'array',
|
||||
description: '该分组内的好友',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: 'integer', description: 'QQ 号' },
|
||||
nickname: { type: 'string', description: '昵称' },
|
||||
remark: { type: 'string', description: '好友备注' },
|
||||
},
|
||||
required: ['user_id', 'nickname', 'remark'],
|
||||
},
|
||||
},
|
||||
},
|
||||
required: ['categoryId', 'categoryName', 'categoryMbCount', 'buddyList'],
|
||||
},
|
||||
},
|
||||
params: {},
|
||||
run: async (_p, ctx) => {
|
||||
if (ctx.getFriendList) {
|
||||
return okResponse(await ctx.getFriendList());
|
||||
}
|
||||
return okResponse([]);
|
||||
const categories = await ctx.bridge.apis.contacts.fetchFriendCategories();
|
||||
return okResponse(categories.map(category => ({
|
||||
categoryId: category.categoryId,
|
||||
categoryName: category.categoryName,
|
||||
categoryMbCount: category.memberCount,
|
||||
buddyList: category.friends.map(friend => ({
|
||||
user_id: friend.uin,
|
||||
nickname: friend.nickname,
|
||||
remark: friend.remark,
|
||||
})),
|
||||
})));
|
||||
},
|
||||
}),
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ function fakeMeta(overrides: Partial<MessageMeta> = {}): MessageMeta {
|
||||
// drops the redundant `Group`/`File` prefix.
|
||||
const APIS_ROUTING: Record<string, [string, string]> = {
|
||||
fetchFriendList: ['contacts', 'fetchFriendList'],
|
||||
fetchFriendCategories: ['contacts', 'fetchFriendCategories'],
|
||||
fetchGroupList: ['contacts', 'fetchGroupList'],
|
||||
fetchGroupMemberList: ['contacts', 'fetchGroupMemberList'],
|
||||
fetchUserProfile: ['contacts', 'fetchUserProfile'],
|
||||
@@ -119,6 +120,46 @@ function makeHandler(ctx: ApiActionContext): ApiHandler {
|
||||
return new ApiHandler(ctx);
|
||||
}
|
||||
|
||||
describe('extended-actions / get_friends_with_category', () => {
|
||||
it('returns the exact categorized friend contract', async () => {
|
||||
const fetchFriendCategories = vi.fn(async () => [{
|
||||
categoryId: 7,
|
||||
categoryName: 'Work',
|
||||
memberCount: 1,
|
||||
sortId: 3,
|
||||
friends: [{ uin: 10001, uid: 'u1', nickname: 'Alice', remark: 'A' }],
|
||||
}]);
|
||||
const bridge = fakeBridge({ fetchFriendCategories });
|
||||
const response = await makeHandler(fakeCtx(bridge))
|
||||
.handle('get_friends_with_category', {});
|
||||
|
||||
expect(fetchFriendCategories).toHaveBeenCalledOnce();
|
||||
expect(response).toMatchObject({ status: 'ok', retcode: 0 });
|
||||
expect(response.data).toEqual([{
|
||||
categoryId: 7,
|
||||
categoryName: 'Work',
|
||||
categoryMbCount: 1,
|
||||
buddyList: [{ user_id: 10001, nickname: 'Alice', remark: 'A' }],
|
||||
}]);
|
||||
});
|
||||
|
||||
it('surfaces categorized fetch failures', async () => {
|
||||
const bridge = fakeBridge({
|
||||
fetchFriendCategories: vi.fn(async () => {
|
||||
throw new Error('repeated friend-list cookie aa');
|
||||
}),
|
||||
});
|
||||
const response = await makeHandler(fakeCtx(bridge))
|
||||
.handle('get_friends_with_category', {});
|
||||
|
||||
expect(response).toMatchObject({
|
||||
status: 'failed',
|
||||
retcode: 100,
|
||||
wording: 'repeated friend-list cookie aa',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Tier 1: send_packet / .send_packet ───
|
||||
|
||||
describe('extended-actions / send_packet', () => {
|
||||
|
||||
Reference in new issue
Block a user