Add a core thread that periodically saves the configuration.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ajax / UnfollowSoneAjaxPage.java
index e9650aa..7f719b7 100644 (file)
@@ -35,7 +35,7 @@ public class UnfollowSoneAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public UnfollowSoneAjaxPage(WebInterface webInterface) {
-               super("ajax/unfollowSone.ajax", webInterface);
+               super("unfollowSone.ajax", webInterface);
        }
 
        /**
@@ -44,17 +44,16 @@ public class UnfollowSoneAjaxPage extends JsonPage {
        @Override
        protected JsonObject createJsonObject(Request request) {
                String soneId = request.getHttpRequest().getParam("sone");
-               Sone sone = webInterface.core().getSone(soneId);
-               if (sone == null) {
-                       return new JsonObject().put("success", false).put("error", "invalid-sone-id");
+               if (!webInterface.getCore().hasSone(soneId)) {
+                       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.removeFriend(sone);
-               webInterface.core().saveSone(currentSone);
-               return new JsonObject().put("success", true);
+               currentSone.removeFriend(soneId);
+               webInterface.getCore().touchConfiguration();
+               return createSuccessJsonObject();
        }
 
 }