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

Properly handle nick assignment when joining a MUC room #208

Merged
merged 1 commit into from
Jan 13, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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