Commit 6664a73a authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added support for enabling/disabling the service. JM-676

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4064 b35dd754-fafc-0310-a699-88a17e54d16e
parent faea1b0b
......@@ -291,4 +291,20 @@ public interface MultiUserChatServer extends Component {
* @param numOccupants number of occupants that received the message.
*/
void messageBroadcastedTo(int numOccupants);
/**
* Enables or disables the MUC service. When disabled the MUC service will disappear from
* the disco#items list. Moreover, service discovery features will be disabled.
*
* @param enabled true if the service is enabled.
*/
void enableService(boolean enabled);
/**
* Returns true if the MUC service is available. Use {@link #enableService(boolean)} to
* enable or disable the service.
*
* @return true if the MUC service is available.
*/
boolean isServiceEnabled();
}
\ No newline at end of file
......@@ -831,6 +831,31 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
}
public void enableService(boolean enabled) {
if (isServiceEnabled() == enabled) {
// Do nothing if the service status has not changed
return;
}
XMPPServer server = XMPPServer.getInstance();
if (!enabled) {
// Disable disco information
server.getIQDiscoItemsHandler().removeServerItemsProvider(this);
// Stop the service/module
stop();
}
JiveGlobals.setProperty("xmpp.muc.enabled", Boolean.toString(enabled));
if (enabled) {
// Start the service/module
start();
// Enable disco information
server.getIQDiscoItemsHandler().addServerItemsProvider(this);
}
}
public boolean isServiceEnabled() {
return JiveGlobals.getBooleanProperty("xmpp.muc.enabled", true);
}
public long getTotalChatTime() {
return totalChatTime;
}
......@@ -886,8 +911,11 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
}
public Iterator<DiscoServerItem> getItems() {
// Check if the service is disabled. Info is not available when disabled.
if (!isServiceEnabled()) {
return null;
}
ArrayList<DiscoServerItem> items = new ArrayList<DiscoServerItem>();
items.add(new DiscoServerItem() {
public String getJID() {
return getServiceDomain();
......@@ -1053,6 +1081,10 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
}
public boolean hasInfo(String name, String node, JID senderJID) {
// Check if the service is disabled. Info is not available when disabled.
if (!isServiceEnabled()) {
return false;
}
if (name == null && node == null) {
// We always have info about the MUC service
return true;
......@@ -1069,6 +1101,10 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
}
public Iterator<Element> getItems(String name, String node, JID senderJID) {
// Check if the service is disabled. Info is not available when disabled.
if (!isServiceEnabled()) {
return null;
}
List<Element> answer = new ArrayList<Element>();
if (name == null && node == null) {
Element item;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment