use of org.jivesoftware.openfire.privacy.PrivacyList in project Openfire by igniterealtime.
the class IQPrivacyHandler method setDefaultList.
/**
* User has specified a new default list that should be used for all session.
*
* @param packet IQ packet setting new default list for all sessions.
* @param from sender of the IQ packet.
* @param listName name of the new default list for all sessions.
* @return acknowledge of success.
*/
private IQ setDefaultList(IQ packet, JID from, String listName) {
IQ result = IQ.createResultIQ(packet);
Element childElement = packet.getChildElement().createCopy();
result.setChildElement(childElement);
if (sessionManager.getSessionCount(from.getNode()) > 1) {
// Current default list is being used by more than one session
result.setError(PacketError.Condition.conflict);
} else {
// Get the list
PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
if (list != null) {
// Get the user session
ClientSession session = sessionManager.getSession(from);
PrivacyList oldDefaultList = session.getDefaultList();
manager.changeDefaultList(from.getNode(), list, oldDefaultList);
// Set the new default list for this session (the only existing session)
session.setDefaultList(list);
} else {
// List not found
result.setError(PacketError.Condition.item_not_found);
}
}
return result;
}
use of org.jivesoftware.openfire.privacy.PrivacyList in project Openfire by igniterealtime.
the class IQPrivacyHandler method setActiveList.
/**
* User has specified a new active list that should be used for the current session.
*
* @param packet IQ packet setting new active list for the current session.
* @param from sender of the IQ packet.
* @param listName name of the new active list for the current session.
* @return acknowledge of success.
*/
private IQ setActiveList(IQ packet, JID from, String listName) {
IQ result = IQ.createResultIQ(packet);
Element childElement = packet.getChildElement().createCopy();
result.setChildElement(childElement);
// Get the list
PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
if (list != null) {
// Get the user session
ClientSession session = sessionManager.getSession(from);
if (session != null) {
// Set the new active list for this session
session.setActiveList(list);
}
} else {
// List not found
result.setError(PacketError.Condition.item_not_found);
}
return result;
}
use of org.jivesoftware.openfire.privacy.PrivacyList in project Openfire by igniterealtime.
the class IQPrivacyHandler method updateOrCreateList.
/**
* Updates an existing privacy list or creates a new one with the specified items list. The
* new list will not become the active or default list by default. The user will have to
* send another packet to set the new list as active or default.<p>
*
* Once the list was updated or created a "privacy list push" will be sent to all
* connected resources of the user.
*
* @param packet IQ packet updating or creating a new privacy list.
* @param from sender of the IQ packet.
* @param listElement the element containing the list and its items.
* @return acknowledge of success.
*/
private IQ updateOrCreateList(IQ packet, JID from, Element listElement) {
IQ result = IQ.createResultIQ(packet);
Element childElement = packet.getChildElement().createCopy();
result.setChildElement(childElement);
String listName = listElement.attributeValue("name");
PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
if (list == null) {
list = manager.createPrivacyList(from.getNode(), listName, listElement);
} else {
// Update existing list
list.updateList(listElement);
provider.updatePrivacyList(from.getNode(), list);
// avoided this issue since identity is ensured.
for (ClientSession session : sessionManager.getSessions(from.getNode())) {
if (list.equals(session.getDefaultList())) {
session.setDefaultList(list);
}
if (list.equals(session.getActiveList())) {
session.setActiveList(list);
}
}
}
// Send a "privacy list push" to all connected resources
IQ pushPacket = new IQ(IQ.Type.set);
Element child = pushPacket.setChildElement("query", "jabber:iq:privacy");
child.addElement("list").addAttribute("name", list.getName());
sessionManager.userBroadcast(from.getNode(), pushPacket);
return result;
}
Aggregations