/// <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); }
/// <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); }
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()); } }
/// <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); }
/// <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); }
/// <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); }