From 11c72499a0425059f1809b2134812c42d2b07149 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 3 Aug 2017 17:06:28 +0200 Subject: [PATCH] don't add duplicate messages to the history --- www/common/common-messaging.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/www/common/common-messaging.js b/www/common/common-messaging.js index 3e620e82f..d82bc03aa 100644 --- a/www/common/common-messaging.js +++ b/www/common/common-messaging.js @@ -165,12 +165,22 @@ define([ var channels = Msg.channels = window.channels = {}; + var msgAlreadyKnown = function (channel, sig) { + return channel.messages.some(function (message) { + return message[0] === sig; + }); + }; + var pushMsg = function (common, channel, cryptMsg) { var msg = channel.encryptor.decrypt(cryptMsg); + + var sig = cryptMsg.slice(0, 64); + if (msgAlreadyKnown(channel, sig)) { return; } + var parsedMsg = JSON.parse(msg); if (parsedMsg[0] === Types.message) { parsedMsg.shift(); - channel.messages.push([cryptMsg.slice(0,64), parsedMsg]); + channel.messages.push([sig, parsedMsg]); return true; } var proxy;