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 requestMethodMap: Record<string, string> = {}
export const emittedBuddyReqList: string[] = [] export const emittedBuddyReqList: string[] = []
export const sendQueue: string[] = []

View File

@ -1,6 +1,7 @@
import type { import type {
Element, Element,
MsgsIncludeSelf, MsgsIncludeSelf,
OnAddSendMsg,
OnBuddyListChange, OnBuddyListChange,
OnBuddyReqChange, OnBuddyReqChange,
OnMemberInfoChange, OnMemberInfoChange,
@ -18,7 +19,7 @@ import type {
import { ChatType, MsgType, SendType } from '@chronocat/red' import { ChatType, MsgType, SendType } from '@chronocat/red'
import type { ChronocatContext } from '@chronocat/shell' import type { ChronocatContext } from '@chronocat/shell'
import type { IpcManData } from 'ipcman' import type { IpcManData } from 'ipcman'
import { emittedBuddyReqList, requestMethodMap } from './globalVars' import { emittedBuddyReqList, requestMethodMap, sendQueue } from './globalVars'
import { import {
FriendRequestDispatchMessage, FriendRequestDispatchMessage,
MessageCreatedDispatchMessage, MessageCreatedDispatchMessage,
@ -216,6 +217,13 @@ const dispatcher = async (
return return
} }
case 'nodeIKernelMsgListener/onAddSendMsg': {
const { msgRecord } = payload as OnAddSendMsg
// msgRecord.sendStatus === 1, sending
sendQueue.push(msgRecord.msgId)
return
}
case 'nodeIKernelMsgListener/onMsgInfoListUpdate': { case 'nodeIKernelMsgListener/onMsgInfoListUpdate': {
const { msgList } = payload as OnMsgInfoListUpdate const { msgList } = payload as OnMsgInfoListUpdate
@ -225,6 +233,13 @@ const dispatcher = async (
ctx.chronocat.uix.add(msg.peerUid, msg.peerUin) 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( const filteredPayload = await Promise.all(
msgList msgList
.filter( .filter(

View File

@ -1,13 +1,4 @@
import type { O } from 'ts-toolbelt' import type { MessageCreatePayload as MessageCreatePayloadRich } from '../../types'
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 MessageCreatePayloadEntity } from '../../types/satoriPayloadEntity' import type { MessageCreatePayload as MessageCreatePayloadEntity } from '../../types/satoriPayloadEntity'
import type { RouteContext } from '../types' import type { RouteContext } from '../types'
@ -137,20 +128,20 @@ async function messageCreateUsingJson({
const result = await cctx.chronocat.api[method](payloadRich, config) 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) return result.map((x) => x.message).filter(Boolean)
} }
export class MessageCreatedDispatchMessage implements SatoriDispatchMessage { // export class MessageCreatedDispatchMessage implements SatoriDispatchMessage {
constructor(private events: Event[]) {} // constructor(private events: Event[]) {}
type = 'satori' as const // type = 'satori' as const
toSatori = async ( // toSatori = async (
_ctx: ChronocatContext, // _ctx: ChronocatContext,
_config: O.Intersect< // _config: O.Intersect<
ChronocatLogCurrentConfig, // ChronocatLogCurrentConfig,
ChronocatSatoriEventsConfig // ChronocatSatoriEventsConfig
>, // >,
) => this.events // ) => this.events
} // }