From a3407bb98b598bcdcad5a10173840ccbba41c442 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Tue, 28 Feb 2017 22:17:28 +0100 Subject: [PATCH] Move MAM specific code to converse-mam.js --- src/converse-core.js | 8 ++++---- src/converse-mam.js | 12 +++++++++++- src/converse-muc.js | 9 +-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/converse-core.js b/src/converse-core.js index c7d225d6c..92e14ae20 100755 --- a/src/converse-core.js +++ b/src/converse-core.js @@ -181,12 +181,12 @@ Strophe.addNamespace('CARBONS', 'urn:xmpp:carbons:2'); Strophe.addNamespace('CHATSTATES', 'http://jabber.org/protocol/chatstates'); Strophe.addNamespace('CSI', 'urn:xmpp:csi:0'); + Strophe.addNamespace('DELAY', 'urn:xmpp:delay'); + Strophe.addNamespace('HINTS', 'urn:xmpp:hints'); + Strophe.addNamespace('NICK', 'http://jabber.org/protocol/nick'); + Strophe.addNamespace('PUBSUB', 'http://jabber.org/protocol/pubsub'); Strophe.addNamespace('ROSTERX', 'http://jabber.org/protocol/rosterx'); Strophe.addNamespace('XFORM', 'jabber:x:data'); - Strophe.addNamespace('NICK', 'http://jabber.org/protocol/nick'); - Strophe.addNamespace('HINTS', 'urn:xmpp:hints'); - Strophe.addNamespace('PUBSUB', 'http://jabber.org/protocol/pubsub'); - Strophe.addNamespace('DELAY', 'urn:xmpp:delay'); // Instance level constants this.TIMEOUTS = { // Set as module attr so that we can override in tests. diff --git a/src/converse-mam.js b/src/converse-mam.js index 0e34a1101..0d4d4e6bc 100644 --- a/src/converse-mam.js +++ b/src/converse-mam.js @@ -30,7 +30,6 @@ Strophe.addNamespace('MAM', 'urn:xmpp:mam:0'); Strophe.addNamespace('RSM', 'http://jabber.org/protocol/rsm'); - converse.plugins.add('converse-mam', { overrides: { @@ -137,6 +136,17 @@ return result; }, + handleMUCMessage: function (stanza) { + /* MAM (message archive management XEP-0313) messages are + * ignored, since they're handled separately. + */ + var is_mam = $(stanza).find('[xmlns="'+Strophe.NS.MAM+'"]').length > 0; + if (is_mam) { + return true; + } + return this.__super__.handleMUCMessage.apply(this, arguments); + }, + fetchArchivedMessages: function (options) { /* Fetch archived chat messages from the XMPP server. * diff --git a/src/converse-muc.js b/src/converse-muc.js index 32995fd10..fe230d887 100755 --- a/src/converse-muc.js +++ b/src/converse-muc.js @@ -1020,17 +1020,10 @@ handleMUCMessage: function (stanza) { /* Handler for all MUC messages sent to this chat room. - * - * MAM (message archive management XEP-0313) messages are - * ignored, since they're handled separately. * * Parameters: * (XMLElement) stanza: The message stanza. */ - var is_mam = $(stanza).find('[xmlns="'+Strophe.NS.MAM+'"]').length > 0; - if (is_mam) { - return true; - } var configuration_changed = stanza.querySelector("status[code='104']"); var logging_enabled = stanza.querySelector("status[code='170']"); var logging_disabled = stanza.querySelector("status[code='171']"); @@ -1374,7 +1367,7 @@ _.each(iq.querySelectorAll('feature'), function (field) { var fieldname = field.getAttribute('var'); if (!fieldname.startsWith('muc_')) { - if (fieldname === 'urn:xmpp:mam:0') { + if (fieldname === Strophe.NS.MAM) { features.mam_enabled = true; } return;