converse-mam: Don't fetch MAM messages on each page load.
This commit is contained in:
parent
3b3720c32d
commit
2a81d2e6f3
@ -3,6 +3,7 @@
|
||||
## 2.0.4 (Unreleased)
|
||||
- Bugfix. Switching from bookmarks form to config form shows only the spinner. [jcbrand]
|
||||
- Bugfix. Other room occupants sometimes not shown when reloading the page. [jcbrand]
|
||||
- Optimize fetching of MAM messages (in some cases happened on each page load). [jcbrand]
|
||||
|
||||
## 2.0.3 (2016-11-30)
|
||||
- #735 Room configuration button not visible. [jcbrand]
|
||||
|
@ -69,12 +69,15 @@
|
||||
if (this.disable_mam || !converse.features.findWhere({'var': Strophe.NS.MAM})) {
|
||||
return this.__super__.afterMessagesFetched.apply(this, arguments);
|
||||
}
|
||||
if (this.model.messages.length < converse.archived_messages_page_size) {
|
||||
if (!this.model.get('mam_initialized') &&
|
||||
this.model.messages.length < converse.archived_messages_page_size) {
|
||||
|
||||
this.fetchArchivedMessages({
|
||||
'before': '', // Page backwards from the most recent message
|
||||
'with': this.model.get('jid'),
|
||||
'max': converse.archived_messages_page_size
|
||||
});
|
||||
this.model.save({'mam_initialized': true});
|
||||
}
|
||||
return this.__super__.afterMessagesFetched.apply(this, arguments);
|
||||
},
|
||||
|
@ -1583,6 +1583,7 @@
|
||||
* 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;
|
||||
@ -1590,15 +1591,15 @@
|
||||
this.addSpinner();
|
||||
converse_api.archive.query(_.extend(options, {'groupchat': true}),
|
||||
function (messages) {
|
||||
this.clearSpinner();
|
||||
that.clearSpinner();
|
||||
if (messages.length) {
|
||||
_.map(messages, this.onChatRoomMessage.bind(this));
|
||||
_.map(messages, that.onChatRoomMessage.bind(that));
|
||||
}
|
||||
}.bind(this),
|
||||
},
|
||||
function () {
|
||||
this.clearSpinner();
|
||||
that.clearSpinner();
|
||||
converse.log("Error while trying to fetch archived messages", "error");
|
||||
}.bind(this)
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user