diff options
-rw-r--r-- | src/java/com/juick/http/www/Main.java | 8 | ||||
-rw-r--r-- | src/java/com/juick/http/www/PM.java | 84 | ||||
-rw-r--r-- | web/scripts3.js | 11 | ||||
-rw-r--r-- | web/style3.css | 5 |
4 files changed, 99 insertions, 9 deletions
diff --git a/src/java/com/juick/http/www/Main.java b/src/java/com/juick/http/www/Main.java index fa4f9850..7564664a 100644 --- a/src/java/com/juick/http/www/Main.java +++ b/src/java/com/juick/http/www/Main.java @@ -28,6 +28,7 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; import javax.servlet.ServletException; +import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -39,6 +40,7 @@ import ru.sape.Sape; * @author Ugnich Anton */ @WebServlet(name = "Main", urlPatterns = {"/"}) +@MultipartConfig public class Main extends HttpServlet implements Stream.StreamListener { Connection sql; @@ -270,6 +272,12 @@ public class Main extends HttpServlet implements Stream.StreamListener { if (uri.equals("/post")) { pagesNewMessage.doPostNewMessage(sql, request, response); } else if (uri.equals("/pm/send")) { + com.juick.User visitor = Utils.getVisitorUser(sql, request, response); + if (visitor != null) { + pm.doPostPM(sql, request, response, xmpp, visitor); + } else { + response.sendError(403); + } } else if (uri.equals("/login")) { login.doPostLogin(sql, request, response); } else if (uri.equals("/signup")) { diff --git a/src/java/com/juick/http/www/PM.java b/src/java/com/juick/http/www/PM.java index e709af6b..bc43f1ee 100644 --- a/src/java/com/juick/http/www/PM.java +++ b/src/java/com/juick/http/www/PM.java @@ -18,6 +18,11 @@ package com.juick.http.www; import com.juick.server.PMQueries; +import com.juick.server.UserQueries; +import com.juick.xmpp.JID; +import com.juick.xmpp.Message; +import com.juick.xmpp.Stream; +import com.juick.xmpp.extensions.JuickMessage; import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; @@ -76,11 +81,11 @@ public class PM { out.println(" <div class=\"msg-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:</div>"); out.println(" <div class=\"msg-ts\"><a href=\"#\" onclick=\"return false\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString, locale) + "</a></div>"); out.println(" <div class=\"msg-txt\">" + txt + "</div>"); - /* - out.println(" <form action=\"/post\" method=\"POST\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"pm\" value=\"" + msg.User.UName + "\"/>"); - out.println(" <div class=\"msg-comment\"><div class=\"ta-wrapper\"><textarea name=\"body\" rows=\"1\" class=\"reply\" placeholder=\"" + rbg.getString("Reply") + "\" onkeypress=\"postformListener(this.form,event)\"></textarea></div></div>"); + + out.println(" <form action=\"/pm/send\" method=\"POST\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"uname\" value=\"" + msg.User.UName + "\"/>"); + out.println(" <div class=\"msg-comment\"><div class=\"ta-wrapper\"><textarea name=\"body\" rows=\"1\" class=\"replypm\" placeholder=\"" + rbg.getString("Reply") + "\" onkeypress=\"postformListener(this.form,event)\"></textarea></div></div>"); out.println(" </form>"); - */ + out.println(" </div>"); out.println(" </li>"); } @@ -138,6 +143,11 @@ public class PM { String title = "PM: Sent"; ArrayList<com.juick.Message> msgs = PMQueries.getLastPMSent(sql, visitor.UID); + String uname = request.getParameter("uname"); + if (!UserQueries.checkUserNameValid(uname)) { + uname = ""; + } + response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { @@ -148,6 +158,14 @@ public class PM { out.println("<div id=\"wrapper\">"); out.println("<div id=\"content\">"); + out.println("<form action=\"/pm/send\" method=\"POST\" enctype=\"multipart/form-data\">"); + out.println("<div class=\"newpm\">"); + out.println(" <div class=\"newpm-to\">To: <input type=\"text\" name=\"uname\" placeholder=\"username\" value=\"" + uname + "\"/></div>"); + out.println(" <div class=\"newpm-body\"><textarea name=\"body\" rows=\"2\" placeholder=\"" + rbg.getString("Reply") + "\" onkeypress=\"postformListener(this.form,event)\"></textarea></div>"); + out.println(" <div class=\"newpm-send\"><input type=\"submit\" value=\"OK\"/></div>"); + out.println("</div>"); + out.println("</form>"); + if (!msgs.isEmpty()) { out.println("<ul>"); for (int i = msgs.size() - 1; i >= 0; i--) { @@ -161,11 +179,6 @@ public class PM { out.println(" <div class=\"msg-header\">→ <a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:</div>"); out.println(" <div class=\"msg-ts\"><a href=\"#\" onclick=\"return false\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString, locale) + "</a></div>"); out.println(" <div class=\"msg-txt\">" + txt + "</div>"); - /* - out.println(" <form action=\"/post\" method=\"POST\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"pm\" value=\"" + msg.User.UName + "\"/>"); - out.println(" <div class=\"msg-comment\"><div class=\"ta-wrapper\"><textarea name=\"body\" rows=\"1\" class=\"reply\" placeholder=\"" + rbg.getString("Reply") + "\" onkeypress=\"postformListener(this.form,event)\"></textarea></div></div>"); - out.println(" </form>"); - */ out.println(" </div>"); out.println(" </li>"); } @@ -203,4 +216,57 @@ public class PM { out.close(); } } + + public void doPostPM(Connection sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException { + String uname = request.getParameter("uname"); + int uid = 0; + if (UserQueries.checkUserNameValid(uname)) { + uid = UserQueries.getUIDbyName(sql, uname); + } + + String body = request.getParameter("body"); + if (uid == 0 || body == null || body.length() < 1 || body.length() > 10240) { + response.sendError(400); + return; + } + + if (UserQueries.isInBLAny(sql, uid, visitor.UID)) { + response.sendError(403); + return; + } + + if (PMQueries.createPM(sql, visitor.UID, uid, body)) { + Message msg = new Message(); + msg.from = new JID("juick", "juick.com", null); + msg.to = new JID(Integer.toString(uid), "push.juick.com", null); + JuickMessage jmsg = new JuickMessage(); + jmsg.User = UserQueries.getUserByUID(sql, visitor.UID); + jmsg.Text = body; + msg.childs.add(jmsg); + xmpp.send(msg); + + msg.to.Host = "ws.juick.com"; + xmpp.send(msg); + + String jid = UserQueries.getJIDbyUID(sql, uid); + if (jid != null) { + Message mm = new Message(); + mm.to = new JID(jid); + mm.type = Message.Type.chat; + if (PMQueries.havePMinRoster(sql, visitor.UID, jid)) { + mm.from = new JID(jmsg.User.UName, "juick.com", "Juick"); + mm.body = body; + } else { + mm.from = new JID("juick", "juick.com", "Juick"); + mm.body = "Private message from @" + jmsg.User.UName + ":\n" + body; + } + xmpp.send(mm); + } + + Utils.sendTemporaryRedirect(response, "/pm/sent"); + + } else { + response.sendError(500); + } + } } diff --git a/web/scripts3.js b/web/scripts3.js index a8630b7e..b71eef16 100644 --- a/web/scripts3.js +++ b/web/scripts3.js @@ -822,6 +822,17 @@ $(document).ready(function() { $(this).off('click'); }); + var pmreply=$('textarea.replypm'); + pmreply.autoResize({ + extraSpace: 0, + minHeight: 1 + }); + pmreply.click(function () { + $(this).addClass("narrowpm"); + $(this).parent().after('<input type="submit" value="OK"/>'); + $(this).off('click'); + }); + if(!!$('#column').offset()) { var stickyTop = $('#column').offset().top; $(window).scroll(function() { diff --git a/web/style3.css b/web/style3.css index c23d2c1d..888c7313 100644 --- a/web/style3.css +++ b/web/style3.css @@ -65,6 +65,7 @@ pre { white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; .ta-wrapper { display: inline-block; border: 1px solid #DDD; } .msg-comment textarea { width: 506px; padding: 2px; resize: vertical; vertical-align: top; min-height: 12pt; height: 12pt; border: 0; } .msg-comment .narrow { width: 425px; } +.msg-comment .narrowpm { width: 450px; } .attach-photo { display: inline-block; padding: 2px 4px; cursor: pointer; width: 16px; height: 13px; background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAANCAQAAAAKsiavAAAAAXNSR0IArs4c6QAAAKRJREFUGNNjZICC6Q5M+xlQwD/HzAMMDEwwLnM9AxqAiDDO/M+AFzCh8B4zhrDwsfAxBjHcggkhm/CY2SDlHYQ5TZD5EoMMmgmMhSnvZnrPfDLzyQyvrPf/CzGs+L2TgYFhBoM0gzTjDAaGX7uwuQG/I1ldGRj+pzM8YXjMmMrAwOGK6cibfy2z3sMdeYpBBTMcHjMU/9zJzsjo8r8DIk1yQGEBAFzpL+AuTCqZAAAAAElFTkSuQmCC") no-repeat 3px 4px; } .attach-photo-active { display: inline-block; padding: 2px 4px; cursor: pointer; width: 16px; height: 13px; background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAANCAMAAACXZR4WAAAAAXNSR0IArs4c6QAAAEVQTFRFAAAAAJUAAJ0AAJIAAJkAAJYAAJwAAJcAAJoAAJgAAJkAAJoAAJoAAJgAAJkAAJoAAJkAAJkAAJkAAJkAAJkAAJkAAJkA9z3GXQAAABZ0Uk5TAAwNDg8REkBHSktRU1RVv9jZ2+Lj5OeV7PgAAABSSURBVAhbdcjBFkAgFADRIUlE9Or9/6daUC0cs5pzAXD65niKFSJQv/aChHHcrg4yA9jcILCW4tkbDGRVwfzDhs+yEBqcFsCmBiqHmULSDr0P3JdgDbuscEckAAAAAElFTkSuQmCC") no-repeat 3px 4px; } .msg-comment input { width: 50px; margin-left: 6px; vertical-align: top; border: 1px solid #CCC; background: #EEE; color: #999; } @@ -104,6 +105,10 @@ blockquote { border-left: 1px dashed #CCC; margin: 10px 0 10px 10px; padding-lef #pmreplytext { border: 1px solid #999; padding: 4px 5px; width: 515px; margin: 15px 5px 15px 0; } #pmreplybutton { border: 1px solid #999; padding: 3px 0; width: 35px; background: #CCCCC5} +.newpm { margin: 20px 60px 30px 60px; } +.newpm textarea { width: 100%; resize: vertical; } +.newpm-send input { width: 100px; } + /********/ #column { width: 230px; top: 0; padding-top: 10px; overflow: hidden; } |