refactor: getUidByUinV2/getUinByUidV2

This commit is contained in:
手瓜一十雪
2024-12-04 18:41:28 +08:00
parent eb99379a79
commit d51d6a5cc1

View File

@@ -26,7 +26,7 @@ export class NTQQUserApi {
uids, uids,
); );
} }
// 默认获取自己的 type = 2 获取别人 type = 1 // 默认获取自己的 type = 2 获取别人 type = 1
async getProfileLike(uid: string, start: number, count: number, type: number = 2) { async getProfileLike(uid: string, start: number, count: number, type: number = 2) {
return this.context.session.getProfileLikeService().getBuddyProfileLike({ return this.context.session.getProfileLikeService().getBuddyProfileLike({
@@ -99,7 +99,7 @@ export class NTQQUserApi {
}; };
return RetUser; return RetUser;
} }
async getUserDetailInfo(uid: string): Promise<User> { async getUserDetailInfo(uid: string): Promise<User> {
let retUser = await solveAsyncProblem(async (uid) => this.fetchUserDetailInfo(uid, UserDetailSource.KDB), uid); let retUser = await solveAsyncProblem(async (uid) => this.fetchUserDetailInfo(uid, UserDetailSource.KDB), uid);
if (retUser && retUser.uin !== '0') { if (retUser && retUser.uin !== '0') {
@@ -173,31 +173,38 @@ export class NTQQUserApi {
return skey; return skey;
} }
//后期改成流水线处理
async getUidByUinV2(Uin: string) { async getUidByUinV2(Uin: string) {
let uid = (await this.context.session.getGroupService().getUidByUins([Uin])).uids.get(Uin); const services = [
if (uid) return uid; () => this.context.session.getGroupService().getUidByUins([Uin]).then((data) => data.uids.get(Uin)).catch(() => undefined),
uid = (await this.context.session.getProfileService().getUidByUin('FriendsServiceImpl', [Uin])).get(Uin); () => this.context.session.getProfileService().getUidByUin('FriendsServiceImpl', [Uin]).then((data) => data.get(Uin)).catch(() => undefined),
if (uid) return uid; () => this.context.session.getUixConvertService().getUid([Uin]).then((data) => data.uidInfo.get(Uin)).catch(() => undefined),
uid = (await this.context.session.getUixConvertService().getUid([Uin])).uidInfo.get(Uin); () => this.getUserDetailInfoByUin(Uin).then((data) => data.detail.uid).catch(() => undefined),
if (uid) return uid; ];
const unverifiedUid = (await this.getUserDetailInfoByUin(Uin)).detail.uid;//从QQ Native 特殊转换 let uid: string | undefined = undefined;
if (unverifiedUid.indexOf('*') == -1) uid = unverifiedUid; for (const service of services) {
//if (uid) return uid; uid = await service();
if (uid && uid.indexOf('*') == -1 && uid !== '') {
break;
}
}
return uid; return uid;
} }
//后期改成流水线处理
async getUinByUidV2(Uid: string) { async getUinByUidV2(Uid: string) {
let uin = (await this.context.session.getGroupService().getUinByUids([Uid])).uins.get(Uid); const services = [
if (uin && uin !== '0') return uin; () => this.context.session.getGroupService().getUinByUids([Uid]).then((data) => data.uins.get(Uid)).catch(() => undefined),
uin = (await this.context.session.getProfileService().getUinByUid('FriendsServiceImpl', [Uid])).get(Uid); () => this.context.session.getProfileService().getUinByUid('FriendsServiceImpl', [Uid]).then((data) => data.get(Uid)).catch(() => undefined),
if (uin && uin !== '0') return uin; () => this.context.session.getUixConvertService().getUin([Uid]).then((data) => data.uinInfo.get(Uid)).catch(() => undefined),
uin = (await this.context.session.getUixConvertService().getUin([Uid])).uinInfo.get(Uid); () => this.core.apis.FriendApi.getBuddyIdMap(true).then((data) => data.getKey(Uid)).catch(() => undefined),
if (uin && uin !== '0') return uin; () => this.getUserDetailInfo(Uid).then((data) => data.uin).catch(() => undefined),
uin = (await this.core.apis.FriendApi.getBuddyIdMap(true)).getKey(Uid); ];
if (uin && uin !== '0') return uin; let uin: string | undefined = undefined;
uin = (await this.getUserDetailInfo(Uid)).uin; //从QQ Native 转换 for (const service of services) {
uin = await service();
if (uin && uin !== '0' && uin !== '') {
break;
}
}
return uin; return uin;
} }