mirror of
https://github.com/Qortal/chrome-extension.git
synced 2025-02-11 17:55:49 +00:00
remove duplicate msgs
This commit is contained in:
parent
540cb45d98
commit
9cb1a977e0
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user