aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/http/www/PM.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-07-07 11:25:23 +0300
committerGravatar Vitaly Takmazov2016-07-07 11:25:23 +0300
commita93c85c5ea1bf6683f604bef2608053957577ff0 (patch)
treef80998a4cf339a2b85cd5f095f4386de9d46597b /src/main/java/com/juick/http/www/PM.java
parent3e48ba7c9cae9027b0a045aa25ae40b533518865 (diff)
parent857a930d31c425185c9b9405f5a7820e6cec9491 (diff)
merge rebase_all
Diffstat (limited to 'src/main/java/com/juick/http/www/PM.java')
-rw-r--r--src/main/java/com/juick/http/www/PM.java42
1 files changed, 17 insertions, 25 deletions
diff --git a/src/main/java/com/juick/http/www/PM.java b/src/main/java/com/juick/http/www/PM.java
index a9505bdb..932d1baf 100644
--- a/src/main/java/com/juick/http/www/PM.java
+++ b/src/main/java/com/juick/http/www/PM.java
@@ -23,14 +23,14 @@ 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;
-import java.util.ArrayList;
-import java.util.List;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
/**
*
@@ -38,7 +38,7 @@ import javax.servlet.http.HttpServletResponse;
*/
public class PM {
- protected void doGetInbox(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
+ protected void doGetInbox(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
/*
int paramBefore = 0;
String paramBeforeStr = request.getParameter("before");
@@ -54,8 +54,7 @@ public class PM {
List<com.juick.Message> msgs = PMQueries.getLastPMInbox(sql, visitor.getUID());
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
PageTemplates.pageHead(out, title, null);
PageTemplates.pageNavigation(out, visitor, null);
PageTemplates.pageHomeColumn(out, sql, visitor);
@@ -64,8 +63,7 @@ public class PM {
if (!msgs.isEmpty()) {
out.println("<ul>");
- for (int i = msgs.size() - 1; i >= 0; i--) {
- com.juick.Message msg = msgs.get(i);
+ for (com.juick.Message msg : msgs) {
String txt = PageTemplates.formatMessage(msg.getText());
@@ -73,7 +71,7 @@ public class PM {
out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.getUser().getUName() + "/\"><img src=\"//i.juick.com/a/" + msg.getUser().getUID() + ".png\" alt=\"" + msg.getUser().getUName() + "\"/></a></div>");
out.println(" <div class=\"msg-cont\">");
out.println(" <div class=\"msg-header\"><a href=\"/" + msg.getUser().getUName() + "/\">@" + msg.getUser().getUName() + "</a>:</div>");
- out.println(" <div class=\"msg-ts\"><a href=\"#\" onclick=\"return false\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString) + "</a></div>");
+ out.println(" <div class=\"msg-ts\"><a href=\"#\" onclick=\"return false\" title=\"" + PageTemplates.sdfSQL.format(msg.getDate()) + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.getDate()) + "</a></div>");
out.println(" <div class=\"msg-txt\">" + txt + "</div>");
out.println(" <form action=\"/pm/send\" method=\"POST\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"uname\" value=\"" + msg.getUser().getUName() + "\"/>");
@@ -97,12 +95,10 @@ public class PM {
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
- protected void doGetSent(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
+ protected void doGetSent(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
/*
int paramBefore = 0;
String paramBeforeStr = request.getParameter("before");
@@ -123,8 +119,7 @@ public class PM {
}
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
PageTemplates.pageHead(out, title, null);
PageTemplates.pageNavigation(out, visitor, null);
PageTemplates.pageHomeColumn(out, sql, visitor);
@@ -141,8 +136,7 @@ public class PM {
if (!msgs.isEmpty()) {
out.println("<ul>");
- for (int i = msgs.size() - 1; i >= 0; i--) {
- com.juick.Message msg = msgs.get(i);
+ for (com.juick.Message msg : msgs) {
String txt = PageTemplates.formatMessage(msg.getText());
@@ -150,7 +144,7 @@ public class PM {
out.println(" <div class=\"msg-avatar\"><img src=\"//i.juick.com/a/" + visitor.getUID() + ".png\"/></div>");
out.println(" <div class=\"msg-cont\">");
out.println(" <div class=\"msg-header\">→ <a href=\"/" + msg.getUser().getUName() + "/\">@" + msg.getUser().getUName() + "</a>:</div>");
- out.println(" <div class=\"msg-ts\"><a href=\"#\" onclick=\"return false\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString) + "</a></div>");
+ out.println(" <div class=\"msg-ts\"><a href=\"#\" onclick=\"return false\" title=\"" + PageTemplates.sdfSQL.format(msg.getDate()) + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.getDate()) + "</a></div>");
out.println(" <div class=\"msg-txt\">" + txt + "</div>");
out.println(" </div>");
out.println(" </li>");
@@ -169,12 +163,10 @@ public class PM {
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
- public void doPostPM(Connection sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
+ public void doPostPM(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
String uname = request.getParameter("uname");
if (uname.startsWith("@")) {
uname = uname.substring(1);
@@ -200,7 +192,7 @@ public class PM {
msg.from = new JID("juick", "juick.com", null);
msg.to = new JID(Integer.toString(uid), "push.juick.com", null);
JuickMessage jmsg = new JuickMessage();
- jmsg.setUser(UserQueries.getUserByUID(sql, visitor.getUID()));
+ jmsg.setUser(visitor);
jmsg.setText(body);
msg.childs.add(jmsg);
xmpp.send(msg);
@@ -208,8 +200,8 @@ public class PM {
msg.to.Host = "ws.juick.com";
xmpp.send(msg);
- String jid = UserQueries.getJIDbyUID(sql, uid);
- if (jid != null) {
+ List<String> jids = UserQueries.getJIDsbyUID(sql, uid);
+ for (String jid : jids) {
Message mm = new Message();
mm.to = new JID(jid);
mm.type = Message.Type.chat;