X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FLikeAjaxPage.java;h=84a93e3ce1ba216ac58655825319c03547f3b466;hb=f10d40f746f6c7c716f783da11791d28c1117447;hp=6787711c470002e48eddb0cebcd3c4492c4be3aa;hpb=99888ce13cc17d49f5e217ab6f2c9ad5ef168792;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java index 6787711..84a93e3 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java @@ -18,10 +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.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; + +import com.google.common.base.Optional; /** * AJAX page that lets the user like a {@link Post}. @@ -40,11 +42,8 @@ public class LikeAjaxPage extends JsonPage { super("like.ajax", webInterface); } - /** - * {@inheritDoc} - */ @Override - protected JsonObject createJsonObject(FreenetRequest 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)) { @@ -55,10 +54,16 @@ public class LikeAjaxPage extends JsonPage { return createErrorJsonObject("auth-required"); } if ("post".equals(type)) { - currentSone.addLikedPostId(id); + Optional post = webInterface.getCore().getDatabase().getPost(id); + if (post.isPresent()) { + post.get().like(currentSone); + } webInterface.getCore().touchConfiguration(); } else if ("reply".equals(type)) { - currentSone.addLikedReplyId(id); + Optional postReply = webInterface.getCore().getDatabase().getPostReply(id); + if (postReply.isPresent()) { + postReply.get().like(currentSone); + } webInterface.getCore().touchConfiguration(); } else { return createErrorJsonObject("invalid-type");