Commit 02a055d3 authored by JC Brand's avatar JC Brand

Bugfix. Query user's JID for `mam:2` support, not the domain

parent 5e68364e
......@@ -32,6 +32,7 @@
- #866 Add babel in order to support ES2015 syntax [jcbrand]
#### Bugfixes:
- The domain was queried for MAM:2 support, instead of the JID. [jcbrand]
- Roster filter is not shown when all groups are collapsed. [jcbrand]
- When filtering, contacts in closed groups appear. [jcbrand]
- Room name wasn't being updated after changing it in the configuration form. [jcbrand]
......
......@@ -1450,8 +1450,7 @@
});
}));
it("is sent when the user maximizes a minimized a chat box",
mock.initConverseWithPromises(
it("is sent when the user maximizes a minimized a chat box", mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......@@ -1474,7 +1473,11 @@
}, 300);
}).then(function () {
expect(_converse.connection.send).toHaveBeenCalled();
var $stanza = $(_converse.connection.send.calls.argsFor(0)[0].tree());
var calls = _.filter(_converse.connection.send.calls.all(), function (call) {
return call.args[0] instanceof Strophe.Builder;
});
expect(calls.length).toBe(1);
var $stanza = $(calls[0].args[0].tree());
expect($stanza.attr('to')).toBe(contact_jid);
expect($stanza.children().length).toBe(3);
expect($stanza.children().get(0).tagName).toBe('active');
......@@ -1637,7 +1640,12 @@
}, 500);
}).then(function () {
expect(_converse.connection.send).toHaveBeenCalled();
var $stanza = $(_converse.connection.send.calls.argsFor(1)[0].tree());
var calls = _.filter(_converse.connection.send.calls.all(), function (call) {
return call.args[0] instanceof Strophe.Builder;
});
expect(calls.length).toBe(2);
var $stanza = $(calls[1].args[0].tree());
expect($stanza.attr('to')).toBe(contact_jid);
expect($stanza.children().length).toBe(3);
expect($stanza.children().get(0).tagName).toBe('paused');
......@@ -1776,7 +1784,11 @@
}, 250);
}).then(function () {
expect(_converse.connection.send).toHaveBeenCalled();
var $stanza = $(_converse.connection.send.calls.first().args[0].tree());
var calls = _.filter(_converse.connection.send.calls.all(), function (call) {
return call.args[0] instanceof Strophe.Builder;
});
expect(calls.length).toBe(2);
var $stanza = $(calls[0].args[0].tree());
expect($stanza.attr('to')).toBe(contact_jid);
expect($stanza.children().length).toBe(3);
expect($stanza.children().get(0).tagName).toBe('paused');
......
......@@ -105,6 +105,7 @@
'from': stanza.getAttribute('from')
});
});
this.trigger('featuresDiscovered');
}
});
......@@ -118,7 +119,7 @@
this.fetchEntities().then(
_.partial(_converse.emit, 'discoInitialized'),
_.partial(_converse.emit, 'discoInitialized')
);
).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
},
fetchEntities () {
......
......@@ -18,12 +18,38 @@
], factory);
}(this, function ($, converse) {
"use strict";
const { Strophe, $iq, _, moment } = converse.env;
const { Promise, Strophe, $iq, _, moment } = converse.env;
const RSM_ATTRIBUTES = ['max', 'first', 'last', 'after', 'before', 'index', 'count'];
// XEP-0313 Message Archive Management
const MAM_ATTRIBUTES = ['with', 'start', 'end'];
function checkMAMSupport (_converse) {
/* Returns a promise which resolves when MAM is supported
* for this user, or which rejects if not.
*/
return _converse.api.waitUntil('discoInitialized').then(() =>
new Promise((resolve, reject) => {
function fulfillPromise (entity) {
if (entity.features.findWhere({'var': Strophe.NS.MAM})) {
resolve(true);
} else {
resolve(false);
}
}
let entity = _converse.disco_entities.get(_converse.bare_jid);
if (_.isUndefined(entity)) {
entity = _converse.disco_entities.create({'jid': _converse.bare_jid});
entity.on('featuresDiscovered', _.partial(fulfillPromise, entity));
} else {
fulfillPromise(entity);
}
})
);
}
converse.plugins.add('converse-mam', {
overrides: {
......@@ -51,18 +77,33 @@
fetchArchivedMessagesIfNecessary () {
/* Check if archived messages should be fetched, and if so, do so. */
const { _converse } = this.__super__,
entity = _converse.disco_entities.get(_converse.domain),
server_supports_mam = entity.features.findWhere({'var': Strophe.NS.MAM});
if (this.disable_mam ||
!server_supports_mam ||
this.model.get('mam_initialized')) {
if (this.disable_mam || this.model.get('mam_initialized')) {
return;
}
const { _converse } = this.__super__;
this.addSpinner();
checkMAMSupport(_converse).then(
(supported) => { // Success
if (supported) {
this.fetchArchivedMessages();
} else {
this.clearSpinner();
}
this.model.save({'mam_initialized': true});
},
() => { // Error
this.clearSpinner();
_converse.log(
"Error or timeout while checking for MAM support",
Strophe.LogLevel.ERROR
);
}
).catch((msg) => {
this.clearSpinner();
_converse.log(msg, Strophe.LogLevel.FATAL);
});
},
fetchArchivedMessages (options) {
/* Fetch archived chat messages from the XMPP server.
......@@ -71,7 +112,7 @@
* box, so that they are displayed inside it.
*/
const { _converse } = this.__super__;
if (!_converse.disco_entities.get(_converse.domain)
if (!_converse.disco_entities.get(_converse.bare_jid)
.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.log(
......@@ -361,9 +402,7 @@
});
_converse.on('afterMessagesFetched', (chatboxview) => {
_converse.api.waitUntil('discoInitialized')
.then(chatboxview.fetchArchivedMessagesIfNecessary.bind(chatboxview))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
chatboxview.fetchArchivedMessagesIfNecessary();
});
}
});
......
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