Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
Lightbarrier #1
Member since Jul 2014 · 52 posts
Group memberships: Members
Show profile · Link to this post
Subject: Check if Chat Room Exists
Hi again Alex,

I realize that the following code below joins a chat room, and if it doesn't exist creates it however, I was wondering if there was a way to check if the room already exists, that way you'll know if your joining a room, or creating one. I apologize if there's a solution to this which I haven't come across. Thanks!

  1. TheMucManager.EnterRoom(roomJid, usersNickName);
This post was edited on 2014-07-29, 20:06 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
This is how MUC is designed in XMPP. If the room does not exist it gets created automatically.

You can you ServiceDiscoveryDisco and send a discover items request to your MUC server (DiscoManager.DiscoverItems). This will return all existing rooms.

Alex
Avatar
Lightbarrier #3
Member since Jul 2014 · 52 posts
Group memberships: Members
Show profile · Link to this post
Subject: Example of Syntax
Could you give me a example of what your thinking?

Currently I've found something like below, where you pass in the group chat Jid, and try to get the status of wither it exists from the discomanager however, I'm not sure if this is what you had in mind as I'm just checking the status of one(even though that's what I wanted), I'm also slightly suspicious if this is even doing what I think it's doing.

Thanks!

  1. public async void CheckIfGroupExists()
  2. {
  3.        DiscoManager manage = new DiscoManager(xmppConection);
  4.        var list = await manage.DiscoverItemsAsync(groupChatJid);
  5.  
  6.        if(list.Type == IqType.error)
  7.        {
  8.             // Doesn't exist
  9.        }
  10.        else
  11.        {
  12.            // Does exist
  13.        }
  14. }
Avatar
Alex #4
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Yes this will work, and can be a good idea when there are lots of rooms available on the server. Less traffic than retrieving the complete list of available rooms.

The other way is to pass the Jid of the muc server component and get back the complete list of available rooms. An example for that is here in this thread:
http://forum.ag-software.net/thread/1346-retrieve-rooms

Alex
Avatar
Lightbarrier #5
Member since Jul 2014 · 52 posts
Group memberships: Members
Show profile · Link to this post
Subject: Thanks
Thanks works well.
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