Commit 9c66302c authored by JC Brand's avatar JC Brand

Bugfix. Error responses weren't being shown for corrections

parent 19f6bce2
...@@ -417,7 +417,28 @@ converse.plugins.add('converse-chatboxes', { ...@@ -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', { ...@@ -988,34 +1009,26 @@ converse.plugins.add('converse-chatboxes', {
}); });
}, },
async onErrorMessage (message) { /**
/* Handler method for all incoming error message stanzas * Handler method for all incoming error stanza stanzas.
*/ * @private
const from_jid = Strophe.getBareJidFromJid(message.getAttribute('from')); * @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; return;
}
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;
}
} }
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);
}, },
......
...@@ -1337,7 +1337,6 @@ converse.plugins.add('converse-muc', { ...@@ -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', { ...@@ -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', { ...@@ -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);
} }
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment