remove duplicate msgs

This commit is contained in:
PhilReact 2024-09-11 22:29:17 +03:00
parent 540cb45d98
commit 9cb1a977e0
2 changed files with 12 additions and 4 deletions

View File

@ -11,7 +11,7 @@ let messageQueue = []; // Global message queue
export const MessageQueueProvider = ({ children }) => {
const [queueChats, setQueueChats] = useState({}); // Stores chats and status for display
const isProcessingRef = useRef(false); // To track if the queue is being processed
const maxRetries = 3;
const maxRetries = 4;
const clearStatesMessageQueueProvider = useCallback(() => {
setQueueChats({})
@ -122,7 +122,7 @@ const processQueue = useCallback(async () => {
}
// Delay between processing each message to avoid overlap
await new Promise((res) => setTimeout(res, 3000));
await new Promise((res) => setTimeout(res, 5000));
}
// Reset the processing lock once all messages are processed

View File

@ -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