Exemple #1
0
        public override bool NewIQ(IQ iq)
        {
            if (!(iq is RosterIQ))
            {
                return(false);
            }

            RosterIQ rostiq = iq as RosterIQ;

            if (iq.ID == RosterIQ.ID)
            {
                //<iq type="result" id="aab8a" to="[email protected]/hypnotoad">
                //<query xmlns="jabber:iq:roster">
                ///<item jid="*****@*****.**" name="BrianBonnett" subscription="both">
                ///    <group>Friends</group>
                ///</item>
                ///</query>
                ///</iq>
                ///


                this.Success = false;
                if (iq.Type == IQType.result.ToString())
                {
                    if ((rostiq.Query != null) && (rostiq.Query.RosterItems != null))
                    {
                        foreach (rosteritem item in rostiq.Query.RosterItems)
                        {
                            RosterItem ros = new RosterItem(XMPPClient, item.JID);

                            if (item.Ask == "subscribe")
                            {
                                /// Need to do subscribe to this user's presence some how
                                ///
                            }

                            /// See if we already have this roster item
                            ///
                            RosterItem existingitem = XMPPClient.FindRosterItem(ros.JID);
                            if (existingitem != null)
                            {
                                existingitem.Name         = (item.Name != null) ? item.Name : ros.JID.BareJID;
                                existingitem.Subscription = (item.Subscription != null) ? item.Subscription : "";
                                existingitem.Node         = item;
                                existingitem.Groups.Clear();
                                /// Get the group for this item
                                if (item.Groups != null)
                                {
                                    foreach (string strGroup in item.Groups)
                                    {
                                        ros.Group = strGroup;
                                        ros.Groups.Add(strGroup);
                                    }
                                }
                            }
                            else
                            {
                                ros.Name         = (item.Name != null) ? item.Name : ros.JID.BareJID;
                                ros.Subscription = (item.Subscription != null) ? item.Subscription : "";
                                ros.Node         = item;
                                XMPPClient.RosterItems.Add(ros);
                                /// Get the group for this item
                                if (item.Groups != null)
                                {
                                    foreach (string strGroup in item.Groups)
                                    {
                                        ros.Group = strGroup;
                                        if (ros.Groups.Contains(strGroup) == false)
                                        {
                                            ros.Groups.Add(strGroup);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    this.Success = true;
                    XMPPClient.FireGotRoster();
                }

                this.IsCompleted = false;

                return(true);
            }
            else if (iq.Type == "set")
            {
                //<iq type="set" id="640-356" to="[email protected]/phone"><query xmlns="jabber:iq:roster"><item jid="*****@*****.**" ask="subscribe" subscription="from"/></query></iq>

                if ((rostiq.Query != null) && (rostiq.Query.RosterItems != null))
                {
                    foreach (rosteritem item in rostiq.Query.RosterItems)
                    {
                        RosterItem ros = new RosterItem(XMPPClient, item.JID)
                        {
                            XMPPClient   = XMPPClient,
                            Name         = item.Name,
                            Subscription = item.Subscription,
                            Node         = item,
                        };

                        if (XMPPClient.FindRosterItem(ros.JID) == null)
                        {
                            XMPPClient.RosterItems.Add(ros);

                            if (item.Groups != null)
                            {
                                foreach (string strGroup in item.Groups)
                                {
                                    ros.Group = strGroup;
                                    if (ros.Groups.Contains(strGroup) == false)
                                    {
                                        ros.Groups.Add(strGroup);
                                    }
                                }
                            }

                            XMPPClient.AsyncFireListChanged();
                        }

                        if (item.Subscription == subscription.from.ToString())  /// should only have a from subscription if we've added the roster item
                        {
                            //if (XMPPClient.AutoAcceptPresenceSubscribe
                            /// subscribe to presence of this one
                            XMPPClient.PresenceLogic.SubscribeToPresence(ros.JID.BareJID);
                        }
                    }

                    iq.Type     = IQType.result.ToString();
                    iq.To       = iq.From;
                    iq.From     = XMPPClient.JID;
                    iq.InnerXML = null;
                    XMPPClient.SendXMPP(iq);

                    this.Success = true;
                    return(true);
                }
            }


            return(false);
        }