Skip to content

Commit

Permalink
feat: report non-chronocat sent message
Browse files Browse the repository at this point in the history
  • Loading branch information
ilharp committed Apr 7, 2024
1 parent df00728 commit cc5de2b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
2 changes: 2 additions & 0 deletions packages/engine-chronocat-event/src/globalVars.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const requestMethodMap: Record<string, string> = {}
export const emittedBuddyReqList: string[] = []

export const sendQueue: string[] = []
17 changes: 16 additions & 1 deletion packages/engine-chronocat-event/src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
Element,
MsgsIncludeSelf,
OnAddSendMsg,
OnBuddyListChange,
OnBuddyReqChange,
OnMemberInfoChange,
Expand All @@ -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,
Expand Down Expand Up @@ -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

Expand All @@ -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(
Expand Down
37 changes: 14 additions & 23 deletions packages/shell/src/satori/routes/message/create.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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

toSatori = async (
_ctx: ChronocatContext,
_config: O.Intersect<
ChronocatLogCurrentConfig,
ChronocatSatoriEventsConfig
>,
) => this.events
}
// export class MessageCreatedDispatchMessage implements SatoriDispatchMessage {
// constructor(private events: Event[]) {}
// type = 'satori' as const

// toSatori = async (
// _ctx: ChronocatContext,
// _config: O.Intersect<
// ChronocatLogCurrentConfig,
// ChronocatSatoriEventsConfig
// >,
// ) => this.events
// }

0 comments on commit cc5de2b

Please sign in to comment.