X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FCreatePostAjaxPage.java;h=536d4fb62bcad4f6d297cbc09ccee502060441ce;hb=8d49fb185ee26853262a12f6d419ef2e39c1116c;hp=0d553cc70daaf8181919700b4abf3228c286a8c0;hpb=7095e29ec66d04d9b466dd3ed762655ee334049e;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java index 0d553cc..536d4fb 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java @@ -1,5 +1,5 @@ /* - * Sone - CreatePostAjaxPage.java - Copyright © 2010 David Roden + * Sone - CreatePostAjaxPage.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,10 +17,16 @@ package net.pterodactylus.sone.web.ajax; +import static com.google.common.base.Optional.of; +import static net.pterodactylus.sone.data.Identified.GET_ID; + import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; +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; + +import com.google.common.base.Optional; /** * AJAX handler that creates a new post. @@ -36,24 +42,32 @@ public class CreatePostAjaxPage extends JsonPage { * The Sone web interface */ public CreatePostAjaxPage(WebInterface webInterface) { - super("ajax/createPost.ajax", webInterface); + super("createPost.ajax", webInterface); } /** * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { Sone sone = getCurrentSone(request.getToadletContext()); if (sone == null) { return createErrorJsonObject("auth-required"); } + String recipientId = request.getHttpRequest().getParam("recipient"); + Optional recipient = webInterface.getCore().getSone(recipientId); + String senderId = request.getHttpRequest().getParam("sender"); + Optional sender = webInterface.getCore().getLocalSone(senderId); + if (!sender.isPresent()) { + sender = of(sone); + } String text = request.getHttpRequest().getParam("text"); if ((text == null) || (text.trim().length() == 0)) { return createErrorJsonObject("text-required"); } - Post newPost = webInterface.getCore().createPost(sone, text); - return createSuccessJsonObject().put("postId", newPost.getId()); + text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text); + Post newPost = sender.get().newPostBuilder().to(recipient.transform(GET_ID)).withText(text).build(of(webInterface.getCore().postCreated())); + return createSuccessJsonObject().put("postId", newPost.getId()).put("sone", sender.get().getId()).put("recipient", newPost.getRecipientId().orNull()); } }