refactor: 回复

This commit is contained in:
手瓜一十雪 2024-07-29 10:07:59 +08:00
parent c59b5564af
commit 5613450313

View File

@ -143,43 +143,35 @@ export class OB11Constructor {
//log("收到回复消息", element.replyElement); //log("收到回复消息", element.replyElement);
try { try {
//做这么多都是因为NC速度太快 可能nt还没有写入数据库 //做这么多都是因为NC速度太快 可能nt还没有写入数据库
const records = msg.records.find(msgRecord => msgRecord.msgId === element.replyElement.sourceMsgIdInRecords); //const records = msg.records.find(msgRecord => msgRecord.msgId === element.replyElement.sourceMsgIdInRecords);
if (!records) {
throw new Error('Record筛选失败');
}
const peer = { const peer = {
chatType: msg.chatType, chatType: msg.chatType,
peerUid: msg.peerUid, peerUid: msg.peerUid,
guildId: '', guildId: '',
}; };
let replyMsg: RawMessage | undefined; let replyMsg: RawMessage | undefined;
replyMsg = (await NTQQMsgApi.getMsgsBySeqAndCount({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, element.replyElement.replayMsgSeq, 1, true, true)).msgList[0]; replyMsg = (await NTQQMsgApi.getMsgsBySeqAndCount({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, element.replyElement.replayMsgSeq, 1, true, true)).msgList[0];
if (!replyMsg || replyMsg.msgRandom !== records.msgRandom) { if (!replyMsg || element.replyElement.replayMsgSeq !== replyMsg.msgSeq) {
replyMsg = (await NTQQMsgApi.getMsgsByMsgId(peer, MessageUnique.getRecentMsgIds(peer, 50))).msgList.find((msg) => msg.msgRandom == records.msgRandom && msg.msgSeq == element.replyElement.replayMsgSeq);
}
if (!replyMsg || replyMsg.msgRandom !== records.msgRandom) {
replyMsg = (await NTQQMsgApi.queryMsgsWithFilterExWithSeq( replyMsg = (await NTQQMsgApi.queryMsgsWithFilterExWithSeq(
peer, peer,
element.replyElement.replayMsgSeq, element.replyElement.replayMsgSeq,
records.msgTime, '0',
records.senderUid '0'
)).msgList[0]; )).msgList[0];
} }
if (!replyMsg || replyMsg.msgRandom !== records.msgRandom) { if (!replyMsg || element.replyElement.replayMsgSeq !== replyMsg.msgSeq) {
replyMsg = (await NTQQMsgApi.getSingleMsg(peer, element.replyElement.replayMsgSeq)).msgList[0]; replyMsg = (await NTQQMsgApi.getSingleMsg(peer, element.replyElement.replayMsgSeq)).msgList[0];
} }
if (!replyMsg || replyMsg.msgRandom !== records.msgRandom) {
if (!replyMsg || element.replyElement.replayMsgSeq !== replyMsg.msgSeq) {
throw new Error('回复消息消息验证失败'); throw new Error('回复消息消息验证失败');
} }
if (replyMsg) { message_data['data']['id'] = MessageUnique.createMsg({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, replyMsg.msgId)?.toString();
message_data['data']['id'] = MessageUnique.createMsg({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, replyMsg.msgId)?.toString();
}
else {
continue;
}
//log("找到回复消息", message_data['data']['id'], replyMsg.msgList[0].msgId) //log("找到回复消息", message_data['data']['id'], replyMsg.msgList[0].msgId)
} catch (e: any) { } catch (e: any) {
message_data['type'] = "unknown";
message_data['data'] = undefined;
logError('获取不到引用的消息', e.stack, element.replyElement.replayMsgSeq); logError('获取不到引用的消息', e.stack, element.replyElement.replayMsgSeq);
} }
@ -214,13 +206,13 @@ export class OB11Constructor {
chatType: msg.chatType, chatType: msg.chatType,
guildId: '', guildId: '',
}, },
msg.msgId, msg.msgId,
msg.msgSeq, msg.msgSeq,
msg.senderUid, msg.senderUid,
element.elementId, element.elementId,
element.elementType.toString(), element.elementType.toString(),
FileElement.fileSize, FileElement.fileSize,
FileElement.fileName FileElement.fileName
); );
} }
else if (element.videoElement) { else if (element.videoElement) {
@ -261,13 +253,13 @@ export class OB11Constructor {
chatType: msg.chatType, chatType: msg.chatType,
guildId: '', guildId: '',
}, },
msg.msgId, msg.msgId,
msg.msgSeq, msg.msgSeq,
msg.senderUid, msg.senderUid,
element.elementId, element.elementId,
element.elementType.toString(), element.elementType.toString(),
videoElement.fileSize || '0', videoElement.fileSize || '0',
videoElement.fileName videoElement.fileName
); );
} }
else if (element.pttElement) { else if (element.pttElement) {
@ -292,13 +284,13 @@ export class OB11Constructor {
chatType: msg.chatType, chatType: msg.chatType,
guildId: '', guildId: '',
}, },
msg.msgId, msg.msgId,
msg.msgSeq, msg.msgSeq,
msg.senderUid, msg.senderUid,
element.elementId, element.elementId,
element.elementType.toString(), element.elementType.toString(),
element.pttElement.fileSize || '0', element.pttElement.fileSize || '0',
element.pttElement.fileUuid || '' element.pttElement.fileUuid || ''
); );
//以uuid作为文件名 //以uuid作为文件名
} }