Commit 329b3cb8 authored by Alex Mateescu's avatar Alex Mateescu Committed by alexm

OF-174 Added a couple of bulk user operations.

Adding users that can create MUC rooms updates the same field in the DB, thus adding users one by one is very inefficient. A bulk update is much more desirable.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13329 b35dd754-fafc-0310-a699-88a17e54d16e
parent 16b098b0
......@@ -110,6 +110,12 @@ public interface MultiUserChatService extends Component {
*/
void addUserAllowedToCreate(JID userJID);
/**
* Adds new users to the list of JIDs that are allowed to create MUC rooms.
* @param userJIDs collection of bare JIDs if users to add to list.
*/
void addUsersAllowedToCreate(Collection<JID> userJIDs);
/**
* Removes a user from list of JIDs that are allowed to create MUC rooms.
*
......@@ -117,6 +123,13 @@ public interface MultiUserChatService extends Component {
*/
void removeUserAllowedToCreate(JID userJID);
/**
* Removes users from list of JIDs that are allowed to create MUC rooms.
*
* @param userJIDs collection of bare JIDs of users to remove from the list.
*/
void removeUsersAllowedToCreate(Collection<JID> userJIDs);
/**
* Sets the time to elapse between clearing of idle chat users. A <code>TimerTask</code> will be
* added to a <code>Timer</code> scheduled for repeated fixed-delay execution whose main
......
......@@ -70,8 +70,8 @@ import org.slf4j.LoggerFactory;
import org.xmpp.component.Component;
import org.xmpp.component.ComponentManager;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.forms.DataForm.Type;
import org.xmpp.forms.FormField;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
......@@ -880,40 +880,51 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
MUCPersistenceManager.setProperty(chatServiceName, "create.anyone", Boolean.toString(roomCreationRestricted));
}
public void addUserAllowedToCreate(JID userJID) {
final JID bareJID = new JID(userJID.toBareJID());
public void addUsersAllowedToCreate(Collection<JID> userJIDs) {
boolean listChanged = false;
for(JID userJID: userJIDs) {
// Update the list of allowed JIDs to create MUC rooms. Since we are updating the instance
// variable there is no need to restart the service
listChanged |= allowedToCreate.add(userJID);
}
allowedToCreate.add(bareJID);
// if nothing was added, there's nothing to update
if(listChanged) {
// CopyOnWriteArray does not allow sorting, so do sorting in temp list.
ArrayList<JID> tempList = new ArrayList<JID>(allowedToCreate);
List<JID> tempList = new ArrayList<JID>(allowedToCreate);
Collections.sort(tempList);
allowedToCreate = new CopyOnWriteArrayList<JID>(tempList);
// Update the config.
String[] jids = new String[allowedToCreate.size()];
for (int i = 0; i < jids.length; i++) {
jids[i] = allowedToCreate.get(i).toBareJID();
MUCPersistenceManager.setProperty(chatServiceName, "create.jid", fromCollection(allowedToCreate));
}
MUCPersistenceManager.setProperty(chatServiceName, "create.jid", fromArray(jids));
}
public void removeUserAllowedToCreate(JID userJID) {
final JID bareJID = new JID(userJID.toBareJID());
public void addUserAllowedToCreate(JID userJID) {
List<JID> asList = new ArrayList<JID>();
asList.add(userJID);
addUsersAllowedToCreate(asList);
}
public void removeUsersAllowedToCreate(Collection<JID> userJIDs) {
boolean listChanged = false;
for(JID userJID: userJIDs) {
// Update the list of allowed JIDs to create MUC rooms. Since we are updating the instance
// variable there is no need to restart the service
allowedToCreate.remove(bareJID);
listChanged |= allowedToCreate.remove(userJID);
}
// Update the config.
String[] jids = new String[allowedToCreate.size()];
for (int i = 0; i < jids.length; i++) {
jids[i] = allowedToCreate.get(i).toBareJID();
// if none of the JIDs were on the list, there's nothing to update
if(listChanged) {
MUCPersistenceManager.setProperty(chatServiceName, "create.jid", fromCollection(allowedToCreate));
}
MUCPersistenceManager.setProperty(chatServiceName, "create.jid", fromArray(jids));
}
public void removeUserAllowedToCreate(JID userJID) {
List<JID> asList = new ArrayList<JID>();
asList.add(userJID);
removeUsersAllowedToCreate(asList);
}
public void initialize(XMPPServer server) {
......@@ -1248,7 +1259,9 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
features.add("http://jabber.org/protocol/disco#items");
features.add("jabber:iq:search");
features.add(ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT);
if (!extraDiscoFeatures.isEmpty()) features.addAll(extraDiscoFeatures);
if (!extraDiscoFeatures.isEmpty()) {
features.addAll(extraDiscoFeatures);
}
}
else if (name != null && node == null) {
// Answer the features of a given room
......@@ -1456,10 +1469,10 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
}
/**
* Converts an array to a comma-delimitted String.
* Converts an array to a comma-delimited String.
*
* @param array the array.
* @return a comma delimtted String of the array values.
* @return a comma delimited String of the array values.
*/
private static String fromArray(String [] array) {
StringBuilder buf = new StringBuilder();
......@@ -1472,6 +1485,21 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
return buf.toString();
}
/**
* Converts a collection to a comma-delimited String.
*
* @param coll the collection.
* @return a comma delimited String of the array values.
*/
private static String fromCollection(Collection<JID> coll) {
StringBuilder buf = new StringBuilder();
for (JID elem: coll) {
buf.append(elem.toBareJID()).append(",");
}
int endPos = buf.length() > 1 ? buf.length() - 1 : 0;
return buf.substring(0, endPos);
}
public boolean isHidden() {
return isHidden;
}
......
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