Commit 388012f2 authored by JC Brand's avatar JC Brand

Workaround for ejabberd...

which doesn't support getting the item count of archived messages.
See here: https://xmpp.org/extensions/xep-0059.html#count

So we don't first fetch a count of archived messages instead try to fetch the
messages themselves immediately.

updates #306
parent 79fba8a6
...@@ -1297,42 +1297,20 @@ ...@@ -1297,42 +1297,20 @@
*/ */
this.model.messages.fetch({ this.model.messages.fetch({
'add': true, 'add': true,
'success': this.afterFetchingCachedMessages.bind(this) 'success': function () {
}); if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
return this; return;
}, }
if (this.model.messages.length < converse.archived_messages_batch_size) {
afterFetchingCachedMessages: function () {
/* Handler method, called after messages cached in
* sessionStorage have been fetched.
*
* The goal of this method is to determine how many archived
* messages exist and whether we should fetch them or not.
*/
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
return;
}
if (this.model.messages.length < converse.archived_messages_batch_size) {
// Get the amount of archived messages
// Refer to: https://xmpp.org/extensions/xep-0059.html#count
API.archive.query({
'with': this.model.get('jid'),
'max': 0
},
function (messages, attrs) { // On Success
if (this.model.messages.length < Number(attrs.count)) {
this.fetchArchivedMessages({ this.fetchArchivedMessages({
'before': '', // Page backwards from the most recent message 'before': '', // Page backwards from the most recent message
'with': this.model.get('jid'), 'with': this.model.get('jid'),
'max': converse.archived_messages_batch_size 'max': converse.archived_messages_batch_size
}); });
} }
}.bind(this),
function (iq) { // On Error
converse.log("Error occured while trying to fetch the archived messages count", "error");
}.bind(this) }.bind(this)
); });
} return this;
}, },
fetchArchivedMessages: function (options) { fetchArchivedMessages: function (options) {
......
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