mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: message id
This commit is contained in:
parent
8db294efe6
commit
2d76bcf0cf
@ -1,5 +1,6 @@
|
|||||||
import { Peer } from '@/core';
|
import { Peer } from '@/core';
|
||||||
import crypto, { randomInt, randomUUID } from 'crypto';
|
import crypto, { randomInt, randomUUID } from 'crypto';
|
||||||
|
import { logError } from './log';
|
||||||
|
|
||||||
class LimitedHashTable<K, V> {
|
class LimitedHashTable<K, V> {
|
||||||
private keyToValue: Map<K, V> = new Map();
|
private keyToValue: Map<K, V> = new Map();
|
||||||
@ -75,7 +76,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}`);
|
//console.log(`${peer.peerUid} ${msgId} ------- ${shortId}`);
|
||||||
if (isExist && isExist === msgId) {
|
if (isExist && isExist === msgId) {
|
||||||
return shortId;
|
return shortId;
|
||||||
}
|
}
|
||||||
|
@ -8,30 +8,39 @@ import { GeneralCallResult } from '@/core/services/common';
|
|||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { MessageUnique } from '../../../common/utils/MessageUnique';
|
import { MessageUnique } from '../../../common/utils/MessageUnique';
|
||||||
import { NTEventDispatch } from '@/common/utils/EventTask';
|
import { NTEventDispatch } from '@/common/utils/EventTask';
|
||||||
|
async function LoadMessageIdList(Peer: Peer, msgId: string) {
|
||||||
|
let msgList = await NTQQMsgApi.getMsgHistory(Peer, msgId, 50);
|
||||||
|
for (let j = 0; j < msgList.msgList.length; j++) {
|
||||||
|
let shortId = MessageUnique.createMsg(Peer, msgList.msgList[j].msgId);
|
||||||
|
//console.log(`开始创建 ${shortId}<------>${msgList.msgList[j].msgId}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function loadMessageUnique() {
|
||||||
|
if (groups.size > 100) {
|
||||||
|
logWarn('群数量大于100,可能会导致性能问题');
|
||||||
|
}
|
||||||
|
let predict = (groups.size + friends.size) / 5;
|
||||||
|
predict = predict < 20 ? 20 : predict;
|
||||||
|
predict = predict > 50 ? 50 : predict;
|
||||||
|
//let waitpromise: Array<Promise<{ msgList: RawMessage[]; }>> = [];
|
||||||
|
MessageUnique.resize(predict * 50);
|
||||||
|
let RecentContact = await NTQQUserApi.getRecentContactListSnapShot(predict);
|
||||||
|
let LoadMessageIdDo: Array<Promise<void>> = new Array<Promise<void>>();
|
||||||
|
if (RecentContact?.info?.changedList && RecentContact?.info?.changedList?.length > 0) {
|
||||||
|
for (let i = 0; i < RecentContact.info.changedList.length; i++) {
|
||||||
|
let Peer: Peer = { chatType: RecentContact.info.changedList[i].chatType, peerUid: RecentContact.info.changedList[i].peerUid, guildId: '' };
|
||||||
|
LoadMessageIdDo.push(LoadMessageIdList(Peer, RecentContact.info.changedList[i].msgId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await Promise.all(LoadMessageIdDo).then(() => {
|
||||||
|
log('消息列表加载完成');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
napCatCore.onLoginSuccess(() => {
|
napCatCore.onLoginSuccess(async () => {
|
||||||
setTimeout(async () => {
|
await sleep(100);
|
||||||
if (groups.size > 100) {
|
loadMessageUnique().then().catch();
|
||||||
logWarn('群数量大于100,可能会导致性能问题');
|
|
||||||
}
|
|
||||||
let predict = (groups.size + friends.size) / 5;
|
|
||||||
predict = predict < 20 ? 20 : predict;
|
|
||||||
predict = predict > 50 ? 50 : predict;
|
|
||||||
//let waitpromise: Array<Promise<{ msgList: RawMessage[]; }>> = [];
|
|
||||||
MessageUnique.resize(predict * 50);
|
|
||||||
let RecentContact = await NTQQUserApi.getRecentContactListSnapShot(predict);
|
|
||||||
if (RecentContact?.info?.changedList && RecentContact?.info?.changedList?.length > 0) {
|
|
||||||
for (let i = 0; i < RecentContact.info.changedList.length; i++) {
|
|
||||||
let Peer: Peer = { chatType: RecentContact.info.changedList[i].chatType, peerUid: RecentContact.info.changedList[i].peerUid, guildId: '' };
|
|
||||||
let msgList = await NTQQMsgApi.getMsgHistory(Peer, RecentContact.info.changedList[i].msgId, 50);
|
|
||||||
for (let j = 0; j < msgList.msgList.length; j++) {
|
|
||||||
let shortId = MessageUnique.createMsg(Peer, msgList.msgList[j].msgId);
|
|
||||||
//console.log(`开始创建 ${shortId}<------>${msgList.msgList[j].msgId}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
});
|
});
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
|
@ -117,7 +117,6 @@ export async function handleForwardNode(destPeer: Peer, messageNodes: OB11Messag
|
|||||||
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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user