Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
Eric380 #1
Member since Jun 2012 · 10 posts
Group memberships: Members, Premium
Show profile · Link to this post
Subject: MucManager OnInvite XmppXElement
I can't find the invite XmppXElement.  How can I retrieve the values I need from the invite (from, reason, and password).  This is what I expected to do:

  1. void OnInvitedToChatRoom(object sender, MessageEventArgs e)
  2. {
  3.       var invite = e.Message.Element<Invite>();
  4. }

Here is the expected message:
  1. <message from='coven@chat.shakespeare.lit' id='nzd143v8' to='hecate@shakespeare.lit'>
  2.    <x xmlns='http://jabber.org/protocol/muc#user'>
  3.       <invite from='crone1@shakespeare.lit/desktop'>
  4.          <reason>Hey Hecate, this is the place for all good witches!</reason>
  5.       </invite>
  6.       <password>cauldronburn</password>
  7.    </x>
  8. </message>
This post was edited on 2012-06-10, 10:40 by Alex.
Edit reason: added code formatting
Avatar
Alex #2
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Element<T>() looks only for the direct childnodes. <invite/> is a grand children of message.

Here is an example of one of our unit Tests which is exactly doing what you want:

  1. var msg = xmpp1 as Message;
  2. var xMuc = msg.Element<Matrix.Xmpp.Muc.User.X>();
  3. Assert.AreEqual(xMuc.Password, "cauldronburn");
  4.  
  5. var invite = xMuc.GetInvites().First();
  6. Assert.AreEqual(invite.Reason, "FOO");

We can add a Element<T, bool traverseWholeTree) function to one of the next releases when this is helpful.

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: MatriX RSS