ClientSession currentSession;
IQ result = IQ.createResultIQ(packet);
Element childElement = packet.getChildElement().createCopy();
result.setChildElement(childElement);
// Get the list to delete
PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
if (list == null) {
// List to delete was not found
result.setError(PacketError.Condition.item_not_found);
return result;
}
else {
currentSession = sessionManager.getSession(from);
// Check if the list is being used by another session
for (ClientSession session : sessionManager.getSessions(from.getNode())) {
if (currentSession == session) {
// Ignore the active session for this checking
continue;
}
if (list.equals(session.getDefaultList()) || list.equals(session.getActiveList())) {
// List to delete is being used by another session so return a conflict error
result.setError(PacketError.Condition.conflict);
return result;
}
}
}
// Remove the list from the active session (if it was being used)
if (list.equals(currentSession.getDefaultList())) {
currentSession.setDefaultList(null);
}
if (list.equals(currentSession.getActiveList())) {
currentSession.setActiveList(null);
}
manager.deletePrivacyList(from.getNode(), listName);
return result;
}