var user = null;
var onlineContacts = [];
var offlineContacts = [];
// Handle authentication - sign the user in.
function onAuthCompleted(sender, e) {
user = new Microsoft.Live.Messenger.User(e.get_identity());
user.get_onlineContacts().add_collectionChanged(onOnlineContactsChanged);
user.get_offlineContacts().add_collectionChanged(onOfflineContactsChanged);
user.signIn();
}
// Responsible for updating the onlineContacts array to match
// the User.OnlineContacts collection.
function onOnlineContactsChanged(sender, e) {
switch (e.get_action()) {
case Microsoft.Live.Messenger.NotifyCollectionChangedAction.add:
onlineContacts.splice(e.get_newStartingIndex(), 0, e.get_newItems());
break;
case Microsoft.Live.Messenger.NotifyCollectionChangedAction.remove:
onlineContacts.splice(e.get_oldStartingIndex(), e.get_oldItems().length);
break;
case Microsoft.Live.Messenger.NotifyCollectionChangedAction.reset:
onlineContacts = new Array(sender.get_count());
for (var i = 0; i < sender.get_count(); i++) {
onlineContacts[i] = sender.get_item(i);
}
break;
}
}
// Responsible for updating the offlineContacts array to match
// the User.OfflineContacts collection.
function onOfflineContactsChanged(sender, e) {
switch (e.get_action()) {
case Microsoft.Live.Messenger.NotifyCollectionChangedAction.add:
offlineContacts.splice(e.get_newStartingIndex(), 0, e.get_newItems());
break;
case Microsoft.Live.Messenger.NotifyCollectionChangedAction.remove:
offlineContacts.splice(e.get_oldStartingIndex(), e.get_oldItems().length);
break;
case Microsoft.Live.Messenger.NotifyCollectionChangedAction.reset:
offlineContacts = new Array(sender.get_count());
for (var i = 0; i < sender.get_count(); i++) {
offlineContacts[i] = sender.get_item(i);
}
break;
}
}