feat: report non-chronocat sent message

This commit is contained in:
Il Harper 2024-04-08 00:13:14 +08:00
parent df007281ef
commit cc5de2b05c
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
3 changed files with 31 additions and 23 deletions

View File

@ -1,2 +1,4 @@
export const requestMethodMap: Record<string, string> = {}
export const emittedBuddyReqList: string[] = []
export const sendQueue: string[] = []

View File

@ -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(

View File

@ -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
// }