X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FCreateReplyAjaxPage.java;h=00561564c9ed0f610b548ab06fb0ea66bba6d3de;hb=fd88107b013522d7620f5297386472206f320e10;hp=9ed960f529c84f3ad50f4fd4fcc4b5921673c89a;hpb=33f333b35a73d3d4a4e79f41e9dd7b342db87b1a;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java index 9ed960f..0056156 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java @@ -1,5 +1,5 @@ /* - * Sone - CreateReplyAjaxPage.java - Copyright © 2010 David Roden + * Sone - CreateReplyAjaxPage.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 @@ -17,11 +17,14 @@ package net.pterodactylus.sone.web.ajax; +import com.google.common.base.Optional; + +import net.pterodactylus.sone.data.LocalSone; import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.Reply; -import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.data.PostReply; +import net.pterodactylus.sone.text.TextFilter; import net.pterodactylus.sone.web.WebInterface; -import net.pterodactylus.util.json.JsonObject; +import net.pterodactylus.sone.web.page.FreenetRequest; /** * This AJAX page create a reply. @@ -48,20 +51,21 @@ public class CreateReplyAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String postId = request.getHttpRequest().getParam("post"); String text = request.getHttpRequest().getParam("text").trim(); String senderId = request.getHttpRequest().getParam("sender"); - Sone sender = webInterface.getCore().getLocalSone(senderId, false); - if (sender == null) { + Optional sender = webInterface.getCore().getLocalSone(senderId); + if (!sender.isPresent()) { sender = getCurrentSone(request.getToadletContext()); } - Post post = webInterface.getCore().getPost(postId); - if ((post == null) || (post.getSone() == null)) { + Optional post = webInterface.getCore().getPost(postId); + if (!post.isPresent()) { return createErrorJsonObject("invalid-post-id"); } - Reply reply = webInterface.getCore().createReply(sender, post, text); - return createSuccessJsonObject().put("reply", reply.getId()).put("sone", sender.getId()); + text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text); + PostReply reply = webInterface.getCore().createReply(sender.get(), post.get(), text); + return createSuccessJsonObject().put("reply", reply.getId()).put("sone", sender.get().getId()); } }