Merge branch 'release-0.9.6'
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ajax / DeletePostAjaxPage.java
index ea2310c..cfc1415 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - DeletePostAjaxPage.java - Copyright © 2010–2012 David Roden
+ * Sone - DeletePostAjaxPage.java - Copyright © 2010–2016 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
 
 package net.pterodactylus.sone.web.ajax;
 
+import com.google.common.base.Optional;
+
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.json.JsonObject;
 
 /**
  * This AJAX page deletes a post.
@@ -47,16 +48,16 @@ public class DeletePostAjaxPage extends JsonPage {
         * {@inheritDoc}
         */
        @Override
-       protected JsonObject createJsonObject(FreenetRequest request) {
+       protected JsonReturnObject createJsonObject(FreenetRequest request) {
                String postId = request.getHttpRequest().getParam("post");
-               Post post = webInterface.getCore().getPost(postId, false);
-               if ((post == null) || (post.getSone() == null)) {
+               Optional<Post> post = webInterface.getCore().getPost(postId);
+               if (!post.isPresent()) {
                        return createErrorJsonObject("invalid-post-id");
                }
-               if (!webInterface.getCore().isLocalSone(post.getSone())) {
+               if (!post.get().getSone().isLocal()) {
                        return createErrorJsonObject("not-authorized");
                }
-               webInterface.getCore().deletePost(post);
+               webInterface.getCore().deletePost(post.get());
                return createSuccessJsonObject();
        }