Two chat room bugfixes. updates #307

* Prevent "join" being called twice by having more finegrained connection
  status for a chat room.
* The directInvite method used the wrong JID.
* Rename getRoomJID to getRoomJIDAndNick to avoid confusion.
This commit is contained in:
JC Brand 2015-03-04 23:01:12 +01:00
parent db44a297cb
commit df724788fc

View File

@ -2407,7 +2407,7 @@
directInvite: function (receiver, reason) { directInvite: function (receiver, reason) {
var attrs = { var attrs = {
xmlns: 'jabber:x:conference', xmlns: 'jabber:x:conference',
jid: this.getRoomJID() jid: this.model.get('jid')
}; };
if (reason !== null) { attrs.reason = reason; } if (reason !== null) { attrs.reason = reason; }
if (this.model.get('password')) { attrs.password = this.model.get('password'); } if (this.model.get('password')) { attrs.password = this.model.get('password'); }
@ -2427,7 +2427,7 @@
createChatRoomMessage: function (text) { createChatRoomMessage: function (text) {
var msgid = converse.connection.getUniqueId(); var msgid = converse.connection.getUniqueId();
var msg = $msg({ var msg = $msg({
to: this.getRoomJID(), to: this.getRoomJIDAndNick(),
from: converse.connection.jid, from: converse.connection.jid,
type: 'groupchat', type: 'groupchat',
id: msgid id: msgid
@ -2531,7 +2531,7 @@
case 'nick': case 'nick':
converse.connection.send($pres({ converse.connection.send($pres({
from: converse.connection.jid, from: converse.connection.jid,
to: this.getRoomJID(match[2]), to: this.getRoomJIDAndNick(match[2]),
id: converse.connection.getUniqueId() id: converse.connection.getUniqueId()
}).tree()); }).tree());
break; break;
@ -2593,7 +2593,7 @@
return true; return true;
}, },
getRoomJID: function (nick) { getRoomJIDAndNick: function (nick) {
nick = nick || this.model.get('nick'); nick = nick || this.model.get('nick');
var room = this.model.get('jid'); var room = this.model.get('jid');
var node = Strophe.escapeNode(Strophe.getNodeFromJid(room)); var node = Strophe.escapeNode(Strophe.getNodeFromJid(room));
@ -2604,7 +2604,7 @@
join: function (password, history_attrs, extended_presence) { join: function (password, history_attrs, extended_presence) {
var msg = $pres({ var msg = $pres({
from: converse.connection.jid, from: converse.connection.jid,
to: this.getRoomJID() to: this.getRoomJIDAndNick()
}).c("x", { }).c("x", {
xmlns: Strophe.NS.MUC xmlns: Strophe.NS.MUC
}); });
@ -2620,6 +2620,7 @@
if (!this.handler) { if (!this.handler) {
this.handler = converse.connection.addHandler($.proxy(this.handleMUCStanza, this)); this.handler = converse.connection.addHandler($.proxy(this.handleMUCStanza, this));
} }
this.model.set('connection_status', Strophe.Status.CONNECTING);
return converse.connection.send(msg); return converse.connection.send(msg);
}, },
@ -2629,13 +2630,13 @@
type: "unavailable", type: "unavailable",
id: presenceid, id: presenceid,
from: converse.connection.jid, from: converse.connection.jid,
to: this.getRoomJID() to: this.getRoomJIDAndNick()
}); });
if (exit_msg !== null) { if (exit_msg !== null) {
presence.c("status", exit_msg); presence.c("status", exit_msg);
} }
converse.connection.addHandler( converse.connection.addHandler(
$.proxy(function () { this.model.set('connected', false); }, this), $.proxy(function () { this.model.set('connection_status', Strophe.Status.DISCONNECTED); }, this),
null, "presence", null, presenceid); null, "presence", null, presenceid);
converse.connection.send(presence); converse.connection.send(presence);
}, },
@ -2872,7 +2873,7 @@
for (i=0; i<reasons.length; i++) { for (i=0; i<reasons.length; i++) {
this.showDisconnectMessage(__('The reason given is: "'+reasons[i]+'"'), true); this.showDisconnectMessage(__('The reason given is: "'+reasons[i]+'"'), true);
} }
this.model.set('connected', false); this.model.set('connection_status', Strophe.Status.DISCONNECTED);
return; return;
} }
$chat_content = this.$el.find('.chat-content'); $chat_content = this.$el.find('.chat-content');
@ -2921,13 +2922,13 @@
var $presence = $(pres), is_self; var $presence = $(pres), is_self;
var nick = this.model.get('nick'); var nick = this.model.get('nick');
if ($presence.attr('type') === 'error') { if ($presence.attr('type') === 'error') {
this.model.set('connected', false); this.model.set('connection_status', Strophe.Status.DISCONNECTED);
this.showErrorMessage($presence.find('error')); this.showErrorMessage($presence.find('error'));
} else { } else {
is_self = ($presence.find("status[code='110']").length) || is_self = ($presence.find("status[code='110']").length) ||
($presence.attr('from') == this.model.get('id')+'/'+Strophe.escapeNode(nick)); ($presence.attr('from') == this.model.get('id')+'/'+Strophe.escapeNode(nick));
if (!this.model.get('conneced')) { if (this.model.get('connection_status') !== Strophe.Status.CONNECTED) {
this.model.set('connected', true); this.model.set('connection_status', Strophe.Status.CONNECTED);
this.$('span.centered.spinner').remove(); this.$('span.centered.spinner').remove();
this.$el.find('.chat-body').children().show(); this.$el.find('.chat-body').children().show();
} }
@ -3052,7 +3053,10 @@
'box_id' : b64_sha1(room_jid), 'box_id' : b64_sha1(room_jid),
'password': $x.attr('password') 'password': $x.attr('password')
}); });
if (!chatroom.get('connected')) { if (!_.contains(
[Strophe.Status.CONNECTING, Strophe.Status.CONNECTED],
chatroom.get('connection_status'))
) {
converse.chatboxviews.get(room_jid).join(null); converse.chatboxviews.get(room_jid).join(null);
} }
} }
@ -3103,6 +3107,12 @@
chatbox = this.get(contact_jid); chatbox = this.get(contact_jid);
if (!chatbox) { if (!chatbox) {
/* FIXME: there is a bug here. If chat state notifications
* (because a roster contact closed a chat box of yours
* they had open) are received and we don't have a chat with
* the user, then a chat box is created here which then
* opens automatically :(
*/
var fullname = roster_item.get('fullname'); var fullname = roster_item.get('fullname');
fullname = _.isEmpty(fullname)? contact_jid: fullname; fullname = _.isEmpty(fullname)? contact_jid: fullname;
chatbox = this.create({ chatbox = this.create({