X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FUnlikeAjaxPage.java;h=bd5f91ba7da7c92460b78c74996650ac04a38d12;hb=2e03e9dddbea4b81aacaf1aa316f5c3ccffd4bf9;hp=84b059330a87818631e3cba21e396e145c37db46;hpb=1bc78b582ac59f2438002997f5780db4dcee0a2a;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java index 84b0593..bd5f91b 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java @@ -1,5 +1,5 @@ /* - * Sone - UnlikeAjaxPage.java - Copyright © 2010 David Roden + * Sone - UnlikeAjaxPage.java - Copyright © 2010–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 @@ -18,9 +18,12 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.PostReply; 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 unlike a {@link Post}. @@ -39,11 +42,8 @@ public class UnlikeAjaxPage extends JsonPage { super("unlike.ajax", webInterface); } - /** - * {@inheritDoc} - */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String type = request.getHttpRequest().getParam("type", null); String id = request.getHttpRequest().getParam(type, null); if ((id == null) || (id.length() == 0)) { @@ -54,10 +54,16 @@ public class UnlikeAjaxPage extends JsonPage { return createErrorJsonObject("auth-required"); } if ("post".equals(type)) { - currentSone.removeLikedPostId(id); + Optional post = webInterface.getCore().getDatabase().getPost(id); + if (post.isPresent()) { + post.get().unlike(currentSone); + } webInterface.getCore().touchConfiguration(); } else if ("reply".equals(type)) { - currentSone.removeLikedReplyId(id); + Optional postReply = webInterface.getCore().getDatabase().getPostReply(id); + if (postReply.isPresent()) { + postReply.get().unlike(currentSone); + } webInterface.getCore().touchConfiguration(); } else { return createErrorJsonObject("invalid-type");