@Override
protected boolean onPresenceAvailable(String from, String to) {
if (to != null) {
Jid jid = new Jid(to);
if (jid.isUser()) {
Room room = server.getRoom(jid.getRoom());
User user = server.getUserByConnection(connection);
int ret = user.joinRoomWithNickname(room, jid.getName());
if (ret == 1) {
for (String other : room.getUserList()) {
if (!other.equals(jid.getName())) {
user.sendPresence(room, jid.getName(), other, null);
}
}
room.broadcastPresence(jid.getName(), null);
} else if (ret == 0) {
// The nick already existed, send a conflict.
user.sendPresenceConflict(room, to);
return false;
}