From: David ‘Bombe’ Roden Date: Tue, 18 Jan 2011 07:04:06 +0000 (+0100) Subject: Allow specifying the sender when creating replies. X-Git-Tag: 0.4.2^2~30^2~2 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=e5fd03bc196f53ae29d3ab22ca1f2dc08e8a4d78;p=Sone.git Allow specifying the sender when creating replies. --- diff --git a/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java b/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java index d4a9775..d3b7c35 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java +++ b/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java @@ -58,8 +58,12 @@ public class CreateReplyPage extends SoneTemplatePage { if (request.getMethod() == Method.POST) { Post post = webInterface.getCore().getPost(postId); if (text.length() > 0) { - Sone currentSone = getCurrentSone(request.getToadletContext()); - webInterface.getCore().createReply(currentSone, post, text); + String senderId = request.getHttpRequest().getPartAsStringFailsafe("sender", 43); + Sone sender = webInterface.getCore().getLocalSone(senderId, false); + if (sender == null) { + sender = getCurrentSone(request.getToadletContext()); + } + webInterface.getCore().createReply(sender, post, text); throw new RedirectException(returnPage); } dataProvider.set("errorTextEmpty", true); 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 0181ff2..9ed960f 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java @@ -51,16 +51,17 @@ public class CreateReplyAjaxPage extends JsonPage { protected JsonObject createJsonObject(Request request) { String postId = request.getHttpRequest().getParam("post"); String text = request.getHttpRequest().getParam("text").trim(); - Sone currentSone = getCurrentSone(request.getToadletContext()); - if (currentSone == null) { - return createErrorJsonObject("auth-required"); + String senderId = request.getHttpRequest().getParam("sender"); + Sone sender = webInterface.getCore().getLocalSone(senderId, false); + if (sender == null) { + sender = getCurrentSone(request.getToadletContext()); } Post post = webInterface.getCore().getPost(postId); if ((post == null) || (post.getSone() == null)) { return createErrorJsonObject("invalid-post-id"); } - Reply reply = webInterface.getCore().createReply(currentSone, post, text); - return createSuccessJsonObject().put("reply", reply.getId()); + Reply reply = webInterface.getCore().createReply(sender, post, text); + return createSuccessJsonObject().put("reply", reply.getId()).put("sone", sender.getId()); } }