fix: 合并转发

This commit is contained in:
手瓜一十雪 2024-07-23 14:19:26 +08:00
parent 7ecb01dc9f
commit 5cc5149aed
3 changed files with 13 additions and 17 deletions

View File

@ -75,6 +75,7 @@ class MessageUniqueWrapper {
const hash = crypto.createHash('sha1').update(key); const hash = crypto.createHash('sha1').update(key);
const shortId = parseInt(hash.digest('hex').slice(0, 8), 16); const shortId = parseInt(hash.digest('hex').slice(0, 8), 16);
const isExist = this.msgIdMap.getKey(shortId); const isExist = this.msgIdMap.getKey(shortId);
console.log(`${peer.peerUid} ${msgId} ------- ${shortId}`);
if (isExist && isExist === msgId) { if (isExist && isExist === msgId) {
return shortId; return shortId;
} }
@ -84,7 +85,7 @@ class MessageUniqueWrapper {
} }
getMsgIdAndPeerByShortId(shortId: number): { MsgId: string; Peer: Peer } | undefined { getMsgIdAndPeerByShortId(shortId: number): { MsgId: string; Peer: Peer } | undefined {
const data = this.msgIdMap.getKey(shortId); const data = this.msgDataMap.getKey(shortId);
if (data) { if (data) {
const [msgId, chatTypeStr, peerUid] = data.split('|'); const [msgId, chatTypeStr, peerUid] = data.split('|');
const peer: Peer = { const peer: Peer = {

View File

@ -52,19 +52,13 @@ msgListener.onGroupFileInfoUpdate = (groupFileListResult: onGroupFileInfoUpdateP
} }
}; };
// msgListener.onAddSendMsg = (msgRecord: RawMessage) => { msgListener.onAddSendMsg = (msgRecord: RawMessage) => {
// // console.log("sent msg", msgRecord, sendMessagePool); // console.log("sent msg", msgRecord, sendMessagePool);
// for (const [uuid, cb] of sentMsgTasks) { for (const [uuid, cb] of sentMsgTasks) {
// cb(msgRecord); cb(msgRecord);
// sentMsgTasks.delete(uuid); sentMsgTasks.delete(uuid);
// } }
// if (sendMessagePool[msgRecord.peerUid]) { };
// const r = sendMessagePool[msgRecord.peerUid]?.(msgRecord);
// if (r instanceof Promise) {
// r.then().catch(logError);
// }
// }
// };
// msgListener.onMsgInfoListUpdate = (msgInfoList: RawMessage[]) => { // msgListener.onMsgInfoListUpdate = (msgInfoList: RawMessage[]) => {
// msgInfoList.forEach(msg => { // msgInfoList.forEach(msg => {

View File

@ -13,7 +13,7 @@ async function cloneMsg(msg: RawMessage): Promise<RawMessage | undefined> {
peerUid: selfInfo.uid peerUid: selfInfo.uid
}; };
// logDebug('克隆的目标消息', msg); //logDebug('克隆的目标消息', msg);
const sendElements: SendMessageElement[] = []; const sendElements: SendMessageElement[] = [];
@ -109,14 +109,15 @@ export async function handleForwardNode(destPeer: Peer, messageNodes: OB11Messag
} }
} }
} }
// 检查srcPeer是否一致不一致则需要克隆成自己的消息, 让所有srcPeer都变成自己的使其保持一致才能够转发 // 检查srcPeer是否一致不一致则需要克隆成自己的消息, 让所有srcPeer都变成自己的使其保持一致才能够转发
const nodeMsgArray: Array<RawMessage> = []; const nodeMsgArray: Array<RawMessage> = [];
let srcPeer: Peer | undefined = undefined; let srcPeer: Peer | undefined = undefined;
let needSendSelf = false; let needSendSelf = false;
for (const msgId of nodeMsgIds) { for (const msgId of nodeMsgIds) {
const nodeMsgPeer = await MessageUnique.getPeerByMsgId(msgId); const nodeMsgPeer = await MessageUnique.getPeerByMsgId(msgId);
const nodeMsg = (await NTQQMsgApi.getMsgsByMsgId(nodeMsgPeer?.Peer!, [msgId])).msgList[0]; const nodeMsg = (await NTQQMsgApi.getMsgsByMsgId(nodeMsgPeer?.Peer!, [msgId])).msgList[0];
console.log("4545",nodeMsgPeer);
if (nodeMsg) { if (nodeMsg) {
nodeMsgArray.push(nodeMsg); nodeMsgArray.push(nodeMsg);
if (!srcPeer) { if (!srcPeer) {
@ -127,7 +128,7 @@ export async function handleForwardNode(destPeer: Peer, messageNodes: OB11Messag
} }
} }
} }
//logDebug('nodeMsgArray', nodeMsgArray); // logDebug('nodeMsgArray', nodeMsgArray);
nodeMsgIds = nodeMsgArray.map(msg => msg.msgId); nodeMsgIds = nodeMsgArray.map(msg => msg.msgId);
if (needSendSelf) { if (needSendSelf) {
//logDebug('需要克隆转发消息'); //logDebug('需要克隆转发消息');