Categories
General

Smack API: No clean way to discover if a multi-user chat room exists

Here’s another one to follow the previous two posts about Smack API and Multi-User Chat issues.
Suppose you want to create a persistent room. Suppose you are not sure if that room already exists. In Smack, and I am not familiar of any other APIs, there is no non-exception-throwing way of doing this.

Fundamentally, a room already exists is the situation where a room is already set up on the server with the same name as the one you wish to create.

The MultiUserChat object has a static getRoomInfo() method which may have been the way to go. If the room does not exist, return null. Instead, if the room does not exist throws an XMPPException. Not sure what the error situation is here – I am just trying to find out if a room exists or not, but that causes an exception.

The flipside is on the creation end. If you try to create a room that already exists, an XMPPException will be thrown. This makes sense and is recoverable. Still, I am a fan of checking first instead of trying to do something only to encounter a bad situation. Not a biggie – just hope this spares someone the exploration and time. Not really documented, etc.

Share
Share