mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-25 18:03:40 +00:00
feat(api): implement event handlers
This commit is contained in:
parent
cd69bb4fb4
commit
e0b7ab6d3c
@ -1,4 +1,10 @@
|
|||||||
import type { Group, Profile, RedIpcData, RedIpcEvent } from '@chronocat/red'
|
import type {
|
||||||
|
Group,
|
||||||
|
Profile,
|
||||||
|
RedIpcData,
|
||||||
|
RedIpcEvent,
|
||||||
|
RedMessage,
|
||||||
|
} from '@chronocat/red'
|
||||||
import { ChronoEventEmitter } from './emitter'
|
import { ChronoEventEmitter } from './emitter'
|
||||||
|
|
||||||
export const requestMethodMap: Record<string, string> = {}
|
export const requestMethodMap: Record<string, string> = {}
|
||||||
@ -12,4 +18,7 @@ export const roleMap: Record<string, Record<string, number>> = {}
|
|||||||
export const friendMap: Record<string, Profile> = {}
|
export const friendMap: Record<string, Profile> = {}
|
||||||
export const richMediaDownloadMap: Record<string, (path: string) => void> = {}
|
export const richMediaDownloadMap: Record<string, (path: string) => void> = {}
|
||||||
|
|
||||||
|
export const sendQueue: ((msg: RedMessage) => void)[] = []
|
||||||
|
export const sendCallbackMap: Record<string, (msg: RedMessage) => void> = {}
|
||||||
|
|
||||||
export const chronoEventEmitter = new ChronoEventEmitter()
|
export const chronoEventEmitter = new ChronoEventEmitter()
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
import type {
|
import type {
|
||||||
|
OnAddSendMsg,
|
||||||
|
OnBuddyListChange,
|
||||||
|
OnGroupListUpdate,
|
||||||
|
OnMsgInfoListUpdate,
|
||||||
OnRichMediaDownloadComplete,
|
OnRichMediaDownloadComplete,
|
||||||
RedIpcArgs,
|
RedIpcArgs,
|
||||||
RedIpcDataEvent,
|
RedIpcDataEvent,
|
||||||
@ -8,7 +12,15 @@ import type { ChronocatContext } from '@chronocat/shell'
|
|||||||
import type { IpcManData } from 'ipcman'
|
import type { IpcManData } from 'ipcman'
|
||||||
import { ipcMan } from 'ipcman'
|
import { ipcMan } from 'ipcman'
|
||||||
import { buildAssetsGet } from './api/internal/assets/get'
|
import { buildAssetsGet } from './api/internal/assets/get'
|
||||||
import { requestMethodMap, richMediaDownloadMap } from './globalVars'
|
import {
|
||||||
|
chronoEventEmitter,
|
||||||
|
friendMap,
|
||||||
|
groupMap,
|
||||||
|
requestMethodMap,
|
||||||
|
richMediaDownloadMap,
|
||||||
|
sendCallbackMap,
|
||||||
|
sendQueue,
|
||||||
|
} from './globalVars'
|
||||||
|
|
||||||
declare const __DEFINE_CHRONO_VERSION__: string
|
declare const __DEFINE_CHRONO_VERSION__: string
|
||||||
|
|
||||||
@ -27,6 +39,50 @@ export const apply = async (ctx: ChronocatContext) => {
|
|||||||
richMediaDownloadMap[downloadId]!(notifyInfo.filePath)
|
richMediaDownloadMap[downloadId]!(notifyInfo.filePath)
|
||||||
delete richMediaDownloadMap[downloadId]
|
delete richMediaDownloadMap[downloadId]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'onGroupListUpdate':
|
||||||
|
case 'nodeIKernelGroupListener/onGroupListUpdate': {
|
||||||
|
const { groupList } = payload as OnGroupListUpdate
|
||||||
|
|
||||||
|
for (const group of groupList) groupMap[group.groupCode] = group
|
||||||
|
|
||||||
|
chronoEventEmitter.emitGroupListUpdate()
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'onBuddyListChange':
|
||||||
|
case 'nodeIKernelBuddyListener/onBuddyListChange': {
|
||||||
|
const { data } = payload as OnBuddyListChange
|
||||||
|
|
||||||
|
for (const category of data) {
|
||||||
|
for (const buddy of category.buddyList) {
|
||||||
|
// buddy.category = category.categoryName
|
||||||
|
friendMap[buddy.uin] = buddy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'nodeIKernelMsgListener/onAddSendMsg': {
|
||||||
|
const { msgRecord } = payload as OnAddSendMsg
|
||||||
|
sendCallbackMap[msgRecord.msgId] = sendQueue.shift()!
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'nodeIKernelMsgListener/onMsgInfoListUpdate': {
|
||||||
|
const { msgList } = payload as OnMsgInfoListUpdate
|
||||||
|
for (const msg of msgList) {
|
||||||
|
if (msg.sendStatus > 1) {
|
||||||
|
// sendCallbackMap[msg.msgId]?.(await uixCache.preprocessObject(msg))
|
||||||
|
delete sendCallbackMap[msg.msgId]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user