浏览代码

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.
JC Brand 6 年之前
父节点
当前提交
b9e5658112
共有 6 个文件被更改,包括 66 次插入12 次删除
  1. 1 0
      CHANGES.md
  2. 23 3
      dist/converse.js
  3. 0 2
      spec/messages.js
  4. 17 4
      src/headless/converse-chatboxes.js
  5. 2 0
      src/headless/converse-muc.js
  6. 23 3
      src/headless/dist/converse-headless.js

+ 1 - 0
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
 

+ 23 - 3
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,

+ 0 - 2
spec/messages.js

@@ -2249,7 +2249,6 @@
                     <stanza-id xmlns="urn:xmpp:sid:0"
                                id="5f3dbc5e-e1d3-4077-a492-693f3769c7ad"
                                by="room@muc.example.com"/>
-                    <origin-id xmlns="urn:xmpp:sid:0" id="de305d54-75b4-431b-adb2-eb6b9e546013"/>
                 </message>`);
             _converse.connection._dataRecv(test_utils.createRequest(stanza));
             await test_utils.waitUntil(() => _converse.api.chats.get().length);
@@ -2267,7 +2266,6 @@
                     <stanza-id xmlns="urn:xmpp:sid:0"
                                id="5f3dbc5e-e1d3-4077-a492-693f3769c7ad"
                                by="room@muc.example.com"/>
-                    <origin-id xmlns="urn:xmpp:sid:0" id="de305d54-75b4-431b-adb2-eb6b9e546013"/>
                 </message>`);
             _converse.connection._dataRecv(test_utils.createRequest(stanza));
             await test_utils.waitUntil(() => view.model.findDuplicateFromStanzaID.calls.count() === 2);

+ 17 - 4
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({

+ 2 - 0
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) &&

+ 23 - 3
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,