aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/http/www/NewMessage.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-02-03 13:54:12 +0300
committerGravatar Vitaly Takmazov2016-02-03 13:54:12 +0300
commite80e13c27e6f06c52a3dc8602cd1f02abdfc3180 (patch)
treea309a04f63bd0e4eefae4b0583e88352f1f0e802 /src/main/java/com/juick/http/www/NewMessage.java
parent380018da475ff41d3375e7f2bea0a192a4d9b178 (diff)
WIP
Diffstat (limited to 'src/main/java/com/juick/http/www/NewMessage.java')
-rw-r--r--src/main/java/com/juick/http/www/NewMessage.java47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/main/java/com/juick/http/www/NewMessage.java b/src/main/java/com/juick/http/www/NewMessage.java
index b3b63b17..d3178c59 100644
--- a/src/main/java/com/juick/http/www/NewMessage.java
+++ b/src/main/java/com/juick/http/www/NewMessage.java
@@ -17,6 +17,7 @@
*/
package com.juick.http.www;
+import com.juick.JuickApplication;
import com.juick.Tag;
import com.juick.server.CrosspostQueries;
import com.juick.server.MessagesQueries;
@@ -54,10 +55,19 @@ public class NewMessage {
private static final Logger logger = Logger.getLogger(NewMessage.class.getName());
- protected void doGetNewMessage(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
+ JuickApplication app;
+ JdbcTemplate sql;
+ Stream xmpp;
+
+ public NewMessage(JuickApplication application) {
+ this.app = application;
+ this.sql = application.getSql();
+ this.xmpp = application.getRouter();
+ }
+
+ protected void doGetNewMessage(HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
PageTemplates.pageHead(out, "Написать", "<script src=\"//maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAVVtPtxkw4soCEHg44FsNChRB4OFYjAXt73He16Zkp6a_0tPs2RTU6i6UlcMs4QvPBYvIY8rWvcxqOg\" type=\"text/javascript\"></script>"
+ "<script src=\"//static.juick.com/mc.js\" type=\"text/javascript\" defer=\"defer\"></script>"
+ "<script src=\"//static.juick.com/maps.js?2010111500\" type=\"text/javascript\" defer=\"defer\"></script>"
@@ -84,17 +94,15 @@ public class NewMessage {
out.println("</form>");
out.println("<div id=\"geomap\"></div>");
out.println("<p style=\"text-align: left\"><b>Теги:</b></p>");
- printUserTags(sql, out, visitor);
+ printUserTags(out, visitor);
out.println("</section>");
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
- void printUserTags(JdbcTemplate sql, PrintWriter out, com.juick.User visitor) {
+ void printUserTags(PrintWriter out, com.juick.User visitor) {
List<Tag> tags = TagQueries.getUserTagsAll(sql, visitor.getUID());
if (tags.isEmpty()) {
@@ -140,7 +148,8 @@ public class NewMessage {
out.println("</p>");
}
- public void doPostMessage(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
+ public void doPostMessage(HttpServletRequest request, HttpServletResponse response,
+ com.juick.User visitor) throws ServletException, IOException {
String body = request.getParameter("body");
if (body == null || body.length() < 1 || body.length() > 4096) {
response.sendError(400);
@@ -222,20 +231,20 @@ public class NewMessage {
xmsg.body = "@" + jmsg.getUser().getUName() + ":" + tagsStr2 + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid;
xmsg.to = new JID("juick", "s2s.juick.com", null);
- Main.push(xmsg);
+ app.push(xmsg);
xmsg.to.Host = "push.juick.com";
- Main.push(xmsg);
+ app.push(xmsg);
xmsg.to.Host = "crosspost.juick.com";
xmsg.to.Username = "twitter";
- Main.push(xmsg);
+ app.push(xmsg);
xmsg.to.Username = "fb";
- Main.push(xmsg);
+ app.push(xmsg);
xmsg.to.Host = "nologin.ru";
xmsg.to.Username = "jubo";
- Main.push(xmsg);
+ app.push(xmsg);
if (xmpp != null) {
xmsg.to.Host = "ws.juick.com";
xmpp.send(xmsg);
@@ -288,7 +297,8 @@ public class NewMessage {
}
}
- public void doPostComment(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
+ public void doPostComment(HttpServletRequest request, HttpServletResponse response,
+ com.juick.User visitor) throws ServletException, IOException {
int mid = Utils.parseInt(request.getParameter("mid"), 0);
if (mid == 0) {
response.sendError(400);
@@ -379,9 +389,9 @@ public class NewMessage {
xmsg.body = "Reply by @" + jmsg.getUser().getUName() + ":\n>" + quote + "\n" + body + "\n\n#" + mid + "/" + ridnew + " http://juick.com/" + mid + "#" + ridnew;
xmsg.to = new JID("juick", "s2s.juick.com", null);
- Main.push(xmsg);
+ app.push(xmsg);
xmsg.to.Host = "push.juick.com";
- Main.push(xmsg);
+ app.push(xmsg);
if (xmpp != null) {
xmsg.to.Host = "ws.juick.com";
@@ -393,7 +403,8 @@ public class NewMessage {
Utils.sendTemporaryRedirect(response, "/" + msg.getUser().getUName() + "/" + mid + "#" + ridnew);
}
- public void doPostRecomm(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
+ public void doPostRecomm(HttpServletRequest request, HttpServletResponse response,
+ com.juick.User visitor) throws ServletException, IOException {
int mid = Utils.parseInt(request.getParameter("mid"), 0);
if (mid == 0) {
response.sendError(400);
@@ -418,7 +429,7 @@ public class NewMessage {
jmsg.setMID(mid);
jmsg.setUser(new JuickUser(visitor));
xmsg.addChild(jmsg);
- Main.push(xmsg);
+ app.push(xmsg);
Utils.replyJSON(request, response, "{\"status\":\"ok\"}");
} else {