private void ProcessRosterIq(Iq iq) { if (iq.Type == IqType.Get) { // Send the roster // we send a dummy roster here, you should retrieve it from a // database or some kind of directory (LDAP, AD etc...) iq.SwitchDirection(); iq.Type = IqType.Result; for (int i = 1; i < 11; i++) { // don't add yourself to the contact list (aka roster) if (Jid.User.EndsWith(i.ToString())) { continue; } var ri = new RosterItem { Jid = new Jid("user" + i + "@" + XmppDomain), Name = "User " + i, Subscription = Subscription.Both }; ri.AddGroup("Group 1"); iq.Query.Add(ri); } Send(iq); } else if (iq.Type == IqType.Set) { // TODO, handle roster add, remove and update here. } }
private void ProcessRosterIQ(IQ iq) { if (iq.Type == IqType.get) { // Send the roster // we send a dummy roster here, you should retrieve it from a // database or some kind of directory (LDAP, AD etc...) iq.SwitchDirection(); iq.Type = IqType.result; for (int i = 1; i < 11; i++) { RosterItem ri = new RosterItem(); ri.Name = "Item " + i.ToString(); ri.Subscription = SubscriptionType.both; ri.Jid = new Jid("item" + i.ToString() + "@localhost"); ri.AddGroup("localhost"); iq.Query.AddChild(ri); } for (int i = 1; i < 11; i++) { RosterItem ri = new RosterItem(); ri.Name = "Item JO " + i.ToString(); ri.Subscription = SubscriptionType.both; ri.Jid = new Jid("item" + i.ToString() + "@jabber.org"); ri.AddGroup("JO"); iq.Query.AddChild(ri); } Send(iq); } }
/// <summary> /// Builds a request to add a contact to the contact list, aka roster /// </summary> /// <param name="jid">The <see cref="Jid"/> to add to the contact list</param> /// <param name="nickname">Optional nickname for this contact</param> /// <param name="groups">Option list of groups this contact should belong to</param> /// <returns><see cref="RosterIq"/> stanza</returns> public static RosterIq AddRosterItem(Jid jid, string nickname = null, string[] groups = null) { var riq = new RosterIq { Type = IqType.Set }; var ri = new RosterItem { Jid = jid }; if (!String.IsNullOrEmpty(nickname)) { ri.Name = nickname; } if (groups != null) { foreach (string g in groups) { ri.AddGroup(g); } } riq.Roster.AddRosterItem(ri); return(riq); }
private void ProcessRosterIQ(IQ iq) { if (iq.Type == IqType.get) { iq.SwitchDirection(); iq.Type = IqType.result; for (int i = 1; i < 11; i++) { RosterItem ri = new RosterItem(); ri.Name = "Item " + i.ToString(); ri.Subscription = SubscriptionType.both; ri.Jid = new Jid("item" + i.ToString() + "@localhost"); ri.AddGroup("localhost"); iq.Query.AddChild(ri); } for (int i = 1; i < 11; i++) { RosterItem ri = new RosterItem(); ri.Name = "Item JO " + i.ToString(); ri.Subscription = SubscriptionType.both; ri.Jid = new Jid("item" + i.ToString() + "@jabber.org"); ri.AddGroup("JO"); iq.Query.AddChild(ri); } Send(iq); } }
public static void ProcessRosterIQGet(string username, IQ iq) { iq.Type = IqType.result; iq.Query = new Roster(); BLL.Users api = new BLL.Users(); List <DAL.VwFriend> FList = api.ListFriend(username); for (int i = 0; i < FList.Count; i++) { RosterItem ri = new RosterItem(); ri.Name = FList[i].VcardFirstName + " " + FList[i].VcardLastName; ri.Subscription = (FList[i].FriendStatus == 1) ? SubscriptionType.from : SubscriptionType.both; ri.Jid = new agsXMPP.Jid(FList[i].FriendUserName + "@" + Config.AppSetting.domain); if (!string.IsNullOrEmpty(FList[i].GroupName)) { ri.AddGroup(FList[i].GroupName); } iq.Query.AddChild(ri); } int index; if (ThreadTools.Users.Online.IsAuthenticated(username, out index)) { ThreadTools.Users.Online[index].Send(iq); ThreadTools.Users.Online[index].Send(Rosters.FriendStatus(username)); ThreadTools.Users.Online[index].Send(Messages.OfflineMessage(username)); ThreadTools.Users.Online[index].Send(Rosters.PendingStatus(iq.From.User)); } }
public void TestGroups() { RosterItem ri2 = XmppXElement.LoadXml(Resource.Get("Xmpp.Roster.item1.xml")).Cast <RosterItem>(); RosterItem ri3 = XmppXElement.LoadXml(Resource.Get("Xmpp.Roster.item2.xml")).Cast <RosterItem>(); Assert.Equal(3, ri2.GetGroups().Count); Assert.Equal(0, ri3.GetGroups().Count); ri3.AddGroup("Test"); Assert.Equal(1, ri3.GetGroups().Count); Assert.Equal("Test", ri3.GetGroups()[0]); }
private void ProcessRosterIq(Iq iq) { if (iq.Type == IqType.Get) { // Send the roster // we send a dummy roster here, you should retrieve it from a // database or some kind of directory (LDAP, AD etc...) iq.SwitchDirection(); iq.Type = IqType.Result; String[] contact = new string[3]; contact[0] = "krishna"; contact[1] = "madu"; contact[2] = "madu2"; for (int i = 0; i < contact.Length; i++) { // don't add yourself to the contact list (aka roster) if (contact[i].Equals(Jid.User)) { continue; } var ri = new RosterItem { Jid = new Jid(contact[i] + "@" + XmppDomain), Name = contact[i], Subscription = Subscription.Both }; ri.AddGroup("Group 1"); iq.Query.Add(ri); } Send(iq); } else if (iq.Type == IqType.Set) { // TODO, handle roster add, remove and update here. } }
/// <summary> /// Add a Rosteritem to the Roster /// </summary> /// <param name="jid">The BARE jid of the rosteritem that should be removed</param> /// <param name="nickname">Nickname for the RosterItem</param> /// <param name="group">An Array of groups when you want to add the Rosteritem to multiple groups</param> public void AddRosterItem(Jid jid, string nickname, string[] group) { RosterIq riq = new RosterIq(); riq.Type = IqType.set; RosterItem ri = new RosterItem(); ri.Jid = jid; if (nickname != null) { ri.Name = nickname; } foreach (string g in group) { ri.AddGroup(g); } riq.Query.AddRosterItem(ri); m_connection.Send(riq); }
/// <summary> /// Add a Rosteritem to the Roster /// </summary> /// <param name="jid">The BARE jid of the rosteritem that should be removed</param> /// <param name="nickname">Nickname for the RosterItem</param> /// <param name="group">An Array of groups when you want to add the Rosteritem to multiple groups</param> public void AddRosterItem(Jid jid, string nickname, string[] group) { RosterIq riq = new RosterIq(); riq.Type = IqType.set; RosterItem ri = new RosterItem(); ri.Jid = jid; if (nickname != null) ri.Name = nickname; foreach (string g in group) { ri.AddGroup(g); } riq.Query.AddRosterItem(ri); m_connection.Send(riq); }