mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
修复提交疏漏
修改在查询群历史消息时,如未提供msg_seq,则返回最新消息
This commit is contained in:
@@ -61,6 +61,10 @@ class LimitedHashTable<K, V> {
|
||||
this.valueToKey.delete(value);
|
||||
}
|
||||
}
|
||||
|
||||
getKeyList(): K[] {
|
||||
return Array.from(this.keyToValue.keys());
|
||||
}
|
||||
}
|
||||
|
||||
class MessageUniqueWrapper {
|
||||
@@ -111,6 +115,25 @@ class MessageUniqueWrapper {
|
||||
this.msgIdMap.resize(maxSize);
|
||||
this.msgDataMap.resize(maxSize);
|
||||
}
|
||||
getNthLatestShortIdByPeer(peer: Peer, index: number = 1): number | undefined {
|
||||
const peerUid = peer.peerUid;
|
||||
const chatType = peer.chatType;
|
||||
const keys = this.msgDataMap.getKeyList();
|
||||
const matches: number[] = [];
|
||||
for (const key of keys) {
|
||||
const [msgId, chatTypeStr, peerUidStr] = key.split('|');
|
||||
if (peerUidStr === peerUid && chatTypeStr === chatType.toString()) {
|
||||
const shortId = this.msgDataMap.getValue(key);
|
||||
if (shortId) {
|
||||
matches.push(shortId);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matches.length >= index) {
|
||||
return matches[matches.length - index];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export const MessageUnique: MessageUniqueWrapper = new MessageUniqueWrapper();
|
@@ -18,7 +18,7 @@ const SchemaData = {
|
||||
message_seq: { type: 'number' },
|
||||
count: { type: 'number' }
|
||||
},
|
||||
required: ['group_id', 'count']
|
||||
required: [ 'group_id' ]
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -31,13 +31,16 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
|
||||
if (!group) {
|
||||
throw `群${payload.group_id}不存在`;
|
||||
}
|
||||
const startMsgId = (await MessageUnique.getMsgIdAndPeerByShortId(payload.message_seq || 0))?.MsgId || '0';
|
||||
// log("startMsgId", startMsgId)
|
||||
const historyResult = (await NTQQMsgApi.getMsgHistory({
|
||||
let targetMsgShortId, count = parseInt(payload.count?.toString() ?? '20');
|
||||
const peer = {
|
||||
chatType: ChatType.group,
|
||||
peerUid: group.groupCode
|
||||
}, startMsgId, parseInt(payload.count?.toString()) || 20));
|
||||
//logDebug(historyResult);
|
||||
}
|
||||
if ( !payload.message_seq ) {
|
||||
targetMsgShortId = await MessageUnique.getNthLatestShortIdByPeer(peer, count)
|
||||
}
|
||||
const startMsgId = (await MessageUnique.getMsgIdAndPeerByShortId(targetMsgShortId ?? (payload.message_seq ?? 0)))?.MsgId || '0';
|
||||
const historyResult = (await NTQQMsgApi.getMsgHistory(peer, startMsgId, count));
|
||||
const msgList = historyResult.msgList;
|
||||
await Promise.all(msgList.map(async msg => {
|
||||
msg.id = await MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
|
||||
|
Reference in New Issue
Block a user