feat: implement uix add

This commit is contained in:
Il Harper 2024-03-05 22:27:50 +08:00
parent 94262588fc
commit af389039cc
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
2 changed files with 110 additions and 1 deletions

View File

@ -2,12 +2,18 @@ import type {
OnAddSendMsg,
OnBuddyListChange,
OnGroupListUpdate,
OnMemberInfoChange,
OnMemberListChange,
OnMsgInfoListUpdate,
OnProfileChanged,
OnRecentContactListChangedVer2,
OnRecvMsg,
OnRichMediaDownloadComplete,
RedIpcArgs,
RedIpcDataEvent,
RedIpcDataRequest,
} from '@chronocat/red'
import { ChatType } from '@chronocat/red'
import type { ChronocatContext } from '@chronocat/shell'
import type { IpcManData } from 'ipcman'
import { ipcMan } from 'ipcman'
@ -30,6 +36,18 @@ export const version = __DEFINE_CHRONO_VERSION__
export const apply = async (ctx: ChronocatContext) => {
const dispatcher = async (method: string, payload: unknown) => {
switch (method) {
case 'nodeIKernelMsgListener/onRecvMsg': {
const { msgList } = payload as OnRecvMsg
for (const msg of msgList) {
ctx.chronocat.uix.add(msg.senderUid, msg.senderUin)
if (msg.chatType === ChatType.Private)
ctx.chronocat.uix.add(msg.peerUid, msg.peerUin)
}
return
}
case 'nodeIKernelMsgListener/onRichMediaDownloadComplete': {
const { notifyInfo } = payload as OnRichMediaDownloadComplete
@ -43,6 +61,45 @@ export const apply = async (ctx: ChronocatContext) => {
return
}
case 'nodeIKernelProfileListener/onProfileSimpleChanged':
case 'nodeIKernelProfileListener/onProfileDetailInfoChanged':
case 'nodeIKernelGroupListener/onSearchMemberChange':
case 'nodeIKernelGroupService/getNextMemberList': {
// const authData = await ctx.chronocat.getAuthData()
const { profiles, infos } = payload as OnProfileChanged
// if (profiles.get(authData.uid))
// selfProfile.value = profiles.get(authData.uid)
const profile = profiles ?? infos
for (const [uid, { uin }] of profile) ctx.chronocat.uix.add(uid, uin)
return
}
case 'nodeIKernelGroupListener/onMemberInfoChange': {
const { members } = payload as OnMemberInfoChange
for (const [uid, { uin }] of members) {
ctx.chronocat.uix.add(uid, uin)
}
return
}
case 'nodeIKernelGroupListener/onMemberListChange': {
const { info } = payload as OnMemberListChange
const groupCode = info.sceneId.split('_')[0]
if (!groupCode) return
for (const [uid, { uin }] of info.infos) {
ctx.chronocat.uix.add(uid, uin)
}
return
}
case 'onGroupListUpdate':
case 'nodeIKernelGroupListener/onGroupListUpdate': {
const { groupList } = payload as OnGroupListUpdate
@ -60,6 +117,8 @@ export const apply = async (ctx: ChronocatContext) => {
for (const category of data) {
for (const buddy of category.buddyList) {
ctx.chronocat.uix.add(buddy.uid, buddy.uin)
// buddy.category = category.categoryName
friendMap[buddy.uin] = buddy
}
@ -68,6 +127,20 @@ export const apply = async (ctx: ChronocatContext) => {
return
}
case 'nodeIKernelRecentContactListener/onRecentContactListChangedVer2': {
const { changedRecentContactLists } =
payload as OnRecentContactListChangedVer2
for (const changedRecentContactList of changedRecentContactLists)
for (const contact of changedRecentContactList.changedList) {
ctx.chronocat.uix.add(contact.senderUid, contact.senderUin)
if (contact.chatType === ChatType.Private)
ctx.chronocat.uix.add(contact.peerUid, contact.peerUin)
}
return
}
case 'nodeIKernelMsgListener/onAddSendMsg': {
const { msgRecord } = payload as OnAddSendMsg
sendCallbackMap[msgRecord.msgId] = sendQueue.shift()!

View File

@ -1,10 +1,12 @@
import type {
Element,
OnBuddyListChange,
OnBuddyReqChange,
OnMemberInfoChange,
OnMemberListChange,
OnMsgInfoListUpdate,
OnProfileChanged,
OnRecentContactListChangedVer2,
OnRecvMsg,
Peer,
RedIpcArgs,
@ -12,7 +14,7 @@ import type {
RedIpcDataRequest,
RedMessage,
} from '@chronocat/red'
import { MsgType, SendType } from '@chronocat/red'
import { ChatType, MsgType, SendType } from '@chronocat/red'
import type { ChronocatContext } from '@chronocat/shell'
import type { IpcManData } from 'ipcman'
import { ipcMan } from 'ipcman'
@ -34,6 +36,12 @@ export const apply = async (ctx: ChronocatContext) => {
case 'nodeIKernelMsgListener/onRecvMsg': {
const { msgList } = payload as OnRecvMsg
for (const msg of msgList) {
ctx.chronocat.uix.add(msg.senderUid, msg.senderUin)
if (msg.chatType === ChatType.Private)
ctx.chronocat.uix.add(msg.peerUid, msg.peerUin)
}
// const prepareRole = async (msg: Message) => {
// if (msg.chatType === ChatType.Group) {
// await getMemberInfo({
@ -62,6 +70,7 @@ export const apply = async (ctx: ChronocatContext) => {
if (filteredPayload.length)
ctx.chronocat.emit(new MessageCreatedDispatchMessage(filteredPayload))
return
}
@ -110,6 +119,33 @@ export const apply = async (ctx: ChronocatContext) => {
return
}
case 'nodeIKernelRecentContactListener/onRecentContactListChangedVer2': {
const { changedRecentContactLists } =
payload as OnRecentContactListChangedVer2
for (const changedRecentContactList of changedRecentContactLists)
for (const contact of changedRecentContactList.changedList) {
ctx.chronocat.uix.add(contact.senderUid, contact.senderUin)
if (contact.chatType === ChatType.Private)
ctx.chronocat.uix.add(contact.peerUid, contact.peerUin)
}
return
}
case 'onBuddyListChange':
case 'nodeIKernelBuddyListener/onBuddyListChange': {
const { data } = payload as OnBuddyListChange
for (const category of data) {
for (const buddy of category.buddyList) {
ctx.chronocat.uix.add(buddy.uid, buddy.uin)
}
}
return
}
case 'nodeIKernelBuddyListener/onBuddyReqChange': {
const { buddyReqs } = payload as OnBuddyReqChange