mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-07-23 04:36:52 +00:00
remove duplicate msgs
This commit is contained in:
@@ -135,8 +135,16 @@ export const ChatList = ({ initialMessages, myAddress, tempMessages }) => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
const totalMessages = [...initialMessages, ...(tempMessages || [])]
|
||||
let uniqueInitialMessagesMap = new Map();
|
||||
|
||||
// Iterate over initialMessages and add only unique messages based on signature
|
||||
initialMessages.forEach((message) => {
|
||||
uniqueInitialMessagesMap.set(message.signature, message);
|
||||
});
|
||||
|
||||
// Convert the map back to an array and sort by timestamp (old to new)
|
||||
let uniqueInitialMessages = Array.from(uniqueInitialMessagesMap.values()).sort((a, b) => a.timestamp - b.timestamp);
|
||||
const totalMessages = [...uniqueInitialMessages, ...(tempMessages || [])]
|
||||
if(totalMessages.length === 0) return
|
||||
setMessages(totalMessages);
|
||||
// cache.clearAll(); // Clear cache so the list can properly re-render with new messages
|
||||
|
Reference in New Issue
Block a user