From b9e565811238d587d191aefbedfc8a469e6853d6 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sat, 27 Apr 2019 14:58:50 +0200 Subject: [PATCH] Message deduplication bugfixes and improvements. - Add a new method to check for dupes based on the message text. - When checking for dupes based on origin_id, no need to restrict to only our own. --- CHANGES.md | 1 + dist/converse.js | 26 +++++++++++++++++++++++--- spec/messages.js | 2 -- src/headless/converse-chatboxes.js | 21 +++++++++++++++++---- src/headless/converse-muc.js | 2 ++ src/headless/dist/converse-headless.js | 26 +++++++++++++++++++++++--- 6 files changed, 66 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1c249679e..fb1b2dd6c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ - Hide the textarea when a user is muted in a groupchat. - Don't restore a BOSH session without knowing the JID - In the `/help` menu, only show allowed commands +- Message deduplication bugfixes and improvements - #1296: `embedded` view mode shows `chatbox-navback` arrow in header - #1532: Converse reloads on enter pressed in the filter box diff --git a/dist/converse.js b/dist/converse.js index 9b096711a..93dcc212e 100644 --- a/dist/converse.js +++ b/dist/converse.js @@ -62423,8 +62423,8 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha return false; }, - getDuplicateMessage(stanza) { - return this.findDuplicateFromOriginID(stanza) || this.findDuplicateFromStanzaID(stanza); + async getDuplicateMessage(stanza) { + return this.findDuplicateFromOriginID(stanza) || (await this.findDuplicateFromStanzaID(stanza)) || this.findDuplicateFromMessage(stanza); }, findDuplicateFromOriginID(stanza) { @@ -62436,7 +62436,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha return this.messages.findWhere({ 'origin_id': origin_id.getAttribute('id'), - 'sender': 'me' + 'from': stanza.getAttribute('from') }); }, @@ -62459,6 +62459,26 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha return this.messages.findWhere(query); }, + findDuplicateFromMessage(stanza) { + const text = this.getMessageBody(stanza) || undefined; + + if (!text) { + return false; + } + + const id = stanza.getAttribute('id'); + + if (!id) { + return false; + } + + return this.messages.findWhere({ + 'message': text, + 'from': stanza.getAttribute('from'), + 'msgid': id + }); + }, + sendMarker(to_jid, id, type) { const stanza = $msg({ 'from': _converse.connection.jid, diff --git a/spec/messages.js b/spec/messages.js index 58888e9bc..020fe84d9 100644 --- a/spec/messages.js +++ b/spec/messages.js @@ -2249,7 +2249,6 @@ - `); _converse.connection._dataRecv(test_utils.createRequest(stanza)); await test_utils.waitUntil(() => _converse.api.chats.get().length); @@ -2267,7 +2266,6 @@ - `); _converse.connection._dataRecv(test_utils.createRequest(stanza)); await test_utils.waitUntil(() => view.model.findDuplicateFromStanzaID.calls.count() === 2); diff --git a/src/headless/converse-chatboxes.js b/src/headless/converse-chatboxes.js index ba43cde75..6744a3ea4 100644 --- a/src/headless/converse-chatboxes.js +++ b/src/headless/converse-chatboxes.js @@ -360,8 +360,10 @@ converse.plugins.add('converse-chatboxes', { return false; }, - getDuplicateMessage (stanza) { - return this.findDuplicateFromOriginID(stanza) || this.findDuplicateFromStanzaID(stanza); + async getDuplicateMessage (stanza) { + return this.findDuplicateFromOriginID(stanza) || + await this.findDuplicateFromStanzaID(stanza) || + this.findDuplicateFromMessage(stanza); }, findDuplicateFromOriginID (stanza) { @@ -371,11 +373,11 @@ converse.plugins.add('converse-chatboxes', { } return this.messages.findWhere({ 'origin_id': origin_id.getAttribute('id'), - 'sender': 'me' + 'from': stanza.getAttribute('from') }); }, - async findDuplicateFromStanzaID(stanza) { + async findDuplicateFromStanzaID (stanza) { const stanza_id = sizzle(`stanza-id[xmlns="${Strophe.NS.SID}"]`, stanza).pop(); if (!stanza_id) { return false; @@ -390,6 +392,17 @@ converse.plugins.add('converse-chatboxes', { return this.messages.findWhere(query); }, + findDuplicateFromMessage (stanza) { + const text = this.getMessageBody(stanza) || undefined; + if (!text) { return false; } + const id = stanza.getAttribute('id'); + if (!id) { return false; } + return this.messages.findWhere({ + 'message': text, + 'from': stanza.getAttribute('from'), + 'msgid': id + }); + }, sendMarker(to_jid, id, type) { const stanza = $msg({ diff --git a/src/headless/converse-muc.js b/src/headless/converse-muc.js index 498de5a9c..444c41cca 100644 --- a/src/headless/converse-muc.js +++ b/src/headless/converse-muc.js @@ -323,6 +323,7 @@ converse.plugins.add('converse-muc', { 'to': this.getRoomJIDAndNick(nick) }).c("x", {'xmlns': Strophe.NS.MUC}) .c("history", {'maxstanzas': this.features.get('mam_enabled') ? 0 : _converse.muc_history_max_stanzas}).up(); + if (password) { stanza.cnode(Strophe.xmlElement("password", [], password)); } @@ -1082,6 +1083,7 @@ converse.plugins.add('converse-muc', { return _converse.api.trigger('message', {'stanza': original_stanza}); } const attrs = await this.getMessageAttributesFromStanza(stanza, original_stanza); + if (attrs.nick && !this.subjectChangeHandled(attrs) && !this.ignorableCSN(attrs) && diff --git a/src/headless/dist/converse-headless.js b/src/headless/dist/converse-headless.js index bfeb8ae3a..02815e711 100644 --- a/src/headless/dist/converse-headless.js +++ b/src/headless/dist/converse-headless.js @@ -40647,8 +40647,8 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha return false; }, - getDuplicateMessage(stanza) { - return this.findDuplicateFromOriginID(stanza) || this.findDuplicateFromStanzaID(stanza); + async getDuplicateMessage(stanza) { + return this.findDuplicateFromOriginID(stanza) || (await this.findDuplicateFromStanzaID(stanza)) || this.findDuplicateFromMessage(stanza); }, findDuplicateFromOriginID(stanza) { @@ -40660,7 +40660,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha return this.messages.findWhere({ 'origin_id': origin_id.getAttribute('id'), - 'sender': 'me' + 'from': stanza.getAttribute('from') }); }, @@ -40683,6 +40683,26 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha return this.messages.findWhere(query); }, + findDuplicateFromMessage(stanza) { + const text = this.getMessageBody(stanza) || undefined; + + if (!text) { + return false; + } + + const id = stanza.getAttribute('id'); + + if (!id) { + return false; + } + + return this.messages.findWhere({ + 'message': text, + 'from': stanza.getAttribute('from'), + 'msgid': id + }); + }, + sendMarker(to_jid, id, type) { const stanza = $msg({ 'from': _converse.connection.jid,