From cc5de2b05c8d08c45e563f6f3db4f4503696e67d Mon Sep 17 00:00:00 2001 From: Il Harper Date: Mon, 8 Apr 2024 00:13:14 +0800 Subject: [PATCH] feat: report non-chronocat sent message --- .../engine-chronocat-event/src/globalVars.ts | 2 ++ .../engine-chronocat-event/src/handler.ts | 17 ++++++++- .../shell/src/satori/routes/message/create.ts | 35 +++++++------------ 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/packages/engine-chronocat-event/src/globalVars.ts b/packages/engine-chronocat-event/src/globalVars.ts index 8830d27..e1c43e7 100644 --- a/packages/engine-chronocat-event/src/globalVars.ts +++ b/packages/engine-chronocat-event/src/globalVars.ts @@ -1,2 +1,4 @@ export const requestMethodMap: Record = {} export const emittedBuddyReqList: string[] = [] + +export const sendQueue: string[] = [] diff --git a/packages/engine-chronocat-event/src/handler.ts b/packages/engine-chronocat-event/src/handler.ts index 7d5d4b1..0c9ae6e 100644 --- a/packages/engine-chronocat-event/src/handler.ts +++ b/packages/engine-chronocat-event/src/handler.ts @@ -1,6 +1,7 @@ import type { Element, MsgsIncludeSelf, + OnAddSendMsg, OnBuddyListChange, OnBuddyReqChange, OnMemberInfoChange, @@ -18,7 +19,7 @@ import type { import { ChatType, MsgType, SendType } from '@chronocat/red' import type { ChronocatContext } from '@chronocat/shell' import type { IpcManData } from 'ipcman' -import { emittedBuddyReqList, requestMethodMap } from './globalVars' +import { emittedBuddyReqList, requestMethodMap, sendQueue } from './globalVars' import { FriendRequestDispatchMessage, MessageCreatedDispatchMessage, @@ -216,6 +217,13 @@ const dispatcher = async ( return } + case 'nodeIKernelMsgListener/onAddSendMsg': { + const { msgRecord } = payload as OnAddSendMsg + // msgRecord.sendStatus === 1, sending + sendQueue.push(msgRecord.msgId) + return + } + case 'nodeIKernelMsgListener/onMsgInfoListUpdate': { const { msgList } = payload as OnMsgInfoListUpdate @@ -225,6 +233,13 @@ const dispatcher = async ( ctx.chronocat.uix.add(msg.peerUid, msg.peerUin) } + msgList + .filter((x) => x.sendStatus > 1 && sendQueue.find((y) => x.msgId === y)) + .forEach((x) => { + sendQueue.splice(sendQueue.indexOf(x.msgId), 1) + ctx.chronocat.emit(new MessageCreatedDispatchMessage([x])) + }) + const filteredPayload = await Promise.all( msgList .filter( diff --git a/packages/shell/src/satori/routes/message/create.ts b/packages/shell/src/satori/routes/message/create.ts index 264ba80..9ea514b 100644 --- a/packages/shell/src/satori/routes/message/create.ts +++ b/packages/shell/src/satori/routes/message/create.ts @@ -1,13 +1,4 @@ -import type { O } from 'ts-toolbelt' -import type { - ChronocatLogCurrentConfig, - ChronocatSatoriEventsConfig, -} from '../../../services/config/configEntity' -import type { ChronocatContext, SatoriDispatchMessage } from '../../../types' -import type { - Event, - MessageCreatePayload as MessageCreatePayloadRich, -} from '../../types' +import type { MessageCreatePayload as MessageCreatePayloadRich } from '../../types' import type { MessageCreatePayload as MessageCreatePayloadEntity } from '../../types/satoriPayloadEntity' import type { RouteContext } from '../types' @@ -137,20 +128,20 @@ async function messageCreateUsingJson({ const result = await cctx.chronocat.api[method](payloadRich, config) - cctx.chronocat.emit(new MessageCreatedDispatchMessage(result)) + // cctx.chronocat.emit(new MessageCreatedDispatchMessage(result)) return result.map((x) => x.message).filter(Boolean) } -export class MessageCreatedDispatchMessage implements SatoriDispatchMessage { - constructor(private events: Event[]) {} - type = 'satori' as const +// export class MessageCreatedDispatchMessage implements SatoriDispatchMessage { +// constructor(private events: Event[]) {} +// type = 'satori' as const - toSatori = async ( - _ctx: ChronocatContext, - _config: O.Intersect< - ChronocatLogCurrentConfig, - ChronocatSatoriEventsConfig - >, - ) => this.events -} +// toSatori = async ( +// _ctx: ChronocatContext, +// _config: O.Intersect< +// ChronocatLogCurrentConfig, +// ChronocatSatoriEventsConfig +// >, +// ) => this.events +// }