List<Element> undoElement = undoSnapshots.pollLast();
String deleteList = "";
JSONArray changeList = new JSONArray();
IWebSocketConnectionRegistry reg = WebSocketSettings.Holder.get(Application.get()).getConnectionRegistry();
for (int i = 0; i < undoElement.size(); i++) {
if (undoCreationList.get(i)) {
elementMap.remove(undoElement.get(i).getId());
if (loadedElementMap.containsKey(undoElement.get(i).getId())) {
loadedContent = "";
whiteboardMap.get(whiteboardObjectId).setLoadedContent("");
loadedElementMap.remove(undoElement.get(i).getId());
}
if ("".equals(deleteList)) {
deleteList = "" + undoElement.get(i).getId();
} else {
deleteList += "," + undoElement.get(i).getId();
}
} else {
elementMap.put(undoElement.get(i).getId(), undoElement.get(i));
try {
changeList.put(undoElement.get(i).getJSON());
} catch (JSONException e) {
log.error("Unexpected error while getting JSON", e);
}
}
}
for (IWebSocketConnection c : reg.getConnections(Application.get())) {
try {
c.sendMessage(getUndoMessage(changeList, deleteList).toString());
} catch (Exception e) {
log.error("Unexpected error while sending message through the web socket", e);
}
}
} else {
Background previousBackground = undoSnapshots_Background.pollLast();
background = previousBackground;
whiteboardMap.get(whiteboardObjectId).setBackground(previousBackground);
IWebSocketConnectionRegistry reg = WebSocketSettings.Holder.get(Application.get()).getConnectionRegistry();
for (IWebSocketConnection c : reg.getConnections(Application.get())) {
try {
if (previousBackground != null) {
c.sendMessage(getAddBackgroundMessage(previousBackground.getJSON()).toString());
} else {
c.sendMessage(getAddBackgroundMessage(new JSONObject()).toString());