From e5fd03bc196f53ae29d3ab22ca1f2dc08e8a4d78 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 18 Jan 2011 08:04:06 +0100 Subject: [PATCH] Allow specifying the sender when creating replies. --- src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java | 8 ++++++-- .../net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java | 11 ++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) 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()); } } -- 2.7.4