mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
fix: 消息重复入库导致message_id每次都是+2
This commit is contained in:
@@ -11,7 +11,7 @@ class DBUtil {
|
|||||||
private readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_";
|
private readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_";
|
||||||
private readonly DB_KEY_PREFIX_FILE = "file_";
|
private readonly DB_KEY_PREFIX_FILE = "file_";
|
||||||
private db: Level;
|
private db: Level;
|
||||||
private cache: Record<string, RawMessage | string | FileCache> = {} // <msg_id_ | msg_short_id_ | msg_seq_id_><id>: RawMessage
|
public cache: Record<string, RawMessage | string | FileCache> = {} // <msg_id_ | msg_short_id_ | msg_seq_id_><id>: RawMessage
|
||||||
private currentShortId: number;
|
private currentShortId: number;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -101,7 +101,7 @@ class DBUtil {
|
|||||||
try {
|
try {
|
||||||
existMsg = await this.getMsgByLongId(msg.msgId)
|
existMsg = await this.getMsgByLongId(msg.msgId)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// log("addMsg getMsgByLongId error", e.stack.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (existMsg) {
|
if (existMsg) {
|
||||||
@@ -109,7 +109,8 @@ class DBUtil {
|
|||||||
this.updateMsg(msg).then()
|
this.updateMsg(msg).then()
|
||||||
return existMsg.msgShortId
|
return existMsg.msgShortId
|
||||||
}
|
}
|
||||||
|
this.addCache(msg);
|
||||||
|
// log("新增消息记录", msg.msgId)
|
||||||
const shortMsgId = await this.genMsgShortId();
|
const shortMsgId = await this.genMsgShortId();
|
||||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId;
|
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId;
|
||||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq;
|
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq;
|
||||||
@@ -123,7 +124,6 @@ class DBUtil {
|
|||||||
// log("新的seqId", seqIdKey)
|
// log("新的seqId", seqIdKey)
|
||||||
this.db.put(seqIdKey, msg.msgId).then();
|
this.db.put(seqIdKey, msg.msgId).then();
|
||||||
}
|
}
|
||||||
this.cache[shortIdKey] = this.cache[longIdKey] = msg;
|
|
||||||
if (!this.cache[seqIdKey]) {
|
if (!this.cache[seqIdKey]) {
|
||||||
this.cache[seqIdKey] = msg;
|
this.cache[seqIdKey] = msg;
|
||||||
}
|
}
|
||||||
|
@@ -155,8 +155,10 @@ function onLoad() {
|
|||||||
async function postReceiveMsg(msgList: RawMessage[]) {
|
async function postReceiveMsg(msgList: RawMessage[]) {
|
||||||
const {debug, reportSelfMessage} = getConfigUtil().getConfig();
|
const {debug, reportSelfMessage} = getConfigUtil().getConfig();
|
||||||
for (let message of msgList) {
|
for (let message of msgList) {
|
||||||
// log("收到新消息", message.msgSeq)
|
// log("收到新消息", message.msgId, message.msgSeq)
|
||||||
message.msgShortId = await dbUtil.addMsg(message)
|
// if (message.senderUin !== selfInfo.uin){
|
||||||
|
message.msgShortId = await dbUtil.addMsg(message);
|
||||||
|
// }
|
||||||
|
|
||||||
OB11Constructor.message(message).then((msg) => {
|
OB11Constructor.message(message).then((msg) => {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
@@ -182,7 +184,7 @@ function onLoad() {
|
|||||||
})
|
})
|
||||||
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.UPDATE_MSG, async (payload) => {
|
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.UPDATE_MSG, async (payload) => {
|
||||||
for (const message of payload.msgList) {
|
for (const message of payload.msgList) {
|
||||||
// log("message update", message.sendStatus, message)
|
// log("message update", message.sendStatus, message.msgId, message.msgSeq)
|
||||||
if (message.recallTime != "0") {
|
if (message.recallTime != "0") {
|
||||||
// 撤回消息上报
|
// 撤回消息上报
|
||||||
const oriMessage = await dbUtil.getMsgByLongId(message.msgId)
|
const oriMessage = await dbUtil.getMsgByLongId(message.msgId)
|
||||||
|
@@ -235,8 +235,8 @@ registerReceiveHook<{
|
|||||||
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload) => {
|
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload) => {
|
||||||
const {autoDeleteFile} = getConfigUtil().getConfig();
|
const {autoDeleteFile} = getConfigUtil().getConfig();
|
||||||
for (const message of payload.msgList) {
|
for (const message of payload.msgList) {
|
||||||
// log("收到新消息,push到历史记录", message.msgSeq)
|
// log("收到新消息,push到历史记录", message.msgId)
|
||||||
dbUtil.addMsg(message).then()
|
// dbUtil.addMsg(message).then()
|
||||||
// 清理文件
|
// 清理文件
|
||||||
if (!autoDeleteFile) {
|
if (!autoDeleteFile) {
|
||||||
continue
|
continue
|
||||||
@@ -270,7 +270,7 @@ registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, ({msgRe
|
|||||||
const message = msgRecord;
|
const message = msgRecord;
|
||||||
const peerUid = message.peerUid;
|
const peerUid = message.peerUid;
|
||||||
// log("收到自己发送成功的消息", Object.keys(sendMessagePool), message);
|
// log("收到自己发送成功的消息", Object.keys(sendMessagePool), message);
|
||||||
// log("收到自己发送成功的消息", message);
|
// log("收到自己发送成功的消息", message.msgId, message.msgSeq);
|
||||||
dbUtil.addMsg(message).then()
|
dbUtil.addMsg(message).then()
|
||||||
const sendCallback = sendMessagePool[peerUid]
|
const sendCallback = sendMessagePool[peerUid]
|
||||||
if (sendCallback) {
|
if (sendCallback) {
|
||||||
|
Reference in New Issue
Block a user