refactor: sendmsg

This commit is contained in:
手瓜一十雪 2024-07-23 09:21:22 +08:00
parent 0efdffd857
commit fc7631f9aa
3 changed files with 23 additions and 8 deletions

View File

@ -174,12 +174,25 @@ export class NTQQMsgApi {
'NodeIKernelMsgListener/onMsgInfoListUpdate',
timeout,
1,
() => true,
(msgRecords: RawMessage[]) => {
for (let msgRecord of msgRecords) {
if (msgRecord.msgId === msgId && msgRecord.sendStatus === 2) {
return true;
}
}
return false;
},
msgId,
peer,
msgElements,
new Map()
);
let retMsg = data[1].find(msgRecord => {
if (msgRecord.msgId === msgId) {
return true;
}
});
return retMsg;
//const result = napCatCore.session.getMsgService().sendMsg(msgId, peer, msgElements, new Map());
}
// static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000): Promise<RawMessage> {

View File

@ -53,13 +53,13 @@ export async function handleForwardNode(destPeer: Peer, messageNodes: OB11Messag
const nodeId = messageNode.data.id;
// 有nodeId表示一个子转发消息卡片
if (nodeId) {
const nodeMsg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(nodeId));
const nodeMsg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(nodeId));
if (!needClone) {
nodeMsgIds.push(nodeMsg!.MsgId);
} else {
if (nodeMsg!.Peer.peerUid !== selfInfo.uid) {
// need cloning
const rawClone = await NTQQMsgApi.getMsgsByMsgId(nodeMsg?.Peer!,[nodeMsg?.MsgId!]);
const rawClone = await NTQQMsgApi.getMsgsByMsgId(nodeMsg?.Peer!, [nodeMsg?.MsgId!]);
const clonedMsg = await cloneMsg(rawClone.msgList[0]);
if (clonedMsg) {
nodeMsgIds.push(clonedMsg.msgId);
@ -91,7 +91,7 @@ export async function handleForwardNode(destPeer: Peer, messageNodes: OB11Messag
//logDebug(sendElementsSplit);
}
// log("分割后的转发节点", sendElementsSplit)
const MsgNodeList: Promise<RawMessage>[] = [];
const MsgNodeList: Promise<RawMessage | undefined>[] = [];
for (const sendElementsSplitElement of sendElementsSplit) {
MsgNodeList.push(sendMsg(selfPeer, sendElementsSplitElement, [], true));
await sleep(Math.trunc(sendElementsSplit.length / 10) * 100);
@ -99,7 +99,9 @@ export async function handleForwardNode(destPeer: Peer, messageNodes: OB11Messag
}
for (const msgNode of MsgNodeList) {
const result = await msgNode;
nodeMsgIds.push(result.msgId);
if (result) {
nodeMsgIds.push(result.msgId);
}
//logDebug('转发节点生成成功', result.msgId);
}
} catch (e) {

View File

@ -66,10 +66,10 @@ export async function sendMsg(peer: Peer, sendElements: SendMessageElement[], de
}
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, timeout);
try {
returnMsg.id = await MessageUnique.createMsg({ chatType: peer.chatType, guildId: '', peerUid: peer.peerUid }, returnMsg.msgId);
returnMsg!.id = await MessageUnique.createMsg({ chatType: peer.chatType, guildId: '', peerUid: peer.peerUid }, returnMsg!.msgId);
} catch (e: any) {
logDebug('发送消息id获取失败', e);
returnMsg.id = 0;
returnMsg!.id = 0;
}
deleteAfterSentFiles.map((f) => {
@ -172,7 +172,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
const { sendElements, deleteAfterSentFiles } = await createSendElements(messages, group);
//console.log(peer, JSON.stringify(sendElements,null,2));
const returnMsg = await sendMsg(peer, sendElements, deleteAfterSentFiles);
return { message_id: returnMsg.id! };
return { message_id: returnMsg!.id! };
}
}