From 3db74c34274d80675137f0e3df4d6891fa2e4616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sun, 4 Aug 2024 12:26:55 +0800 Subject: [PATCH] refactor: BuddyList --- src/core/src/apis/friend.ts | 8 +++- src/core/src/apis/user.ts | 37 +++++++++++++++++++ .../src/services/NodeIKernelBuddyService.ts | 13 ++++++- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/core/src/apis/friend.ts b/src/core/src/apis/friend.ts index 01b9cb6a..047000be 100644 --- a/src/core/src/apis/friend.ts +++ b/src/core/src/apis/friend.ts @@ -1,8 +1,14 @@ import { FriendRequest, User } from '@/core/entities'; -import { napCatCore, OnBuddyChangeParams } from '@/core'; +import { BuddyListReqType, napCatCore, OnBuddyChangeParams } from '@/core'; import { NTEventDispatch } from '@/common/utils/EventTask'; export class NTQQFriendApi { + static async getBuddyV2(refresh = false) { + if (!refresh) { + return await napCatCore.session.getBuddyService().getBuddyListFromCache('0'); + } + return (await (napCatCore.session.getBuddyService().getBuddyListV2('0', BuddyListReqType.KNOMAL))).data; + } static async isBuddy(uid: string) { return napCatCore.session.getBuddyService().isBuddy(uid); } diff --git a/src/core/src/apis/user.ts b/src/core/src/apis/user.ts index fda691a8..4c137930 100644 --- a/src/core/src/apis/user.ts +++ b/src/core/src/apis/user.ts @@ -65,6 +65,43 @@ export class NTQQUserApi { // KQZONE, // KOTHER // } + static async fetchUserDetailInfos(uids: string[]) { + type EventService = NodeIKernelProfileService['fetchUserDetailInfo']; + type EventListener = NodeIKernelProfileListener['onUserDetailInfoChanged']; + let retData: User[] = []; + let [_retData, _retListener] = await NTEventDispatch.CallNormalEvent + + ( + 'NodeIKernelProfileService/fetchUserDetailInfo', + 'NodeIKernelProfileListener/onUserDetailInfoChanged', + uids.length, + 5000, + (profile) => { + if (uids.includes(profile.uid)) { + let RetUser: User = { + ...profile.simpleInfo.coreInfo, + ...profile.simpleInfo.status, + ...profile.simpleInfo.vasInfo, + ...profile.commonExt, + ...profile.simpleInfo.baseInfo, + qqLevel: profile.commonExt.qqLevel, + pendantId: "" + }; + retData.push(RetUser); + return true; + } + return false; + }, + "BuddyProfileStore", + uids, + UserDetailSource.KSERVER, + [ + ProfileBizType.KALL + ] + ); + + return retData; + } static async fetchUserDetailInfo(uid: string) { type EventService = NodeIKernelProfileService['fetchUserDetailInfo']; type EventListener = NodeIKernelProfileListener['onUserDetailInfoChanged']; diff --git a/src/core/src/services/NodeIKernelBuddyService.ts b/src/core/src/services/NodeIKernelBuddyService.ts index be868d75..1d28a300 100644 --- a/src/core/src/services/NodeIKernelBuddyService.ts +++ b/src/core/src/services/NodeIKernelBuddyService.ts @@ -7,7 +7,16 @@ export enum BuddyListReqType { } export interface NodeIKernelBuddyService { // 26702 以上 - getBuddyListV2(callFrom: string, reqType: BuddyListReqType): Promise; + getBuddyListV2(callFrom: string, reqType: BuddyListReqType): Promise + }> + }>; //26702 以上 getBuddyListFromCache(callFrom: string): Promise