From 4026e0162eca5ace42fbd1aa78987a2ca342522a Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 15 Dec 2020 10:44:35 +1100 Subject: [PATCH] fix a bug preventing fitlering of duplicates for open group messages --- js/modules/loki_app_dot_net_api.js | 10 ++++++---- ts/receiver/dataMessage.ts | 5 ++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/js/modules/loki_app_dot_net_api.js b/js/modules/loki_app_dot_net_api.js index 06ed9abfa..5f016638b 100644 --- a/js/modules/loki_app_dot_net_api.js +++ b/js/modules/loki_app_dot_net_api.js @@ -6,7 +6,7 @@ const { URL, URLSearchParams } = require('url'); const FormData = require('form-data'); const https = require('https'); const path = require('path'); -const dataMessage = require('../../ts/receiver/dataMessage'); +const DataMessage = require('../../ts/receiver/dataMessage'); // Can't be less than 1200 if we have unauth'd requests const PUBLICCHAT_MSG_POLL_EVERY = 1.5 * 1000; // 1.5s @@ -1619,6 +1619,7 @@ class LokiPublicChannelAPI { preview, quote, avatar, + text: adnMessage.text, profileKey, }; } @@ -1746,8 +1747,10 @@ class LokiPublicChannelAPI { } // Duplicate check + // message is one of the object of this.lastMessagesCache + // testedMessage is the adnMessage object const isDuplicate = (message, testedMessage) => - dataMessage.isDuplicate( + DataMessage.isDuplicate( message, testedMessage, testedMessage.user.username @@ -1758,7 +1761,6 @@ class LokiPublicChannelAPI { return false; // Duplicate message } - // FIXME: maybe move after the de-multidev-decode // Add the message to the lastMessage cache and keep the last 5 recent messages this.lastMessagesCache = [ ...this.lastMessagesCache, @@ -1767,10 +1769,10 @@ class LokiPublicChannelAPI { source: pubKey, body: adnMessage.text, sent_at: timestamp, + serverId: adnMessage.id, }, }, ].splice(-5); - const from = adnMessage.user.name || 'Anonymous'; // profileName // if us diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index 4728a9e7b..a09d84ee5 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -396,13 +396,16 @@ async function isMessageDuplicate({ export const isDuplicate = (m: any, testedMessage: any, source: string) => { // The username in this case is the users pubKey const sameUsername = m.attributes.source === source; + const sameServerId = + m.attributes.serverId !== undefined && + testedMessage.id === m.attributes.serverId; const sameText = m.attributes.body === testedMessage.body; // Don't filter out messages that are too far apart from each other const timestampsSimilar = Math.abs(m.attributes.sent_at - testedMessage.timestamp) <= PUBLICCHAT_MIN_TIME_BETWEEN_DUPLICATE_MESSAGES; - return sameUsername && sameText && timestampsSimilar; + return sameUsername && sameText && (timestampsSimilar || sameServerId); }; async function handleProfileUpdate(