1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-23 06:42:05 +01:00

Adds reserved room nickname discovery and sets on every connection that this client supports MUC

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2304 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2004-05-03 00:47:30 +00:00 committed by gdombiak
parent 13f15c5e4b
commit 8e6941e95d

View file

@ -86,6 +86,19 @@ public class MultiUserChat {
private PacketListener declinesListener; private PacketListener declinesListener;
private PacketCollector messageCollector; private PacketCollector messageCollector;
// Set on every established connection that this client supports the Multi-User Chat protocol.
// This information will be used when another client tries to discover whether this client
// supports MUC or not.
// Note: The ServiceDiscoveryManager class should have been already initialized
static {
XMPPConnection.addConnectionListener(new ConnectionEstablishedListener() {
public void connectionEstablished(XMPPConnection connection) {
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(
"http://jabber.org/protocol/muc");
}
});
}
/** /**
* Creates a new multi user chat with the specified connection and room name. Note: no * Creates a new multi user chat with the specified connection and room name. Note: no
* information is sent to or received from the server until you attempt to * information is sent to or received from the server until you attempt to
@ -689,6 +702,36 @@ public class MultiUserChat {
} }
} }
/**
* Returns the reserved room nickname for the user in the room. A user may have a reserved
* nickname, for example through explicit room registration or database integration. In such
* cases it may be desirable for the user to discover the reserved nickname before attempting
* to enter the room.
*
* @return the reserved room nickname or <tt>null</tt> if none.
*/
public String getReservedNickname() {
try {
DiscoverInfo result =
ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(
room,
"x-roomuser-item");
// Look for the Identity whose category is "client" and return its name
for (Iterator identities = result.getIdentities(); identities.hasNext();) {
DiscoverInfo.Identity identity = (DiscoverInfo.Identity) identities.next();
if ("client".equals(identity.getCategory())) {
return identity.getName();
}
}
// If no Identity was found then the user does not have a reserved room nickname
return null;
}
catch (XMPPException e) {
e.printStackTrace();
return null;
}
}
/** /**
* Returns the nickname that was used to join the room, or <tt>null</tt> if not * Returns the nickname that was used to join the room, or <tt>null</tt> if not
* currently joined. * currently joined.