mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
refactor: api getbuddyv2
This commit is contained in:
@@ -1,21 +1,31 @@
|
||||
import { FriendRequest, User } from '@/core/entities';
|
||||
import { BuddyListReqType, napCatCore, NodeIKernelBuddyListener, OnBuddyChangeParams } from '@/core';
|
||||
import { FriendRequest, 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) {
|
||||
static async getBuddyV2(refresh = false): Promise<SimpleInfo[]> {
|
||||
// NTEventDispatch.RegisterListen<NodeIKernelBuddyListener['onBuddyListChange']>('NodeIKernelBuddyListener/onBuddyListChange', 1, 5000, (arg: OnBuddyChangeParams) => {
|
||||
// console.log(arg);
|
||||
// return true;
|
||||
// }).catch().then();
|
||||
let uids: string[];
|
||||
if (!refresh) {
|
||||
return await napCatCore.session.getBuddyService().getBuddyListFromCache('0');
|
||||
uids = (await napCatCore.session.getBuddyService().getBuddyListFromCache('0')).flatMap((item) => item.buddyUids);
|
||||
}
|
||||
return (await (napCatCore.session.getBuddyService().getBuddyListV2('0', BuddyListReqType.KNOMAL))).data;
|
||||
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());
|
||||
return retArr;
|
||||
}
|
||||
static async isBuddy(uid: string) {
|
||||
return napCatCore.session.getBuddyService().isBuddy(uid);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @param forced
|
||||
* @returns
|
||||
*/
|
||||
static async getFriends(forced = false): Promise<User[]> {
|
||||
let [_retData, _BuddyArg] = await NTEventDispatch.CallNormalEvent
|
||||
<(force: boolean) => Promise<any>, (arg: OnBuddyChangeParams) => void>
|
||||
|
@@ -2,11 +2,12 @@ import { QQLevel, Sex } from './user';
|
||||
|
||||
export interface Group {
|
||||
groupCode: string,
|
||||
createTime?:string,//高版本才有
|
||||
maxMember: number,
|
||||
memberCount: number,
|
||||
groupName: string,
|
||||
groupStatus: 0,
|
||||
memberRole: 2,
|
||||
groupStatus: number,
|
||||
memberRole: number,
|
||||
isTop: boolean,
|
||||
toppedTimestamp: string,
|
||||
privilegeFlag: number, //65760
|
||||
|
@@ -9,14 +9,14 @@ export interface BuddyCategoryType {
|
||||
categroyMbCount: number;
|
||||
buddyList: User[];
|
||||
}
|
||||
interface CoreInfo {
|
||||
export interface CoreInfo {
|
||||
uid: string;
|
||||
uin: string;
|
||||
nick: string;
|
||||
remark: string;
|
||||
}
|
||||
|
||||
interface BaseInfo {
|
||||
export interface BaseInfo {
|
||||
qid: string;
|
||||
longNick: string;
|
||||
birthday_year: number;
|
||||
@@ -162,16 +162,16 @@ interface PhotoWall {
|
||||
picList: Pic[];
|
||||
}
|
||||
|
||||
interface SimpleInfo {
|
||||
uid: string;
|
||||
uin: string;
|
||||
export interface SimpleInfo {
|
||||
uid?: string;
|
||||
uin?: string;
|
||||
coreInfo: CoreInfo;
|
||||
baseInfo: BaseInfo;
|
||||
status: UserStatus;
|
||||
vasInfo: VasInfo;
|
||||
relationFlags: RelationFlags;
|
||||
otherFlags: any;
|
||||
intimate: any;
|
||||
status: UserStatus | null;
|
||||
vasInfo: VasInfo | null;
|
||||
relationFlags: RelationFlags | null;
|
||||
otherFlags: any | null;
|
||||
intimate: any | null;
|
||||
}
|
||||
|
||||
export interface UserDetailInfoListenerArg {
|
||||
@@ -272,7 +272,7 @@ export interface Friend extends User { }
|
||||
export enum BizKey {
|
||||
KPRIVILEGEICON,
|
||||
KPHOTOWALL
|
||||
}
|
||||
}
|
||||
export interface UserDetailInfoByUin {
|
||||
result: number,
|
||||
errMsg: string,
|
||||
|
@@ -5,7 +5,7 @@ import { GeneralCallResult } from '@/core/services/common';
|
||||
export interface QueryMsgsParams {
|
||||
chatInfo: Peer,
|
||||
filterMsgType: [],
|
||||
filterSendersUid: [],
|
||||
filterSendersUid: string[],
|
||||
filterMsgFromTime: string,
|
||||
filterMsgToTime: string,
|
||||
pageLimit: number,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { AnyCnameRecord } from 'node:dns';
|
||||
import { BizKey, ModifyProfileParams, UserDetailInfoByUin } from '../entities';
|
||||
import { BaseInfo, BizKey, CoreInfo, ModifyProfileParams, SimpleInfo, UserDetailInfoByUin } from '../entities';
|
||||
import { NodeIKernelProfileListener } from '../listeners';
|
||||
import { GeneralCallResult } from '@/core/services/common';
|
||||
export enum UserDetailSource {
|
||||
@@ -14,6 +14,17 @@ export enum ProfileBizType {
|
||||
KOTHER
|
||||
}
|
||||
export interface NodeIKernelProfileService {
|
||||
// {
|
||||
// coreInfo: CoreInfo,
|
||||
// baseInfo: BaseInfo,
|
||||
// status: null,
|
||||
// vasInfo: null,
|
||||
// relationFlags: null,
|
||||
// otherFlags: null,
|
||||
// intimate: null
|
||||
// }
|
||||
getCoreAndBaseInfo(callfrom: string, uids: string[]): Promise<Map<string, SimpleInfo>>;
|
||||
|
||||
fetchUserDetailInfo(trace: string, uids: string[], arg2: number, arg3: number[]): Promise<unknown>;
|
||||
|
||||
addKernelProfileListener(listener: NodeIKernelProfileListener): number;
|
||||
|
@@ -21,7 +21,7 @@ export interface NodeIKernelRobotService {
|
||||
|
||||
removeKernelRobotListener(ListenerId: number): unknown;
|
||||
|
||||
getAllRobotFriendsFromCache(): unknown;
|
||||
getAllRobotFriendsFromCache(): Promise<unknown>;
|
||||
|
||||
fetchAllRobots(arg1: unknown, arg2: unknown): unknown;
|
||||
|
||||
|
@@ -5,6 +5,7 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQFriendApi } from '@/core';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { requireMinNTQQBuild } from '@/common/utils/QQBasicInfo';
|
||||
|
||||
|
||||
// no_cache get时传字符串
|
||||
@@ -20,7 +21,10 @@ export default class GetFriendList extends BaseAction<Payload, OB11User[]> {
|
||||
actionName = ActionName.GetFriendList;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
//let data = await NTQQFriendApi.getBuddyV2(payload?.no_cache === true || payload?.no_cache=== 'true');
|
||||
if (requireMinNTQQBuild('26702')) {
|
||||
//全新逻辑
|
||||
return OB11Constructor.friendsV2(await NTQQFriendApi.getBuddyV2(payload?.no_cache === true || payload?.no_cache === 'true'));
|
||||
}
|
||||
if (friends.size === 0 || payload?.no_cache === true || payload?.no_cache === 'true') {
|
||||
const _friends = await NTQQFriendApi.getFriends(true);
|
||||
// log('强制刷新好友列表,结果: ', _friends)
|
||||
|
@@ -22,6 +22,7 @@ import {
|
||||
RawMessage,
|
||||
SelfInfo,
|
||||
Sex,
|
||||
SimpleInfo,
|
||||
TipGroupElementType,
|
||||
User,
|
||||
VideoElement
|
||||
@@ -552,7 +553,14 @@ export class OB11Constructor {
|
||||
nickname: selfInfo.nick,
|
||||
};
|
||||
}
|
||||
|
||||
static friendsV2(friends: SimpleInfo[]): OB11User[] {
|
||||
const data: OB11User[] = [];
|
||||
friends.forEach(friend => {
|
||||
const sexValue = this.sex(friend.baseInfo.sex!);
|
||||
data.push({ ...friend.baseInfo, ...friend.coreInfo, user_id: parseInt(friend.coreInfo.uin), nickname: friend.coreInfo.nick, remark: friend.coreInfo.nick, sex: sexValue, level: 0 });
|
||||
});
|
||||
return data;
|
||||
}
|
||||
static friends(friends: Friend[]): OB11User[] {
|
||||
const data: OB11User[] = [];
|
||||
friends.forEach(friend => {
|
||||
|
Reference in New Issue
Block a user