예제 #1
0
        /// <summary>
        ///   Adds the given contact to the roster
        /// </summary>
        /// <param name = "jid">Contact JID</param>
        /// <param name = "name">Contact name</param>
        public XmppRoster AddContact(string jid, string name)
        {
            var query = new RosterQuery();
            var iq    = new IQ();

            iq.ID   = XmppIdentifierGenerator.Generate();
            iq.Type = IQType.Set;
            iq.From = connection.UserId;

            var item = new RosterItem();

            item.Subscription = RosterSubscriptionType.None;
            item.Jid          = jid;
            item.Name         = name;

            query.Items.Add(item);

            iq.Items.Add(query);

            pendingMessages.Add(iq.ID);

            connection.Send(iq);

            return(this);
        }
예제 #2
0
        /// <summary>
        ///   Request Roster list to the XMPP Server
        /// </summary>
        public XmppRoster RequestRosterList()
        {
            var query = new RosterQuery();
            var iq    = new IQ();

            iq.ID   = XmppIdentifierGenerator.Generate();
            iq.Type = IQType.Get;
            iq.From = connection.UserId;

            iq.Items.Add(query);

            connection.Send(iq);

            return(this);
        }
예제 #3
0
        private void OnRosterNotification(RosterQuery message)
        {
            // It's a roster management related message
            foreach (RosterItem item in message.Items)
            {
                XmppContact contact = this.Where(c => c.ContactId.BareIdentifier == item.Jid).FirstOrDefault();

                if (contact == null)
                {
                    // Create the new contact
                    var newContact = new XmppContact
                                     (
                        session,
                        item.Jid,
                        item.Name,
                        (XmppContactSubscriptionType)item.Subscription,
                        item.Groups
                                     );

                    // Add the contact to the roster
                    contacts.Add(newContact);
                }
                else
                {
                    switch (item.Subscription)
                    {
                    case RosterSubscriptionType.Remove:
                        contacts.Remove(contact);
                        break;

                    default:
                        // Update contact data
                        contact.RefreshData
                        (
                            item.Name,
                            (XmppContactSubscriptionType)item.Subscription,
                            item.Groups
                        );
                        break;
                    }
                }
            }

            if (RosterReceived != null)
            {
                RosterReceived(this, new EventArgs());
            }
        }
예제 #4
0
        /// <summary>
        ///   Updates the contact data.
        /// </summary>
        public void Update()
        {
            var iq    = new IQ();
            var query = new RosterQuery();
            var item  = new RosterItem();

            iq.Type = IQType.Set;

            item.Jid          = ContactId.BareIdentifier;
            item.Name         = DisplayName;
            item.Subscription = (RosterSubscriptionType)Subscription;

            item.Groups.AddRange(Groups);

            query.Items.Add(item);
            iq.Items.Add(query);

            session.Send(iq);
        }
예제 #5
0
        /// <summary>
        ///   Deletes a user from the roster list
        /// </summary>
        public XmppRoster RemoveContact(XmppJid jid)
        {
            var query = new RosterQuery();
            var iq    = new IQ();

            iq.ID   = XmppIdentifierGenerator.Generate();
            iq.Type = IQType.Set;
            iq.From = connection.UserId;

            var item = new RosterItem();

            item.Jid          = jid.BareIdentifier;
            item.Subscription = RosterSubscriptionType.Remove;

            query.Items.Add(item);

            iq.Items.Add(query);

            pendingMessages.Add(iq.ID);

            connection.Send(iq);

            return(this);
        }
예제 #6
0
        /// <summary>
        ///   Adds to group.
        /// </summary>
        /// <param name = "groupName">Name of the group.</param>
        public void AddToGroup(string groupName)
        {
            var iq    = new IQ();
            var query = new RosterQuery();
            var item  = new RosterItem();

            if (!Groups.Contains(groupName))
            {
                Groups.Add(groupName);
            }

            iq.Type = IQType.Set;

            item.Jid          = ContactId.BareIdentifier;
            item.Name         = Name;
            item.Subscription = (RosterSubscriptionType)Subscription;

            item.Groups.Add(groupName);

            query.Items.Add(item);
            iq.Items.Add(query);

            session.Send(iq);
        }
예제 #7
0
        /// <summary>
        ///   Updates the contact data.
        /// </summary>
        public void Update()
        {
            var iq = new IQ();
            var query = new RosterQuery();
            var item = new RosterItem();

            iq.Type = IQType.Set;

            item.Jid = ContactId.BareIdentifier;
            item.Name = DisplayName;
            item.Subscription = (RosterSubscriptionType)Subscription;

            item.Groups.AddRange(Groups);

            query.Items.Add(item);
            iq.Items.Add(query);

            session.Send(iq);
        }
예제 #8
0
        /// <summary>
        ///   Adds to group.
        /// </summary>
        /// <param name = "groupName">Name of the group.</param>
        public void AddToGroup(string groupName)
        {
            var iq = new IQ();
            var query = new RosterQuery();
            var item = new RosterItem();

            if (!Groups.Contains(groupName))
            {
                Groups.Add(groupName);
            }

            iq.Type = IQType.Set;

            item.Jid = ContactId.BareIdentifier;
            item.Name = Name;
            item.Subscription = (RosterSubscriptionType)Subscription;

            item.Groups.Add(groupName);

            query.Items.Add(item);
            iq.Items.Add(query);

            session.Send(iq);
        }