if (disconnectCalled) {
throw new IMException("Unable to send message cause the IM connection is been " +
"disconnected");
}
if (loginProcessed && loggedIn) {
final Email email = Email.parseStr(to);
final String text = message;
messageCount ++;
MsnSwitchboard[] switchboards = messenger.getActiveSwitchboards();
for (MsnSwitchboard switchboard1 : switchboards) {
if (switchboard1.containContact(email)
&& switchboard1.getAllContacts().length == 1) {
switchboard1.sendText(text);
messageCount--;
return;
}
}
final Object attachment = new Object();
messenger.addSwitchboardListener(new MsnSwitchboardAdapter() {
public void switchboardStarted(MsnSwitchboard switchboard) {
if (switchboard.getAttachment() == attachment) {
switchboard.inviteContact(email);
}
}
public void contactJoinSwitchboard(MsnSwitchboard switchboard,
MsnContact contact) {
if (switchboard.getAttachment() == attachment
&& email.equals(contact.getEmail())) {
switchboard.setAttachment(null);
messenger.removeSwitchboardListener(this);
switchboard.sendText(text);
messageCount --;
}