mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
feat: 拉取重启消息
This commit is contained in:
@@ -9,6 +9,9 @@ class LimitedHashTable<K, V> {
|
|||||||
constructor(maxSize: number) {
|
constructor(maxSize: number) {
|
||||||
this.maxSize = maxSize;
|
this.maxSize = maxSize;
|
||||||
}
|
}
|
||||||
|
resize(count: number) {
|
||||||
|
this.maxSize = count;
|
||||||
|
}
|
||||||
|
|
||||||
set(key: K, value: V): void {
|
set(key: K, value: V): void {
|
||||||
const isExist = this.keyToValue.get(key);
|
const isExist = this.keyToValue.get(key);
|
||||||
@@ -19,6 +22,8 @@ class LimitedHashTable<K, V> {
|
|||||||
this.valueToKey.set(value, key);
|
this.valueToKey.set(value, key);
|
||||||
while (this.keyToValue.size !== this.valueToKey.size) {
|
while (this.keyToValue.size !== this.valueToKey.size) {
|
||||||
console.log('keyToValue.size !== valueToKey.size Error Atom');
|
console.log('keyToValue.size !== valueToKey.size Error Atom');
|
||||||
|
this.keyToValue.clear();
|
||||||
|
this.valueToKey.clear();
|
||||||
}
|
}
|
||||||
// console.log('---------------');
|
// console.log('---------------');
|
||||||
// console.log(this.keyToValue);
|
// console.log(this.keyToValue);
|
||||||
@@ -71,7 +76,7 @@ class MessageUniqueWrapper {
|
|||||||
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);
|
||||||
if (isExist && isExist === msgId) {
|
if (isExist && isExist === msgId) {
|
||||||
return undefined;
|
return shortId;
|
||||||
}
|
}
|
||||||
this.msgIdMap.set(msgId, shortId);
|
this.msgIdMap.set(msgId, shortId);
|
||||||
this.msgDataMap.set(key, shortId);
|
this.msgDataMap.set(key, shortId);
|
||||||
@@ -100,6 +105,10 @@ class MessageUniqueWrapper {
|
|||||||
if (!shortId) return undefined;
|
if (!shortId) return undefined;
|
||||||
return this.getMsgIdAndPeerByShortId(shortId);
|
return this.getMsgIdAndPeerByShortId(shortId);
|
||||||
}
|
}
|
||||||
|
resize(maxSize: number): void {
|
||||||
|
this.msgIdMap.resize(maxSize);
|
||||||
|
this.msgDataMap.resize(maxSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MessageUnique = new MessageUniqueWrapper(1000);
|
export const MessageUnique: MessageUniqueWrapper = new MessageUniqueWrapper();
|
@@ -1,13 +1,38 @@
|
|||||||
import { GetFileListParam, Peer, RawMessage, SendMessageElement } from '@/core/entities';
|
import { ChatType, GetFileListParam, Peer, RawMessage, SendMessageElement } from '@/core/entities';
|
||||||
import { selfInfo } from '@/core/data';
|
import { friends, groups, selfInfo } from '@/core/data';
|
||||||
import { log, logError } from '@/common/utils/log';
|
import { log, logError, logWarn } from '@/common/utils/log';
|
||||||
import { sleep } from '@/common/utils/helper';
|
import { sleep } from '@/common/utils/helper';
|
||||||
import { napCatCore } from '@/core';
|
import { napCatCore, NTQQUserApi } from '@/core';
|
||||||
import { MsgListener, onGroupFileInfoUpdateParamType } from '@/core/listeners';
|
import { MsgListener, onGroupFileInfoUpdateParamType } from '@/core/listeners';
|
||||||
import { GeneralCallResult } from '@/core/services/common';
|
import { GeneralCallResult } from '@/core/services/common';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
|
import { MessageUnique } from '../../../common/utils/MessageUnique';
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
napCatCore.onLoginSuccess(() => {
|
||||||
|
setTimeout(async () => {
|
||||||
|
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);
|
||||||
|
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);
|
||||||
const sendMessagePool: Record<string, ((sendSuccessMsg: RawMessage) => void | Promise<void>) | null> = {};// peerUid: callbackFunc
|
const sendMessagePool: Record<string, ((sendSuccessMsg: RawMessage) => void | Promise<void>) | null> = {};// peerUid: callbackFunc
|
||||||
|
|
||||||
const sendSuccessCBMap: Record<string, ((sendSuccessMsg: RawMessage) => boolean | Promise<boolean>) | null> = {};// uuid: callbackFunc
|
const sendSuccessCBMap: Record<string, ((sendSuccessMsg: RawMessage) => boolean | Promise<boolean>) | null> = {};// uuid: callbackFunc
|
||||||
@@ -71,13 +96,13 @@ setTimeout(() => {
|
|||||||
|
|
||||||
export class NTQQMsgApi {
|
export class NTQQMsgApi {
|
||||||
// static napCatCore: NapCatCore | null = null;
|
// static napCatCore: NapCatCore | null = null;
|
||||||
// enum BaseEmojiType {
|
// enum BaseEmojiType {
|
||||||
// NORMAL_EMOJI,
|
// NORMAL_EMOJI,
|
||||||
// SUPER_EMOJI,
|
// SUPER_EMOJI,
|
||||||
// RANDOM_SUPER_EMOJI,
|
// RANDOM_SUPER_EMOJI,
|
||||||
// CHAIN_SUPER_EMOJI,
|
// CHAIN_SUPER_EMOJI,
|
||||||
// EMOJI_EMOJI
|
// EMOJI_EMOJI
|
||||||
// }
|
// }
|
||||||
static async setEmojiLike(peer: Peer, msgSeq: string, emojiId: string, set: boolean = true) {
|
static async setEmojiLike(peer: Peer, msgSeq: string, emojiId: string, set: boolean = true) {
|
||||||
// nt_qq//global//nt_data//Emoji//emoji-resource//sysface_res/apng/ 下可以看到所有QQ表情预览
|
// nt_qq//global//nt_data//Emoji//emoji-resource//sysface_res/apng/ 下可以看到所有QQ表情预览
|
||||||
// nt_qq\global\nt_data\Emoji\emoji-resource\face_config.json 里面有所有表情的id, 自带表情id是QSid, 标准emoji表情id是QCid
|
// nt_qq\global\nt_data\Emoji\emoji-resource\face_config.json 里面有所有表情的id, 自带表情id是QSid, 标准emoji表情id是QCid
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import { Peer } from "../entities";
|
import { Peer } from "../entities";
|
||||||
import { NodeIKernelRecentContactListener } from "../listeners/NodeIKernelRecentContactListener";
|
import { NodeIKernelRecentContactListener } from "../listeners/NodeIKernelRecentContactListener";
|
||||||
|
import { GeneralCallResult } from "./common";
|
||||||
export interface FSABRecentContactParams {
|
export interface FSABRecentContactParams {
|
||||||
anchorPointContact: {
|
anchorPointContact: {
|
||||||
contactId: string;
|
contactId: string;
|
||||||
@@ -33,7 +34,14 @@ export interface NodeIKernelRecentContactService {
|
|||||||
|
|
||||||
enterOrExitMsgList(...args: unknown[]): unknown; // 1 arguments
|
enterOrExitMsgList(...args: unknown[]): unknown; // 1 arguments
|
||||||
|
|
||||||
/*!---!*/getRecentContactListSnapShot(count: number): unknown; // 1 arguments
|
/*!---!*/getRecentContactListSnapShot(count: number): Promise<GeneralCallResult & {
|
||||||
|
info: {
|
||||||
|
errCode: number,
|
||||||
|
errMsg: string,
|
||||||
|
sortedContactList: Array<number>,
|
||||||
|
changedList: Array<any>
|
||||||
|
}
|
||||||
|
}>; // 1 arguments
|
||||||
|
|
||||||
clearMsgUnreadCount(...args: unknown[]): unknown; // 1 arguments
|
clearMsgUnreadCount(...args: unknown[]): unknown; // 1 arguments
|
||||||
|
|
||||||
|
@@ -136,26 +136,26 @@ export class OB11Constructor {
|
|||||||
message_data['type'] = 'reply';
|
message_data['type'] = 'reply';
|
||||||
// log("收到回复消息", element.replyElement.replayMsgSeq)
|
// log("收到回复消息", element.replyElement.replayMsgSeq)
|
||||||
try {
|
try {
|
||||||
// let retData = await NTQQMsgApi.getMsgsBySeqAndCount(
|
let replyMsg = await NTQQMsgApi.getMsgsBySeqAndCount(
|
||||||
// {
|
{
|
||||||
// chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
// peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
// guildId: '',
|
guildId: '',
|
||||||
// },
|
},
|
||||||
// element.replyElement.replayMsgSeq,
|
element.replyElement.replayMsgSeq,
|
||||||
// 1,
|
1,
|
||||||
// false,
|
true,
|
||||||
// true
|
true
|
||||||
// );
|
);
|
||||||
// console.log(JSON.stringify(retData, null, 2));
|
// console.log(JSON.stringify(retData, null, 2));
|
||||||
const replyMsg = await NTQQMsgApi.getMsgsBySeqAndCount({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, element.replyElement.replayMsgSeq, 1, true, true);
|
// const replyMsg = await NTQQMsgApi.getMsgsBySeqAndCount({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, element.replyElement.replayMsgSeq, 1, true, true);
|
||||||
// log("找到回复消息", replyMsg.msgShortId, replyMsg.msgId)
|
|
||||||
if (replyMsg) {
|
if (replyMsg) {
|
||||||
message_data['data']['id'] = MessageUnique.createMsg({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, replyMsg.msgList[0].msgId);
|
message_data['data']['id'] = MessageUnique.createMsg({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, replyMsg.msgList[0].msgId)?.toString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
//log("找到回复消息", message_data['data']['id'], replyMsg.msgList[0].msgId)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logError('获取不到引用的消息', e.stack, element.replyElement.replayMsgSeq);
|
logError('获取不到引用的消息', e.stack, element.replyElement.replayMsgSeq);
|
||||||
}
|
}
|
||||||
@@ -202,18 +202,18 @@ export class OB11Constructor {
|
|||||||
message_data['data']['file_id'] = videoOrFileElement.fileUuid;
|
message_data['data']['file_id'] = videoOrFileElement.fileUuid;
|
||||||
message_data['data']['file_size'] = videoOrFileElement.fileSize;
|
message_data['data']['file_size'] = videoOrFileElement.fileSize;
|
||||||
if (!element.videoElement) {
|
if (!element.videoElement) {
|
||||||
// dbUtil.addFileCache({
|
// dbUtil.addFileCache({
|
||||||
// msgId: msg.msgId,
|
// msgId: msg.msgId,
|
||||||
// name: videoOrFileElement.fileName,
|
// name: videoOrFileElement.fileName,
|
||||||
// path: videoOrFileElement.filePath,
|
// path: videoOrFileElement.filePath,
|
||||||
// size: parseInt(videoOrFileElement.fileSize || '0'),
|
// size: parseInt(videoOrFileElement.fileSize || '0'),
|
||||||
// uuid: videoOrFileElement.fileUuid || '',
|
// uuid: videoOrFileElement.fileUuid || '',
|
||||||
// url: '',
|
// url: '',
|
||||||
// element: element.videoElement || element.fileElement,
|
// element: element.videoElement || element.fileElement,
|
||||||
// elementType: element.videoElement ? ElementType.VIDEO : ElementType.FILE,
|
// elementType: element.videoElement ? ElementType.VIDEO : ElementType.FILE,
|
||||||
// elementId: element.elementId
|
// elementId: element.elementId
|
||||||
// }).then();
|
// }).then();
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (element.pttElement) {
|
else if (element.pttElement) {
|
||||||
@@ -285,6 +285,7 @@ export class OB11Constructor {
|
|||||||
else (resMsg.message as OB11MessageData[]).push(message_data);
|
else (resMsg.message as OB11MessageData[]).push(message_data);
|
||||||
resMsg.raw_message += cqCode;
|
resMsg.raw_message += cqCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
resMsg.raw_message = resMsg.raw_message.trim();
|
resMsg.raw_message = resMsg.raw_message.trim();
|
||||||
return resMsg;
|
return resMsg;
|
||||||
|
Reference in New Issue
Block a user