Bugfix for groupchat archive queries.

Groupchat queries should have a "to" parameter on the IQ stanza and don't use
the "with" query option.

updates #306
This commit is contained in:
JC Brand 2015-07-21 11:38:44 +02:00
parent e03db127cf
commit 404ab96609

View File

@ -1320,7 +1320,7 @@
* Then, upon receiving them, call onMessage on the chat box, * Then, upon receiving them, call onMessage on the chat box,
* so that they are displayed inside it. * so that they are displayed inside it.
*/ */
API.archive.query(options, API.archive.query(_.extend(options, {'groupchat': this.is_chatroom}),
function (messages) { function (messages) {
this.clearSpinner(); this.clearSpinner();
if (messages.length) { if (messages.length) {
@ -2779,7 +2779,6 @@
converse.emit('chatRoomOpened', this); converse.emit('chatRoomOpened', this);
this.$el.insertAfter(converse.chatboxviews.get("controlbox").$el); this.$el.insertAfter(converse.chatboxviews.get("controlbox").$el);
this.model.messages.fetch({add: true});
if (this.model.get('minimized')) { if (this.model.get('minimized')) {
this.hide(); this.hide();
} else { } else {
@ -3037,26 +3036,26 @@
}, },
join: function (password, history_attrs, extended_presence) { join: function (password, history_attrs, extended_presence) {
var msg = $pres({ var stanza = $pres({
from: converse.connection.jid, from: converse.connection.jid,
to: this.getRoomJIDAndNick() to: this.getRoomJIDAndNick()
}).c("x", { }).c("x", {
xmlns: Strophe.NS.MUC xmlns: Strophe.NS.MUC
}); });
if (typeof history_attrs === "object" && history_attrs.length) { if (typeof history_attrs === "object" && Object.keys(history_attrs).length) {
msg = msg.c("history", history_attrs).up(); stanza = stanza.c("history", history_attrs).up();
} }
if (password) { if (password) {
msg.cnode(Strophe.xmlElement("password", [], password)); stanza.cnode(Strophe.xmlElement("password", [], password));
} }
if (typeof extended_presence !== "undefined" && extended_presence !== null) { if (typeof extended_presence !== "undefined" && extended_presence !== null) {
msg.up.cnode(extended_presence); stanza.up.cnode(extended_presence);
} }
if (!this.handler) { if (!this.handler) {
this.handler = converse.connection.addHandler(this.handleMUCStanza.bind(this)); this.handler = converse.connection.addHandler(this.handleMUCStanza.bind(this));
} }
this.model.set('connection_status', Strophe.Status.CONNECTING); this.model.set('connection_status', Strophe.Status.CONNECTING);
return converse.connection.send(msg); return converse.connection.send(stanza);
}, },
leave: function(exit_msg) { leave: function(exit_msg) {
@ -3362,6 +3361,7 @@
($presence.attr('from') == this.model.get('id')+'/'+Strophe.escapeNode(nick)); ($presence.attr('from') == this.model.get('id')+'/'+Strophe.escapeNode(nick));
if (this.model.get('connection_status') !== Strophe.Status.CONNECTED) { if (this.model.get('connection_status') !== Strophe.Status.CONNECTED) {
this.model.set('connection_status', Strophe.Status.CONNECTED); this.model.set('connection_status', Strophe.Status.CONNECTED);
this.fetchMessages();
this.$('span.centered.spinner').remove(); this.$('span.centered.spinner').remove();
this.$el.find('.chat-body').children().show(); this.$el.find('.chat-body').children().show();
} }
@ -6334,13 +6334,21 @@
throw new Error('This server does not support XEP-0313, Message Archive Management'); throw new Error('This server does not support XEP-0313, Message Archive Management');
} }
var queryid = converse.connection.getUniqueId(); var queryid = converse.connection.getUniqueId();
var stanza = $iq({'type':'set'}).c('query', {'xmlns':Strophe.NS.MAM, 'queryid':queryid});
var attrs = {'type':'set'};
if (typeof options != "undefined" && options.groupchat) {
if (!options['with']) {
throw new Error('You need to specify a "with" value containing the chat room JID, when querying groupchat messages.');
}
attrs.to = options['with'];
}
var stanza = $iq(attrs).c('query', {'xmlns':Strophe.NS.MAM, 'queryid':queryid});
if (typeof options != "undefined") { if (typeof options != "undefined") {
stanza.c('x', {'xmlns':Strophe.NS.XFORM}) stanza.c('x', {'xmlns':Strophe.NS.XFORM})
.c('field', {'var':'FORM_TYPE'}) .c('field', {'var':'FORM_TYPE'})
.c('value').t(Strophe.NS.MAM).up().up(); .c('value').t(Strophe.NS.MAM).up().up();
if (options['with']) { if (options['with'] && !options.groupchat) {
stanza.c('field', {'var':'with'}).c('value').t(options['with']).up().up(); stanza.c('field', {'var':'with'}).c('value').t(options['with']).up().up();
} }
_.each(['start', 'end'], function (t) { _.each(['start', 'end'], function (t) {