Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Merge branch 'nick_assignment_fix' of git://github.com/PaulSD/candy i…
Browse files Browse the repository at this point in the history
…nto dev
  • Loading branch information
mweibel committed Jan 13, 2014
2 parents a84fc5c + 81b18f7 commit 042a6f2
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/core/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,31 +405,35 @@ 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) {
Candy.Core.getRooms()[roomJid] = new Candy.Core.ChatRoom(roomJid);
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,
Expand All @@ -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';
Expand Down Expand Up @@ -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;
},
Expand Down

0 comments on commit 042a6f2

Please sign in to comment.