Commit 61b2dc7f authored by JC Brand's avatar JC Brand

Move MAM code to proper place.

Also, don't query for MAM messages if the chat room doesn't support it.
parent 0d48929b
...@@ -86,12 +86,14 @@ ...@@ -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 @@ ...@@ -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 @@ ...@@ -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");
}
);
}
} }
}, },
......
...@@ -1888,32 +1888,6 @@ ...@@ -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");
}
);
} }
}); });
......
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