Пример #1
0
 [Test] public void Test_Groups()
 {
     RosterIQ riq = new RosterIQ(doc);
     Roster r = riq.Instruction;
     Item i = r.AddItem();
     i.JID = new JID("*****@*****.**");
     Group g = i.AddGroup("foo");
     Assert.AreEqual("<iq id=\""+riq.ID+"\" type=\"get\"><query xmlns=\"jabber:iq:roster\">" +
         "<item jid=\"[email protected]\"><group>foo</group></item></query></iq>",
         riq.ToString());
     g = i.AddGroup("foo");
     Assert.AreEqual("<iq id=\""+riq.ID+"\" type=\"get\"><query xmlns=\"jabber:iq:roster\">" +
         "<item jid=\"[email protected]\"><group>foo</group></item></query></iq>",
         riq.ToString());
     g = i.AddGroup("bar");
     Assert.AreEqual("<iq id=\""+riq.ID+"\" type=\"get\"><query xmlns=\"jabber:iq:roster\">" +
         "<item jid=\"[email protected]\"><group>foo</group><group>bar</group></item></query></iq>",
         riq.ToString());
     Assert.AreEqual(2, i.GetGroups().Length);
     Assert.AreEqual("foo", i.GetGroup("foo").GroupName);
     Assert.AreEqual("bar", i.GetGroup("bar").GroupName);
     i.RemoveGroup("foo");
     Assert.AreEqual(1, i.GetGroups().Length);
     Assert.AreEqual(null, i.GetGroup("foo"));
 }
Пример #2
0
        public void TestAdd()
        {
            RosterManager rm = new RosterManager();

            RosterIQ riq = new RosterIQ(doc);
            riq.Type = IQType.set;
            Roster r = riq.Instruction;
            Item i = r.AddItem();
            i.JID = new JID("foo", "bar", null);
            i.Nickname = "FOO";
            i.Subscription = Subscription.both;

            rm.AddRoster(riq);
            Assert.AreEqual(Subscription.both, rm["foo@bar"].Subscription);
            Assert.AreEqual("FOO", rm["foo@bar"].Nickname);

            riq = new RosterIQ(doc);
            riq.Type = IQType.set;
            r = riq.Instruction;
            i = r.AddItem();
            i.JID = new JID("foo", "bar", null);
            i.Nickname = "BAR";
            i.Subscription = Subscription.to;
            rm.AddRoster(riq);
            Assert.AreEqual(Subscription.to, rm["foo@bar"].Subscription);
            Assert.AreEqual("BAR", rm["foo@bar"].Nickname);
        }
Пример #3
0
 [Test] public void Test_Item()
 {
     RosterIQ riq = new RosterIQ(doc);
     Roster r = riq.Instruction;
     Item i = r.AddItem();
     i.JID = new JID("*****@*****.**");
     Assert.AreEqual("<iq id=\""+riq.ID+"\" type=\"get\"><query xmlns=\"jabber:iq:roster\">" +
         "<item jid=\"[email protected]\" /></query></iq>",
         riq.ToString());
 }
Пример #4
0
 public void Test_Ask()
 {
     RosterIQ riq = new RosterIQ(doc);
     Roster r = riq.Instruction;
     Item i = r.AddItem();
     Assert.AreEqual("", i.GetAttribute("ask"));
     Assert.AreEqual(Ask.NONE, i.Ask);
     i.Ask = Ask.subscribe;
     Assert.AreEqual("subscribe", i.GetAttribute("ask"));
     Assert.AreEqual(Ask.subscribe, i.Ask);
     i.Ask = Ask.NONE;
     Assert.AreEqual("", i.GetAttribute("ask"));
     Assert.AreEqual(Ask.NONE, i.Ask);
 }
Пример #5
0
 [Test] public void Test_GetItems()
 {
     RosterIQ riq = new RosterIQ(doc);
     Roster r = riq.Instruction;
     Item i = r.AddItem();
     i.JID = new JID("*****@*****.**");
     i = r.AddItem();
     i.Subscription = Subscription.from;
     i.JID = new JID("*****@*****.**");
     i.Subscription = Subscription.both;
     Item[] items = r.GetItems();
     Assert.AreEqual(items.Length, 2);
     Assert.AreEqual(items[0].JID, "*****@*****.**");
     Assert.AreEqual(items[1].JID, "*****@*****.**");
 }
Пример #6
0
        public void TestNumeric()
        {
            RosterManager rm = new RosterManager();

            RosterIQ riq = new RosterIQ(doc);
            riq.Type = IQType.set;
            Roster r = riq.Instruction;
            Item i = r.AddItem();
            i.JID = new JID("support", "conference.192.168.32.109", null);
            i.Nickname = "FOO";
            i.Subscription = Subscription.both;

            rm.AddRoster(riq);
            Assert.AreEqual(Subscription.both, rm["[email protected]"].Subscription);
            Assert.AreEqual("FOO", rm["[email protected]"].Nickname);
        }
Пример #7
0
        /// <summary>
        /// Remove a contact from the roster
        /// </summary>
        /// <param name="jid">Typically just a user@host JID</param>
        public void Remove(JID jid)
        {
/*
 * C: <iq from='[email protected]/balcony' type='set' id='delete_1'>
 *   <query xmlns='jabber:iq:roster'>
 *     <item jid='*****@*****.**' subscription='remove'/>
 *   </query>
 * </iq>
 */
            RosterIQ iq = new RosterIQ(m_stream.Document);

            iq.Type = IQType.set;
            Roster r    = iq.Instruction;
            Item   item = r.AddItem();

            item.JID          = jid;
            item.Subscription = Subscription.remove;
            Write(iq);  // ignore response
        }
Пример #8
0
        /// <summary>
        /// Removes a contact from the roster.
        /// This will also remove the subscription for that contact being removed.
        /// </summary>
        /// <param name="to">The JID to remove</param>
        public void RemoveRosterItem(JID to)
        {
            Debug.Assert(to != null);

/*
 * <iq from='[email protected]/balcony' type='set' id='roster_4'>
 * <query xmlns='jabber:iq:roster'>
 *  <item jid='*****@*****.**' subscription='remove'/>
 * </query>
 * </iq>
 */
            RosterIQ riq = new RosterIQ(Document);

            riq.Type = IQType.set;
            Roster r = riq.Instruction;
            Item   i = r.AddItem();

            i.JID          = to;
            i.Subscription = Subscription.remove;
            Write(riq); // don't care about result.  we should get a iq/response and a roster push.
        }
Пример #9
0
        public void Add(JID jid)
        {
            Item item = this[jid];

            // only create a new roster item if it does not already exist
            if (item == null)
            {
                RosterIQ iq = new RosterIQ(m_stream.Document);
                iq.Type = IQType.set;
                Roster r = iq.Instruction;
                item     = r.AddItem();
                item.JID = jid;
                Write(iq);
            }

            // subscribe to presence
            Presence sub = new Presence(m_stream.Document);

            sub.To   = jid;
            sub.Type = PresenceType.subscribe;
            Write(sub);
        }
Пример #10
0
        /// <summary>
        /// Sends a presence subscription request and updates the roster
        /// for a new roster contact.
        /// </summary>
        /// <param name="to">The JID of the contact (required)</param>
        /// <param name="nickname">The nickname to show for the contact.</param>
        /// <param name="groups">A list of groups to put the contact in.  May be null.  Hint: new string[] {"foo", "bar"}</param>
        public void Subscribe(JID to, string nickname, string[] groups)
        {
            Debug.Assert(to != null);

            RosterIQ riq = new RosterIQ(Document) {Type = IQType.Set};
            Roster r = riq.Instruction;
            Item i = r.AddItem();
            i.JID = to;
            if (nickname != null)
                i.Nickname = nickname;
            if (groups != null)
            {
                foreach (string g in groups)
                    i.AddGroup(g);
            }
            Write(riq); // don't care about result.  we should get a iq/response and a roster push.

            Presence pres = new Presence(Document) {To = to, Type = PresenceType.subscribe};
            Write(pres);
        }
Пример #11
0
        /// <summary>
        /// Removes a contact from the roster.
        /// This will also remove the subscription for that contact being removed.
        /// </summary>
        /// <param name="to">The JID to remove</param>
        public void RemoveRosterItem(JID to)
        {
            Debug.Assert(to != null);

            /*
            <iq from='[email protected]/balcony' type='set' id='roster_4'>
              <query xmlns='jabber:iq:roster'>
            <item jid='*****@*****.**' subscription='remove'/>
              </query>
            </iq>
             */
            RosterIQ riq = new RosterIQ(Document) {Type = IQType.Set};
            Roster r = riq.Instruction;
            Item i = r.AddItem();
            i.JID = to;
            i.Subscription = Subscription.remove;
            Write(riq); // don't care about result.  we should get a iq/response and a roster push.
        }
Пример #12
0
 /// <summary>
 /// Requests a new copy of the roster.
 /// </summary>
 public void GetRoster()
 {
     if (IsAuthenticated)
     {
         RosterIQ riq = new RosterIQ(Document) {Type = IQType.Get};
         Write(riq);
     }
     else
     {
         throw new InvalidOperationException("Client must be authenticated before getting roster.");
     }
 }
Пример #13
0
        /// <summary>
        /// Requests a new copy of the roster.
        /// </summary>
        public void GetRoster()
        {
            if (IsAuthenticated)
            {
                if (this.SupportNestedGroups && String.IsNullOrEmpty(this.NestedGroupDelimiter))
                {
                    PrivateIQ privIq = new PrivateIQ(this.Document);

                    RosterDelimiter rosterDelim = new RosterDelimiter(privIq.OwnerDocument);
                    privIq.Instruction.AddChild(rosterDelim);

                    this.Write(privIq);
                }
                else
                {
                    RosterIQ riq = new RosterIQ(this.Document);
                    riq.Type = IQType.get;

                    this.Write(riq);
                }
            }
            else
            {
                throw new InvalidOperationException("Client must be authenticated before getting roster.");
            }
        }
Пример #14
0
        public void Add(JID jid)
        {
            Item item = this[jid];
            // only create a new roster item if it does not already exist
            if (item == null) {
                RosterIQ iq = new RosterIQ(m_stream.Document);
                iq.Type = IQType.set;
                Roster r = iq.Instruction;
                item = r.AddItem();
                item.JID = jid;
                Write(iq);
            }

            // subscribe to presence
            Presence sub = new Presence(m_stream.Document);
            sub.To = jid;
            sub.Type = PresenceType.subscribe;
            Write(sub);
        }
Пример #15
0
 /// <summary>
 /// Modifies the roster item to look like the given roster item.
 /// This does not modify the model,
 /// but waits for roster pushes from the XMPP server.
 /// </summary>
 /// <param name="item">Roster item that will appear in the roster.</param>
 public void Modify(Item item)
 {
     RosterIQ iq = new RosterIQ(m_stream.Document);
     iq.Type = IQType.set;
     Roster r = iq.Instruction;
     r.AppendChild(item);
     m_stream.Write(iq);  // ignore response
 }
Пример #16
0
        /// <summary>
        /// Remove a contact from the roster
        /// </summary>
        /// <param name="jid">Typically just a user@host JID</param>
        public void Remove(JID jid)
        {
/*
C: <iq from='[email protected]/balcony' type='set' id='delete_1'>
     <query xmlns='jabber:iq:roster'>
       <item jid='*****@*****.**' subscription='remove'/>
     </query>
   </iq>
 */
            RosterIQ iq = new RosterIQ(m_stream.Document);
            iq.Type = IQType.set;
            Roster r = iq.Instruction;
            Item item = r.AddItem();
            item.JID = jid;
            item.Subscription = Subscription.remove;
            m_stream.Write(iq);  // ignore response
        }
Пример #17
0
        protected override void OnAfterLabelEdit(NodeLabelEditEventArgs e)
        {
            base.OnAfterLabelEdit(e);

            if (e.Node.GetType() == typeof(ItemNode) &&
                e.Label != null && e.Label != e.Node.Text)
            {
                ItemNode itemNode = e.Node as ItemNode;

                if (e.Label == itemNode.Item.JID.User)
                    itemNode.Item.Nickname = null;
                else
                    itemNode.Item.Nickname = e.Label;

                RosterIQ riq = new RosterIQ(this.m_client.Document);
                riq.Type = IQType.set;
                riq.Instruction.AddChild(itemNode.Item);

                this.m_client.Write(riq);
            }
        }