Răsfoiți Sursa

Bugfix. Error responses weren't being shown for corrections

JC Brand 6 ani în urmă
părinte
comite
9c66302c4a
2 a modificat fișierele cu 36 adăugiri și 24 ștergeri
  1. 34 21
      src/headless/converse-chatboxes.js
  2. 2 3
      src/headless/converse-muc.js

+ 34 - 21
src/headless/converse-chatboxes.js

@@ -417,7 +417,28 @@ converse.plugins.add('converse-chatboxes', {
                 }
                 }
             },
             },
 
 
-            shouldShowErrorMessage () {
+            /**
+             * @private
+             * @method _converse.ChatBox#shouldShowErrorMessage
+             * @returns {boolean}
+             */
+            shouldShowErrorMessage (stanza) {
+                const id = stanza.getAttribute('id');
+                if (id) {
+                    const msgs = this.messages.where({'msgid': id});
+                    const referenced_msgs = msgs.filter(m => m.get('type') !== 'error');
+                    if (!referenced_msgs.length && stanza.querySelector('body') === null) {
+                        // If the error refers to a message not included in our store,
+                        // and it doesn't have a <body> tag, we assume that this was a
+                        // CSI message (which we don't store).
+                        // See https://github.com/conversejs/converse.js/issues/1317
+                        return;
+                    }
+                    const dupes = msgs.filter(m => m.get('type') === 'error');
+                    if (dupes.length) {
+                        return;
+                    }
+                }
                 // Gets overridden in ChatRoom
                 // Gets overridden in ChatRoom
                 return true;
                 return true;
             },
             },
@@ -988,34 +1009,26 @@ converse.plugins.add('converse-chatboxes', {
                 });
                 });
             },
             },
 
 
-            async onErrorMessage (message) {
-                /* Handler method for all incoming error message stanzas
-                 */
-                const from_jid =  Strophe.getBareJidFromJid(message.getAttribute('from'));
+            /**
+             * Handler method for all incoming error stanza stanzas.
+             * @private
+             * @method _converse.ChatBox#onErrorMessage
+             * @param { XMLElement } stanza - The error message stanza
+             */
+            async onErrorMessage (stanza) {
+                const from_jid =  Strophe.getBareJidFromJid(stanza.getAttribute('from'));
                 if (utils.isSameBareJID(from_jid, _converse.bare_jid)) {
                 if (utils.isSameBareJID(from_jid, _converse.bare_jid)) {
-                    return true;
+                    return;
                 }
                 }
                 const chatbox = this.getChatBox(from_jid);
                 const chatbox = this.getChatBox(from_jid);
                 if (!chatbox) {
                 if (!chatbox) {
-                    return true;
-                }
-                const id = message.getAttribute('id');
-                if (id) {
-                    const msgs = chatbox.messages.where({'msgid': id});
-                    if (!msgs.length || msgs.filter(m => m.get('type') === 'error').length) {
-                        // If the error refers to a message not included in our store.
-                        // We assume that this was a CSI message (which we don't store).
-                        // See https://github.com/conversejs/converse.js/issues/1317
-                        //
-                        // We also ignore duplicate error messages.
-                        return;
-                    }
+                    return;
                 }
                 }
-                const should_show = await chatbox.shouldShowErrorMessage(message);
+                const should_show = await chatbox.shouldShowErrorMessage(stanza);
                 if (!should_show) {
                 if (!should_show) {
                     return;
                     return;
                 }
                 }
-                const attrs = await chatbox.getMessageAttributesFromStanza(message, message);
+                const attrs = await chatbox.getMessageAttributesFromStanza(stanza, stanza);
                 chatbox.messages.create(attrs);
                 chatbox.messages.create(attrs);
             },
             },
 
 

+ 2 - 3
src/headless/converse-muc.js

@@ -1337,7 +1337,6 @@ converse.plugins.add('converse-muc', {
             },
             },
 
 
             /**
             /**
-             * @async
              * @private
              * @private
              * @method _converse.ChatRoom#shouldShowErrorMessage
              * @method _converse.ChatRoom#shouldShowErrorMessage
              * @returns {Promise<boolean>}
              * @returns {Promise<boolean>}
@@ -1348,7 +1347,7 @@ converse.plugins.add('converse-muc', {
                         return false;
                         return false;
                     }
                     }
                 }
                 }
-                return true;
+                return _converse.ChatBox.prototype.shouldShowErrorMessage.call(this, stanza);
             },
             },
 
 
             getErrorMessage (stanza) {
             getErrorMessage (stanza) {
@@ -1357,7 +1356,7 @@ converse.plugins.add('converse-muc', {
                 } else if (sizzle(`not-acceptable[xmlns="${Strophe.NS.STANZAS}"]`, stanza).length) {
                 } else if (sizzle(`not-acceptable[xmlns="${Strophe.NS.STANZAS}"]`, stanza).length) {
                     return __("Your message was not delivered because you're not present in the groupchat.");
                     return __("Your message was not delivered because you're not present in the groupchat.");
                 } else {
                 } else {
-                    return _converse.ChatBox.prototype.getErrorMessage.apply(this, arguments);
+                    return _converse.ChatBox.prototype.getErrorMessage.call(this, stanza);
                 }
                 }
             },
             },