修复提交疏漏

修改在查询群历史消息时,如未提供msg_seq,则返回最新消息
This commit is contained in:
Alen
2024-07-27 15:01:08 +08:00
parent 3e5c92a2b1
commit e4ba9edeb8
2 changed files with 32 additions and 6 deletions

View File

@@ -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();