Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
mchhetri #1
Member since Feb 2008 · 6 posts · Location: Melbourne, Australia
Group memberships: Members
Show profile · Link to this post
Subject: Getting sender id in a multi user chat room
Hi,

I'm creating a multi user chat room using the following:
            MucManager _mucManager = new MucManager(_connection);
            Jid roomJid = new Jid("Chatroom@xxxxxx.com");
            _mucManager.CreateReservedRoom(roomJid);
            _mucManager.JoinRoom(roomJid, _nickName);
            _mucManager.AcceptDefaultConfiguration(roomJid);

I handle all received messages using the MessageHandler.

But I couldn't find any method to know who the sender of the message is in the multi user chat.

Each message is of type groupchat and but the sender (From) is Chatroom@xxxxxx.com and not the actual sender of the message.

How do I identify who sent a particular message in the multi-user conversation?

Thanks.
Avatar
Alex #2
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you have to look at the full Jid. In MUC the sender nick is in the resource.
So the from of the message is something like:

jdev@conference.jabber.org/Alex
jdev@conference.jabber.org/Bob
jdev@conference.jabber.org/Alice

The real Jid of the sender is not exposed in messages. Depending on the room configuration users with different roles/affiliations are allowed to see the real Jid. The Jid is sent with the participant's presence then like:

  1. <presence
  2.     from='darkcave@macbeth.shakespeare.lit/thirdwitch'
  3.     to='crone1@shakespeare.lit/desktop'>
  4.  <x xmlns='http://jabber.org/protocol/muc#user'>
  5.     <item affiliation='none'
  6.           jid='hag66@shakespeare.lit/pda'
  7.           role='participant'/>
  8.  </x>
  9. </presence>

Alex
Avatar
UnknownAX #3
Member since Oct 2008 · 1 post
Group memberships: Members
Show profile · Link to this post
Hi Alex,

I'm also trying to access the Jid from a Presence in MUC. I know that the server is sending the <item> with jid in it, but I haven't the slightest clue on how to get that Jid out of the Presence.

I'm quite new to XMPP and XML in general, as well, so this is probably a really easy thing to do. :)

Thanks,
UAX

EDIT: I managed to figure it out on my own.

The solution was to use:

pres.SelectSingleElement("x").SelectSingleElement("item").GetAttribute("jid")
This post was edited on 2008-10-09, 12:47 by UnknownAX.
Avatar
Alex #4
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
this works, but is not the best way to do it.

I wrote a small example:

  1. string xml = "<presence xmlns='jabber:client' from='darkcave@macbeth.shakespeare.lit/thirdwitch' to='crone1@shakespeare.lit/desktop'>";
  2. xml += "<x xmlns='http://jabber.org/protocol/muc#user'>";
  3. xml += "<item affiliation='none' jid='hag66@shakespeare.lit/pda' role='participant'/>";
  4. xml += "</x></presence>";
  5.  
  6. Document doc = new Document();
  7. doc.LoadXml(xml);
  8.  
  9. agsXMPP.protocol.x.muc.User user = doc.RootElement.SelectSingleElement<agsXMPP.protocol.x.muc.User>();
  10. Console.WriteLine(user.Item.Jid);

normally only owners and admins of the rooms can see the jid. But this can also depend on the room configuration.

Alex
Avatar
farhad #5
Member since Jun 2014 · 10 posts
Group memberships: Members
Show profile · Link to this post
hello alex

I have a question , thank you for your answer in advance

how should i get the Affiliation of a user when joinig a muc room via OnPresence event?  (i want to know Whether the user is admin or owner or simple participant)
Avatar
Alex #6
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
the presence includes a <x/> tag like this:

  1. <presence>
  2.    <x xmlns='http://jabber.org/protocol/muc#user'>";
  3.       <item affiliation='none' jid='hag66@shakespeare.lit/pda' role='participant'/>
  4.    </x>
  5. </presence>

there you have the affiliation and role. Just get this tag from the presence and check the Role and Affiliation properties.

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: agsXMPP RSS