Prevent Message Duplicates in Message History

This commit is contained in:
Raven Scott 2024-06-14 00:08:32 -04:00
parent 7a31202ac3
commit 98aa79f075

12
app.js
View File

@ -768,7 +768,19 @@ function addMessageToStore(topic, messageObj) {
if (!messagesStore[topic]) { if (!messagesStore[topic]) {
messagesStore[topic] = []; messagesStore[topic] = [];
} }
// Check for duplicates
const isDuplicate = messagesStore[topic].some(msg =>
msg.from === messageObj.from &&
msg.message === messageObj.message &&
msg.timestamp === messageObj.timestamp
);
if (!isDuplicate) {
messagesStore[topic].push(messageObj); messagesStore[topic].push(messageObj);
} else {
console.log('Duplicate message detected:', messageObj); // Debugging log
}
} }
function loadConfigFromFile() { function loadConfigFromFile() {