fix(api): fix friend.list

This commit is contained in:
Il Harper 2024-09-16 02:29:39 +08:00
parent 4005d8ccb7
commit afbee93033
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
5 changed files with 284 additions and 44 deletions

View File

@ -22,12 +22,6 @@ export const buildFriendList =
await ctx.chronocat.sleep(1000) await ctx.chronocat.sleep(1000)
return { return {
data: Object.values(friendMap).map((x) => ({ data: Object.values(friendMap),
id: x.uin,
name: x.nick,
nick: x.remark || undefined,
avatar: `http://thirdqq.qlogo.cn/headimg_dl?dst_uin=${x.uin}&spec=640`,
is_bot: false,
})),
} }
} }

View File

@ -1,4 +1,5 @@
import type { Group, Profile, RedIpcData, RedMessage } from '@chronocat/red' import type { Group, RedIpcData, RedMessage } from '@chronocat/red'
import { User } from '@chronocat/shell'
import { ChronoEventEmitter } from './emitter' import { ChronoEventEmitter } from './emitter'
export const requestMethodMap: Record<string, string> = {} export const requestMethodMap: Record<string, string> = {}
@ -9,7 +10,7 @@ export const requestCallbackMap: Record<
export const groupMap: Record<string, Group> = {} export const groupMap: Record<string, Group> = {}
export const roleMap: Record<string, Record<string, number>> = {} export const roleMap: Record<string, Record<string, number>> = {}
export const friendMap: Record<string, Profile> = {} export const friendMap: Record<string, User> = {}
export const richMediaDownloadMap: Record<string, (path: string) => void> = {} export const richMediaDownloadMap: Record<string, (path: string) => void> = {}
export const emojiDownloadMap: Record<string, (path: string) => void> = {} export const emojiDownloadMap: Record<string, (path: string) => void> = {}

View File

@ -220,8 +220,10 @@ const responseDispatcher = async (
case 'onBuddyListChange': case 'onBuddyListChange':
case 'nodeIKernelBuddyListener/onBuddyListChange': { case 'nodeIKernelBuddyListener/onBuddyListChange': {
const { data } = payload as OnBuddyListChange const { data, buddyCategory, userSimpleInfos } =
payload as OnBuddyListChange
if (data) {
for (const category of data) { for (const category of data) {
for (const buddy of category.buddyList) { for (const buddy of category.buddyList) {
ctx.chronocat.uix.add(buddy.uid, buddy.uin) ctx.chronocat.uix.add(buddy.uid, buddy.uin)
@ -233,11 +235,44 @@ const responseDispatcher = async (
}) })
// buddy.category = category.categoryName // buddy.category = category.categoryName
friendMap[buddy.uin] = buddy friendMap[buddy.uin] = {
id: buddy.uin,
name: buddy.nick,
nick: buddy.remark || undefined,
avatar: `http://thirdqq.qlogo.cn/headimg_dl?dst_uin=${buddy.uin}&spec=640`,
is_bot: false,
}
} }
} }
chronoEventEmitter.emitBuddyListChange() chronoEventEmitter.emitBuddyListChange()
} else if (buddyCategory && userSimpleInfos) {
// 先填充 uix
for (const uid in userSimpleInfos)
ctx.chronocat.uix.add(uid, userSimpleInfos[uid]!.uin)
for (const category of buddyCategory) {
for (const uid of category.buddyUids) {
ctx.chronocatEngineChronocatApi.msgBoxActiv.activate({
chatType: ChatType.Private,
peerUid: uid,
guildId: '',
})
const userSimpleInfo = userSimpleInfos[uid]!
friendMap[userSimpleInfo.uin] = {
id: userSimpleInfo.uin,
name: userSimpleInfo.coreInfo.nick,
nick: userSimpleInfo.coreInfo.remark || undefined,
avatar: `http://thirdqq.qlogo.cn/headimg_dl?dst_uin=${userSimpleInfo.uin}&spec=640`,
is_bot: false,
}
}
}
chronoEventEmitter.emitBuddyListChange()
}
return return
} }

View File

@ -294,11 +294,17 @@ const dispatcher = async (
case 'onBuddyListChange': case 'onBuddyListChange':
case 'nodeIKernelBuddyListener/onBuddyListChange': { case 'nodeIKernelBuddyListener/onBuddyListChange': {
const { data } = payload as OnBuddyListChange const { data, buddyCategory, userSimpleInfos } =
payload as OnBuddyListChange
if (data) {
for (const category of data) for (const category of data)
for (const buddy of category.buddyList) for (const buddy of category.buddyList)
ctx.chronocat.uix.add(buddy.uid, buddy.uin) ctx.chronocat.uix.add(buddy.uid, buddy.uin)
} else if (buddyCategory && userSimpleInfos) {
for (const uid in userSimpleInfos)
ctx.chronocat.uix.add(uid, userSimpleInfos[uid]!.uin)
}
return return
} }

View File

@ -108,7 +108,20 @@ export interface OnBuddyListChange {
/** /**
* *
*/ */
data: { data: BuddyListChangeData[] | undefined
/**
*
*/
buddyCategory: BuddyCategory[] | undefined
/**
* uid
*/
userSimpleInfos: Record<string, UserSimpleInfo> | undefined
}
export interface BuddyListChangeData {
/** /**
* ID * ID
*/ */
@ -128,7 +141,198 @@ export interface OnBuddyListChange {
* *
*/ */
buddyList: Profile[] buddyList: Profile[]
}[] }
export interface BuddyCategory {
categoryId: number
/**
*
*/
categorySortId: number
categroyName: string
categroyMbCount: number
onlineCount: number
buddyUids: string[]
}
export interface UserSimpleInfo {
uid: string
uin: string
coreInfo: UserCoreInfo
baseInfo: UserBaseInfo
status: UserStatus | null
vasInfo: UserVasInfo | null
relationFlags: UserRelationFlags
otherFlags: unknown
intimate: unknown
}
export interface UserCoreInfo {
uid: string
uin: string
nick: string
/**
*
*/
remark: string
}
export interface UserBaseInfo {
/**
*
*/
qid: string
/**
*
*/
longNick: string
/**
* 0
*/
birthday_year: number
/**
* 0
*/
birthday_month: number
/**
* 0
*/
birthday_day: number
age: number
sex: number
eMail: string
phoneNum: string
categoryId: number
richTime: number
richBuffer: unknown
}
export interface UserStatus {
uid: string
uin: string
status: number
extStatus: number
batteryStatus: number
termType: number
netType: number
iconType: number
customStatus: {
faceId: string
faceType: string
wording: string
}
setTime: string
specialFlag: number
abiFlag: number
eNetworkType: number
showName: string
termDesc: string
musicInfo: {
buf: unknown
}
extOnlineBusinessInfo: {
buf: unknown
customStatus: unknown
videoBizInfo: {
cid: string
tvUrl: string
synchType: string
}
videoInfo: {
name: string
}
}
extBuffer: {
buf: unknown
}
}
export interface UserVasInfo {
/**
* VIP
*/
vipFlag: boolean
/**
* VIP
*/
yearVipFlag: boolean
/**
* SVIP
*/
svipFlag: boolean
/**
* VIP
*/
vipLevel: number
/**
*
*/
bigClub: boolean
/**
*
*/
bigClubLevel: number
nameplateVipType: number
grayNameplateFlag: number
superVipTemplateId: number
diyFontId: number
pendantId: number
pendantDiyId: number
faceId: number
vipFont: number
vipFontType: number
magicFont: number
fontEffect: number
newLoverDiamondFlag: number
extendNameplateId: number
diyNameplateIDs: unknown[]
vipStartFlag: number
vipDataFlag: number
gameNameplateId: string
gameLastLoginTime: string
gameRank: number
gameIconShowFlag: boolean
gameCardId: string
/**
* VIP
*/
vipNameColorId: string
privilegeIcon: null
}
export interface UserRelationFlags {
topTime: string
isBlock: boolean
isMsgDisturb: boolean
isSpecialCareOpen: boolean
isSpecialCareZone: boolean
ringId: string
isBlocked: boolean
recommendImgFlag: number
disableEmojiShortCuts: number
qidianMasterFlag: number
qidianCrewFlag: number
qidianCrewFlag2: number
isHideQQLevel: number
isHidePrivilegeIcon: number
} }
export interface OnAddSendMsg { export interface OnAddSendMsg {