mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-06 13:05:09 +00:00
refctor: getBuddyV2 支持分类
This commit is contained in:
@@ -1,23 +1,62 @@
|
||||
import { FriendRequest, SimpleInfo, User } from '@/core/entities';
|
||||
import { FriendRequest, FriendV2, SimpleInfo, User } from '@/core/entities';
|
||||
import { BuddyListReqType, napCatCore, NodeIKernelBuddyListener, NodeIKernelProfileService, OnBuddyChangeParams } from '@/core';
|
||||
import { NTEventDispatch } from '@/common/utils/EventTask';
|
||||
|
||||
export class NTQQFriendApi {
|
||||
static async getBuddyV2(refresh = false): Promise<SimpleInfo[]> {
|
||||
// NTEventDispatch.RegisterListen<NodeIKernelBuddyListener['onBuddyListChange']>('NodeIKernelBuddyListener/onBuddyListChange', 1, 5000, (arg: OnBuddyChangeParams) => {
|
||||
// console.log(arg);
|
||||
// return true;
|
||||
// }).catch().then();
|
||||
static async getBuddyV2(refresh = false): Promise<FriendV2[]> {
|
||||
let uids: string[];
|
||||
let categoryMap: Map<string, any> = new Map();
|
||||
if (!refresh) {
|
||||
uids = (await napCatCore.session.getBuddyService().getBuddyListFromCache('0')).flatMap((item) => item.buddyUids);
|
||||
uids = (await napCatCore.session.getBuddyService().getBuddyListFromCache('0')).flatMap((item) => {
|
||||
for (let i = 0; i < item.buddyUids.length; i++) {
|
||||
categoryMap.set(item.buddyUids[i], { categoryId: item.categoryId, categroyName: item.categroyName });
|
||||
}
|
||||
return item.buddyUids;
|
||||
});
|
||||
}
|
||||
uids = (await (napCatCore.session.getBuddyService().getBuddyListV2('0', BuddyListReqType.KNOMAL))).data.flatMap((item) => item.buddyUids);
|
||||
let data = await NTEventDispatch.CallNoListenerEvent<NodeIKernelProfileService['getCoreAndBaseInfo']>('NodeIKernelProfileService/getCoreAndBaseInfo', 5000, 'nodeStore', uids);
|
||||
//遍历data
|
||||
let retArr = Array.from(data.values());
|
||||
let retArr: FriendV2[] = [];
|
||||
data.forEach((value, key) => {
|
||||
let category = categoryMap.get(key);
|
||||
if (category) {
|
||||
retArr.push({
|
||||
...value,
|
||||
categoryId: category.categoryId,
|
||||
categroyName: category.categroyName
|
||||
});
|
||||
}
|
||||
})
|
||||
return retArr;
|
||||
}
|
||||
static async getBuddyV2Ex(refresh = false): Promise<FriendV2[]> {
|
||||
let uids: string[] = [];
|
||||
let categoryMap: Map<string, any> = new Map();
|
||||
|
||||
const buddyService = napCatCore.session.getBuddyService();
|
||||
|
||||
if (!refresh) {
|
||||
const cachedBuddyList = await buddyService.getBuddyListFromCache('0');
|
||||
cachedBuddyList.forEach(item => {
|
||||
item.buddyUids.forEach(uid => {
|
||||
categoryMap.set(uid, { categoryId: item.categoryId, categroyName: item.categroyName });
|
||||
});
|
||||
uids.push(...item.buddyUids);
|
||||
});
|
||||
}
|
||||
|
||||
const buddyListV2 = await buddyService.getBuddyListV2('0', BuddyListReqType.KNOMAL);
|
||||
uids.push(...buddyListV2.data.flatMap(item => item.buddyUids));
|
||||
|
||||
const data = await NTEventDispatch.CallNoListenerEvent<NodeIKernelProfileService['getCoreAndBaseInfo']>(
|
||||
'NodeIKernelProfileService/getCoreAndBaseInfo', 5000, 'nodeStore', uids
|
||||
);
|
||||
return Array.from(data).map(([key, value]) => {
|
||||
const category = categoryMap.get(key);
|
||||
return category ? { ...value, categoryId: category.categoryId, categroyName: category.categroyName } : value;
|
||||
});
|
||||
}
|
||||
static async isBuddy(uid: string) {
|
||||
return napCatCore.session.getBuddyService().isBuddy(uid);
|
||||
}
|
||||
|
||||
@@ -173,7 +173,10 @@ export interface SimpleInfo {
|
||||
otherFlags: any | null;
|
||||
intimate: any | null;
|
||||
}
|
||||
|
||||
export interface FriendV2 extends SimpleInfo {
|
||||
categoryId?: number;
|
||||
categroyName?: string;
|
||||
}
|
||||
export interface UserDetailInfoListenerArg {
|
||||
uid: string;
|
||||
uin: string;
|
||||
|
||||
Reference in New Issue
Block a user