Remove method to mark replies as known from the core.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ajax / MarkAsKnownAjaxPage.java
index b641ea0..fb602db 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - MarkAsKnownAjaxPage.java - Copyright © 2011 David Roden
+ * Sone - MarkAsKnownAjaxPage.java - Copyright © 2011–2013 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,10 +19,13 @@ package net.pterodactylus.sone.web.ajax;
 
 import net.pterodactylus.sone.core.Core;
 import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.WebInterface;
-import net.pterodactylus.util.json.JsonObject;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+
+import com.google.common.base.Optional;
 
 /**
  * AJAX page that lets the user mark a number of {@link Sone}s, {@link Post}s,
@@ -42,11 +45,8 @@ public class MarkAsKnownAjaxPage extends JsonPage {
                super("markAsKnown.ajax", webInterface);
        }
 
-       /**
-        * {@inheritDoc}
-        */
        @Override
-       protected JsonObject createJsonObject(Request request) {
+       protected JsonReturnObject createJsonObject(FreenetRequest request) {
                String type = request.getHttpRequest().getParam("type");
                if (!type.equals("sone") && !type.equals("post") && !type.equals("reply")) {
                        return createErrorJsonObject("invalid-type");
@@ -55,31 +55,28 @@ public class MarkAsKnownAjaxPage extends JsonPage {
                Core core = webInterface.getCore();
                for (String id : ids) {
                        if (type.equals("post")) {
-                               Post post = core.getPost(id, false);
-                               if (post == null) {
+                               Optional<Post> post = core.getDatabase().getPost(id);
+                               if (!post.isPresent()) {
                                        continue;
                                }
-                               core.markPostKnown(post);
+                               core.markPostKnown(post.get());
                        } else if (type.equals("reply")) {
-                               Reply reply = core.getReply(id, false);
-                               if (reply == null) {
+                               Optional<PostReply> reply = core.getDatabase().getPostReply(id);
+                               if (!reply.isPresent()) {
                                        continue;
                                }
-                               core.markReplyKnown(reply);
+                               reply.get().modify().setKnown().update(webInterface.getCore().postReplyUpdated());
                        } else if (type.equals("sone")) {
-                               Sone sone = core.getSone(id, false);
-                               if (sone == null) {
+                               Optional<Sone> sone = core.getSone(id);
+                               if (!sone.isPresent()) {
                                        continue;
                                }
-                               core.markSoneKnown(sone);
+                               core.markSoneKnown(sone.get());
                        }
                }
                return createSuccessJsonObject();
        }
 
-       /**
-        * {@inheritDoc}
-        */
        @Override
        protected boolean requiresLogin() {
                return false;