diff options
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/PM.java')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/PM.java | 67 |
1 files changed, 14 insertions, 53 deletions
diff --git a/juick-www/src/main/java/com/juick/www/PM.java b/juick-www/src/main/java/com/juick/www/PM.java index 9d7da65b..ac2cbb76 100644 --- a/juick-www/src/main/java/com/juick/www/PM.java +++ b/juick-www/src/main/java/com/juick/www/PM.java @@ -18,11 +18,14 @@ package com.juick.www; import com.juick.server.PMQueries; +import com.juick.server.TagQueries; 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 com.mitchellbosecke.pebble.error.PebbleException; +import com.mitchellbosecke.pebble.template.PebbleTemplate; import org.springframework.jdbc.core.JdbcTemplate; import javax.servlet.ServletException; @@ -30,7 +33,9 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -41,64 +46,20 @@ import java.util.logging.Logger; public class PM { private static final Logger logger = Logger.getLogger(PM.class.getName()); - protected void doGetInbox(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException { - /* - int paramBefore = 0; - String paramBeforeStr = request.getParameter("before"); - if (paramBeforeStr != null) { - try { - paramBefore = Integer.parseInt(paramBeforeStr); - } catch (NumberFormatException e) { - } - } - */ + protected void doGetInbox(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException, PebbleException { String title = "PM: Inbox"; List<com.juick.Message> msgs = PMQueries.getLastPMInbox(sql, visitor.getUID()); response.setContentType("text/html; charset=UTF-8"); try (PrintWriter out = response.getWriter()) { - PageTemplates.pageHead(out, visitor, title, null); - PageTemplates.pageNavigation(out, visitor, null); - - out.println("<section id=\"content\">"); - - if (!msgs.isEmpty()) { - out.println("<ul id=\"private-messages\">"); - for (com.juick.Message msg : msgs) { - - String txt = PageTemplates.formatMessage(msg.getText()); - - out.println(" <li class=\"msg\">"); - out.println(" <div class=\"msg-cont\">"); - 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-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-header\">@<a href=\"/" + msg.getUser().getUName() + "/\">" + msg.getUser().getUName() + "</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() + "\"/>"); - out.println(" <div class=\"msg-comment\"><div class=\"ta-wrapper\"><textarea name=\"body\" rows=\"1\" class=\"replypm\" placeholder=\"Написать ответ\"></textarea></div></div>"); - out.println(" </form>"); - - out.println(" </div>"); - out.println(" </li>"); - } - out.println("</ul>"); - } - - /* - if (msgs.size() >= 20) { - String nextpage = "?before=" + msgs.get(msgs.size() - 1); - out.println("<p class=\"page\"><a href=\"" + nextpage + "\">Читать дальше →</a></p>"); - } - */ - - out.println("</section>"); - - PageTemplates.pageHomeColumn(out, sql, visitor); - - PageTemplates.pageFooter(request, out, visitor, false); - PageTemplates.pageEnd(out); + PebbleTemplate template = Utils.getEngine().getTemplate("views/pm_inbox.html"); + Map<String, Object> context = new HashMap<>(); + context.put("title", title); + context.put("visitor", visitor); + context.put("msgs", msgs); + context.put("tags", TagQueries.getPopularTags(sql)); + template.evaluate(out, context); } } @@ -142,7 +103,7 @@ public class PM { out.println("<ul>"); for (com.juick.Message msg : msgs) { - String txt = PageTemplates.formatMessage(msg.getText()); + String txt = Utils.formatMessage(msg.getText()); out.println(" <li class=\"msg\">"); out.println(" <div class=\"msg-avatar\"><img src=\"//i.juick.com/a/" + visitor.getUID() + ".png\"/></div>"); |