From 03c056702cfa13f0e73c3bba7f6ace211e0a6231 Mon Sep 17 00:00:00 2001 From: "Wesley F. Young" Date: Sat, 31 Aug 2024 13:53:30 +0800 Subject: [PATCH] chore: clean code for friend.ts --- src/core/apis/friend.ts | 47 ++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/src/core/apis/friend.ts b/src/core/apis/friend.ts index 4a966229..fdaff939 100644 --- a/src/core/apis/friend.ts +++ b/src/core/apis/friend.ts @@ -16,47 +16,42 @@ export class NTQQFriendApi { // } } - async getBuddyV2(refresh = false): Promise { - const uids: string[] = []; + async getBuddyV2SimpleInfoMap(refresh = false) { const buddyService = this.context.session.getBuddyService(); const buddyListV2 = refresh ? await buddyService.getBuddyListV2('0', BuddyListReqType.KNOMAL) : await buddyService.getBuddyListV2('0', BuddyListReqType.KNOMAL); - uids.push(...buddyListV2.data.flatMap(item => item.buddyUids)); - const data = await this.core.eventWrapper.callNoListenerEvent( - 'NodeIKernelProfileService/getCoreAndBaseInfo', 'nodeStore', uids, + const uids = buddyListV2.data.flatMap(item => item.buddyUids); + return await this.core.eventWrapper.callNoListenerEvent( + 'NodeIKernelProfileService/getCoreAndBaseInfo', + 'nodeStore', + uids, ); - return Array.from(data.values()); + } + + async getBuddyV2(refresh = false): Promise { + return Array.from((await this.getBuddyV2SimpleInfoMap(refresh)).values()); } async getBuddyIdMap(refresh = false): Promise> { - const uids: string[] = []; const retMap: LimitedHashTable = new LimitedHashTable(5000); - const buddyService = this.context.session.getBuddyService(); - const buddyListV2 = refresh ? await buddyService.getBuddyListV2('0', BuddyListReqType.KNOMAL) : await buddyService.getBuddyListV2('0', BuddyListReqType.KNOMAL); - uids.push(...buddyListV2.data.flatMap(item => item.buddyUids)); - const data = await this.core.eventWrapper.callNoListenerEvent( - 'NodeIKernelProfileService/getCoreAndBaseInfo', 'nodeStore', uids, - ); - data.forEach((value) => { - retMap.set(value.uin!, value.uid!); - }); - //console.log('getBuddyIdMap', retMap.getValue); + const data = await this.getBuddyV2SimpleInfoMap(refresh); + data.forEach((value) => retMap.set(value.uin!, value.uid!)); return retMap; } async getBuddyV2ExWithCate(refresh = false) { - const uids: string[] = []; const categoryMap: Map = new Map(); const buddyService = this.context.session.getBuddyService(); const buddyListV2 = refresh ? (await buddyService.getBuddyListV2('0', BuddyListReqType.KNOMAL)).data : (await buddyService.getBuddyListV2('0', BuddyListReqType.KNOMAL)).data; - uids.push( - ...buddyListV2.flatMap(item => { - item.buddyUids.forEach(uid => { - categoryMap.set(uid, { categoryId: item.categoryId, categoryName: item.categroyName }); - }); - return item.buddyUids; - })); + const uids = buddyListV2.flatMap(item => { + item.buddyUids.forEach(uid => { + categoryMap.set(uid, { categoryId: item.categoryId, categoryName: item.categroyName }); + }); + return item.buddyUids; + }); const data = await this.core.eventWrapper.callNoListenerEvent( - 'NodeIKernelProfileService/getCoreAndBaseInfo', 'nodeStore', uids, + 'NodeIKernelProfileService/getCoreAndBaseInfo', + 'nodeStore', + uids, ); return buddyListV2.map(category => ({ categoryId: category.categoryId,