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', {
}
},
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
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)) {
return true;
return;
}
const chatbox = this.getChatBox(from_jid);
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) {
return;
}
const attrs = await chatbox.getMessageAttributesFromStanza(message, message);
const attrs = await chatbox.getMessageAttributesFromStanza(stanza, stanza);
chatbox.messages.create(attrs);
},
......
......@@ -1337,7 +1337,6 @@ converse.plugins.add('converse-muc', {
},
/**
* @async
* @private
* @method _converse.ChatRoom#shouldShowErrorMessage
* @returns {Promise<boolean>}
......@@ -1348,7 +1347,7 @@ converse.plugins.add('converse-muc', {
return false;
}
}
return true;
return _converse.ChatBox.prototype.shouldShowErrorMessage.call(this, stanza);
},
getErrorMessage (stanza) {
......@@ -1357,7 +1356,7 @@ converse.plugins.add('converse-muc', {
} 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.");
} 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