Add a core thread that periodically saves the configuration.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ajax / FollowSoneAjaxPage.java
index 6d98b43..d82ab1d 100644 (file)
@@ -35,7 +35,7 @@ public class FollowSoneAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public FollowSoneAjaxPage(WebInterface webInterface) {
-               super("ajax/followSone.ajax", webInterface);
+               super("followSone.ajax", webInterface);
        }
 
        /**
@@ -45,15 +45,15 @@ public class FollowSoneAjaxPage extends JsonPage {
        protected JsonObject createJsonObject(Request request) {
                String soneId = request.getHttpRequest().getParam("sone");
                if (!webInterface.getCore().hasSone(soneId)) {
-                       return new JsonObject().put("success", false).put("error", "invalid-sone-id");
+                       return createErrorJsonObject("invalid-sone-id");
                }
                Sone currentSone = getCurrentSone(request.getToadletContext());
                if (currentSone == null) {
-                       return new JsonObject().put("success", false).put("error", "auth-required");
+                       return createErrorJsonObject("auth-required");
                }
                currentSone.addFriend(soneId);
-               webInterface.getCore().saveSone(currentSone);
-               return new JsonObject().put("success", true);
+               webInterface.getCore().touchConfiguration();
+               return createSuccessJsonObject();
        }
 
 }