Subject: Creating new user, updating VCard and adding that user to a group
A while ago I made a topic about the OnRosterItem not being fired. You said that the problem is probably in the OpenFire pluging that we use. So yesterday/today I started making something that uses the MatriX SDK to add new users, but I'm having some problems with it.
I used the tutorial as an example. The user gets added to OpenFire properly, but when I try to update the VCard and add the user to a group, nothing happens. I don't get any error, but the VCard and group don't get updated either.
Here's the code I made:
As you can see, I wait untill the OnRosterEnd event to update the VCard and group. I tried doing that in the "OnRegister" at first, but it seems that's too early, because I was getting "not-authorized" errors. I put my xml logs on pastebin again so that this post does not too messy.
I used the tutorial as an example. The user gets added to OpenFire properly, but when I try to update the VCard and add the user to a group, nothing happens. I don't get any error, but the VCard and group don't get updated either.
Here's the code I made:
- public void AddUserToChat(string userName, string password)
- {
- var client = new XmppClient();
- client.OnRegisterError += (sender, args) =>
- {
- logger.Error("Failed to register user in chat: " + args.Iq);
- client.Close();
- };
- client.OnRegisterInformation += (sender, args) =>
- {
- args.Register.RemoveAll<Data>();
- args.Register.Username = client.Username;
- args.Register.Password = client.Password;
- };
- client.OnSendXml += (sender, args) => logger.Debug("ONSENDXML: " + args.Text);
- client.OnReceiveXml += (sender, args) => logger.Debug("ONRECEIVEXML:" + args.Text);
- client.OnRosterEnd += (sender, args) =>
- {
- var jid = client.Username + "@" + client.XmppDomain;
- var viq = new VcardIq
- {
- Type = IqType.set,
- Vcard = new Vcard
- {
- Fullname = "Deze naam staat hardcoded"
- }
- };
- client.Send(viq);
- var rosterManager = new RosterManager(client);
- rosterManager.Add(jid, client.Username, chatGroup, this.AddedToRoster);
- };
- client.SetXmppDomain(ConfigurationManager.AppSettings["OpenFireLocation"]);
- client.SetUsername(userName);
- client.Password = password;
- client.RegisterNewAccount = true;
- client.Open();
- }
- private void AddedToRoster(object sender, IqEventArgs e)
- {
- }
As you can see, I wait untill the OnRosterEnd event to update the VCard and group. I tried doing that in the "OnRegister" at first, but it seems that's too early, because I was getting "not-authorized" errors. I put my xml logs on pastebin again so that this post does not too messy.