try {
connectContext.getCallbackHandler().handle(cb);
client.addSessionListener(new ISessionListener() {
public void sessionConnected(ChatSession session) {
try {
Contact contact = session.getParticipants()[0];
final ID toID = namespace
.createInstance(new Object[] { contact
.getEmail() });
chatSessions.put(toID, session);
session.addChatSessionListener(new ChatSessionListener(
toID));
} catch (IDCreateException e) {
// ignored since this should not be possible
}
}
});
client.getContactList().addContactListListener(
new IContactListListener() {
public void contactAdded(Contact contact) {
final MSNRosterEntry entry = new MSNRosterEntry(
MSNContainer.this, contact, namespace);
for (int i = 0; i < entries.size(); i++) {
Object e = entries.get(i);
if (e instanceof MSNRosterGroup) {
MSNRosterGroup group = (MSNRosterGroup) e;
if (group.getGroup().contains(contact)) {
MSNRosterEntry check = group
.getEntryFor(contact);
if (check == null) {
check = entry;
contact
.addContactListener(new IContactListener() {
public void nameChanged(
String name) {
firePresence(
entry
.getID(),
entry
.getPresence());
fireRosterUpdate(entry);
}
public void personalMessageChanged(
String personalMessage) {
entry
.updatePersonalMessage();
firePresence(
entry
.getID(),
entry
.getPresence());
fireRosterUpdate(entry);
}
public void statusChanged(
Status status) {
firePresence(
entry
.getID(),
entry
.getPresence());
fireRosterUpdate(entry);
}
});
group.add(check);
fireRosterEntryAdded(check);
}
fireRosterUpdate(group);
return;
}
} else {
MSNRosterEntry check = (MSNRosterEntry) e;
if (entry.getContact().equals(
check.getContact())) {
fireRosterEntryAdded(check);
fireRosterUpdate(check.getParent());
return;
}
}
}
contact.addContactListener(new IContactListener() {
public void nameChanged(String name) {
firePresence(entry.getID(), entry
.getPresence());
fireRosterUpdate(entry);
}
public void personalMessageChanged(
String personalMessage) {
entry.updatePersonalMessage();
firePresence(entry.getID(), entry
.getPresence());
fireRosterUpdate(entry);
}
public void statusChanged(Status status) {
firePresence(entry.getID(), entry
.getPresence());
fireRosterUpdate(entry);
}
});
entries.add(entry);
entry.setParent(MSNContainer.this);
fireRosterEntryAdded(entry);
fireRosterUpdate(MSNContainer.this);
}
public void contactRemoved(Contact contact) {
MSNRosterEntry entry = findEntry(entries, contact
.getEmail());
if (entry != null) {
fireHandleUnsubscribed(entry.getUser().getID());
fireRosterEntryRemoved(entry);
fireRosterUpdate(entry.getParent());