From 81b18f7790cd0d7a256364bd7bcf4e76e549e38b Mon Sep 17 00:00:00 2001 From: Paul Donohue Date: Fri, 10 Jan 2014 17:02:09 -0500 Subject: [PATCH] Properly handle nick assignment when joining a MUC room --- src/core/event.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/core/event.js b/src/core/event.js index 0574fda1..562cb872 100644 --- a/src/core/event.js +++ b/src/core/event.js @@ -405,24 +405,21 @@ Candy.Core.Event = (function(self, Strophe, $) { roomJid = Strophe.getBareJidFromJid(from), presenceType = msg.attr('type'), status = msg.find('status'), + nickAssign = false, nickChange = false; if(status.length) { - // check if status code indicates a nick change + // check if status code indicates a nick assignment or nick change for(var i = 0, l = status.length; i < l; i++) { var $status = $(status[i]); - if($status.attr('code') === '303') { + if($status.attr('code') === '210') { + nickAssign = true; + } else if($status.attr('code') === '303') { nickChange = true; } } } - // Current User left a room - if(Strophe.getResourceFromJid(from) === Candy.Core.getUser().getNick() && presenceType === 'unavailable' && nickChange === false) { - self.Jabber.Room.Leave(msg); - return true; - } - // Current User joined a room var room = Candy.Core.getRoom(roomJid); if(!room) { @@ -430,6 +427,13 @@ Candy.Core.Event = (function(self, Strophe, $) { room = Candy.Core.getRoom(roomJid); } + // Current User left a room + var currentUser = room.getUser() ? room.getUser() : Candy.Core.getUser(); + if(Strophe.getResourceFromJid(from) === currentUser.getNick() && presenceType === 'unavailable' && nickChange === false) { + self.Jabber.Room.Leave(msg); + return true; + } + var roster = room.getRoster(), action, user, nick, @@ -443,8 +447,9 @@ Candy.Core.Event = (function(self, Strophe, $) { nick = Strophe.getResourceFromJid(from); user = new Candy.Core.ChatUser(from, nick, item.attr('affiliation'), item.attr('role')); // Room existed but client (myself) is not yet registered - if(room.getUser() === null && Candy.Core.getUser().getNick() === nick) { + if(room.getUser() === null && (Candy.Core.getUser().getNick() === nick || nickAssign)) { room.setUser(user); + currentUser = user; } roster.add(user); action = 'join'; @@ -486,7 +491,7 @@ Candy.Core.Event = (function(self, Strophe, $) { 'roomName': room.getName(), 'user': user, 'action': action, - 'currentUser': Candy.Core.getUser() + 'currentUser': currentUser }); return true; },