Esempio n. 1
0
 /// <summary>
 /// Se produit lorsque un �l�ment du Roster est re�u
 /// </summary>
 /// <param name="sender">Objet parent</param>
 /// <param name="item">Element du ROster re�u</param>
 private void xmppOnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
 {
     if (item.Jid != null)
     {
         string bare = item.Jid.Bare.Trim();
         string resource = (item.Jid.Resource != null) ? item.Jid.Resource.Trim() : string.Empty;
         if (item.Subscription == agsXMPP.protocol.iq.roster.SubscriptionType.remove)
         {
             // si le contact existe
             if (contacts.ContainsKey(bare))
             {
                 foreach (KeyValuePair<string, Contact> r in contacts[bare])
                 {
                     r.Value.Dispose();
                     OnResourceRemoved(r.Value);
                 }
                 contacts.Remove(bare);
                 OnContactRemoved(bare);
             }
         }
         else
         {
             // si le contact n'existe pas encore
             if (!contacts.ContainsKey(bare))
             {
                 contacts.Add(bare, new Dictionary<string, Contact>());
                 OnContactAdded(bare);
             }
             // si on a une resource disponible sur ce contact
             if (resource != string.Empty)
             {
                 // si elle n'existe pas encore
                 if (!contacts[bare].ContainsKey(resource))
                 {
                     contacts[bare].Add(resource, new Contact(item.Jid, ((item.Name != null) ? item.Name : string.Empty), item.GetGroups()));
                     contacts[bare][resource].subscription = Enumerations.SubscribtionTypeConverter(item.Subscription);
                     OnResourceAdded(contacts[bare][resource]);
                 }
             }
             if (item.Subscription == agsXMPP.protocol.iq.roster.SubscriptionType.from)
             {
                 subscribe(bare);
             }
             privacyListUpdated(Jabber._privacy);
         }
     }
 }
Esempio n. 2
0
        public RosterNode AddRosterItem(agsXMPP.protocol.iq.roster.RosterItem ritem)
        {
            string nodeText = ritem.Name != null ? ritem.Name : ritem.Jid.ToString();
            RosterNode node;

            if (!m_Roster.ContainsKey(ritem.Jid.ToString()))
            {
                node = new RosterNode();

                node.Text = nodeText;
                node.RosterItem = ritem;
                node.NodeType = RosterNodeType.RosterNode;
                node.ImageIndex = IMAGE_OFFLINE;
                node.SelectedImageIndex = IMAGE_OFFLINE;

                string groupname;
                if (ritem.GetGroups().Count > 0)
                {
                    Group g = (Group)ritem.GetGroups().Item(0);
                    groupname = g.Name;
                }
                else
                {
                    groupname = m_DefaultGroupName;
                }

                RosterNode group = GetGroup(m_RootOffline, groupname);
                if (group == null)
                    group = AddGroup(groupname, m_RootOffline);

                group.Nodes.Add(node);
                //group.Text = group.Name + " (" + group.Nodes.Count.ToString() + ")";
                m_Roster.Add(ritem.Jid.ToString(), new RosterData(node));

                return node;
            }
            else
            {
                if (m_Roster[ritem.Jid.ToString()].Online)
                {                   
                    // We upate a rosterItem which is online and has Presences
                    // So store this Presences before we remove this item and add them to the 
                    // new Node again                  
                    Presence[] pres = new Presence[m_Roster[ritem.Jid.ToString()].Presences.Count];
                    int i= 0;
                    Dictionary<string, PresenceData>.Enumerator myEnum = m_Roster[ritem.Jid.ToString()].Presences.GetEnumerator();
                    while (myEnum.MoveNext())
                    {
                       pres[i] = myEnum.Current.Value.Presence;
                       i++;
                    }
                    RemoveRosterItem(ritem);
                    node = AddRosterItem(ritem);
                    foreach (Presence p in pres)
                    {
                        SetPresence(p);
                    }
                    return node;
                }
                else
                {
                    RemoveRosterItem(ritem);
                    return AddRosterItem(ritem);
                }
            }
        }
Esempio n. 3
0
 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);
             }
         )
     );
 }