Jibbr.ViewModels.AccountViewModel.OnRosterItem C# (CSharp) Method

OnRosterItem() private method

private OnRosterItem ( object sender, agsXMPP item ) : void
sender object
item agsXMPP
return void
        private void OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
        {
            Execute.BeginOnUIThread
            (
                new System.Action
                (
                    () =>
                    {
                        //Create the new JIDViewModel
                        JIDViewModel jidvm = new JIDViewModel(item.Jid, this);
                        //Add it to each group.  Create the group when needed
                        agsXMPP.Xml.Dom.ElementList list = item.GetGroups();
                        foreach (agsXMPP.Xml.Dom.Element element in list)
                        {
                            agsXMPP.protocol.Base.Group group = element as agsXMPP.protocol.Base.Group;
                            RosterGroupViewModel rosterGroupVM = this.groups.SingleOrDefault(x => x.GroupName == group.Name);
                            if (rosterGroupVM == null)
                            {
                                rosterGroupVM = new RosterGroupViewModel(group, this);
                                this.groups.Add(rosterGroupVM);
                                //Shitty, but this is the only way to re-order an observable collection
                                groups = new ObservableCollection<RosterGroupViewModel>(groups.OrderBy(x => x.GroupName));
                                NotifyOfPropertyChange(() => Groups);
                            }
                            rosterGroupVM.Members.Add(jidvm);
                        }
                        //Add to our friends
                        friends.Add(jidvm);
                    }
                )
            );
        }