Move MAM code to proper place.

Also, don't query for MAM messages if the chat room doesn't support it.
This commit is contained in:
JC Brand 2017-02-24 20:52:23 +00:00
parent 0d48929bb3
commit 61b2dc7f99
2 changed files with 41 additions and 31 deletions

View File

@ -86,12 +86,14 @@
fetchArchivedMessages: function (options) { fetchArchivedMessages: function (options) {
/* Fetch archived chat messages from the XMPP server. /* Fetch archived chat messages from the XMPP server.
* *
* Then, upon receiving them, call onMessage on the chat box, * Then, upon receiving them, call onMessage on the chat
* so that they are displayed inside it. * box, so that they are displayed inside it.
*/ */
var _converse = this.__super__._converse; var _converse = this.__super__._converse;
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) { if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313"); _converse.log(
"Attempted to fetch archived messages but this "+
"user's server doesn't support XEP-0313");
return; return;
} }
if (this.disable_mam) { if (this.disable_mam) {
@ -106,7 +108,9 @@
}.bind(this), }.bind(this),
function () { function () {
this.clearSpinner(); this.clearSpinner();
_converse.log("Error or timeout while trying to fetch archived messages", "error"); _converse.log(
"Error or timeout while trying to fetch "+
"archived messages", "error");
}.bind(this) }.bind(this)
); );
}, },
@ -132,8 +136,40 @@
return result; return result;
}, },
fetchArchivedMessages: function (options) {
/* Fetch archived chat messages from the XMPP server.
*
* Then, upon receiving them, call onChatRoomMessage
* so that they are displayed inside it.
*/
var that = this;
var _converse = this.__super__._converse;
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.log(
"Attempted to fetch archived messages but this "+
"user's server doesn't support XEP-0313");
return;
}
if (!this.model.get('mam_enabled')) {
return;
}
this.addSpinner();
_converse.api.archive.query(_.extend(options, {'groupchat': true}),
function (messages) {
that.clearSpinner();
if (messages.length) {
_.each(messages, that.onChatRoomMessage.bind(that));
}
},
function () {
that.clearSpinner();
_converse.log(
"Error while trying to fetch archived messages",
"error");
}
);
}
} }
}, },

View File

@ -1888,32 +1888,6 @@
_converse.emit('message', message); _converse.emit('message', message);
} }
return true; return true;
},
fetchArchivedMessages: function (options) {
/* Fetch archived chat messages from the XMPP server.
*
* Then, upon receiving them, call onChatRoomMessage
* so that they are displayed inside it.
*/
var that = this;
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313");
return;
}
this.addSpinner();
_converse.api.archive.query(_.extend(options, {'groupchat': true}),
function (messages) {
that.clearSpinner();
if (messages.length) {
_.each(messages, that.onChatRoomMessage.bind(that));
}
},
function () {
that.clearSpinner();
_converse.log("Error while trying to fetch archived messages", "error");
}
);
} }
}); });