diff options
Diffstat (limited to 'juick-www/src/main/java/com/juick/www')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/Main.java | 6 | ||||
-rw-r--r-- | juick-www/src/main/java/com/juick/www/PM.java | 70 |
2 files changed, 14 insertions, 62 deletions
diff --git a/juick-www/src/main/java/com/juick/www/Main.java b/juick-www/src/main/java/com/juick/www/Main.java index 1e755ca3..c67eced0 100644 --- a/juick-www/src/main/java/com/juick/www/Main.java +++ b/juick-www/src/main/java/com/juick/www/Main.java @@ -190,7 +190,11 @@ public class Main extends HttpServlet implements Stream.StreamListener { } break; case "/pm/sent": - pm.doGetSent(sql, request, response, visitor); + try { + pm.doGetSent(sql, request, response, visitor); + } catch (PebbleException e) { + log("pebble exception", e); + } break; default: Errors.doGet404(sql, request, response); 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 f912f0b6..7380ca8f 100644 --- a/juick-www/src/main/java/com/juick/www/PM.java +++ b/juick-www/src/main/java/com/juick/www/PM.java @@ -39,8 +39,6 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import static com.juick.www.PageTemplates.sape; - /** * * @author Ugnich Anton @@ -53,7 +51,6 @@ public class PM { String title = "PM: Inbox"; List<com.juick.Message> msgs = PMQueries.getLastPMInbox(sql, visitor.getUID()); msgs.forEach(m -> m.setText(Utils.formatMessage(m.getText()))); - String links = sape.getPageLinks(request.getRequestURI(), request.getCookies()).render(); response.setContentType("text/html; charset=UTF-8"); try (PrintWriter out = response.getWriter()) { PebbleTemplate template = Utils.getEngine().getTemplate("views/pm_inbox.html"); @@ -62,25 +59,11 @@ public class PM { context.put("visitor", visitor); context.put("msgs", msgs); context.put("tags", TagQueries.getPopularTags(sql)); - if (visitor.getUID() == 0) { - context.put("showAdv", true); - context.put("links", links); - } template.evaluate(out, context); } } - protected void doGetSent(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 doGetSent(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException, PebbleException { String title = "PM: Sent"; List<com.juick.Message> msgs = PMQueries.getLastPMSent(sql, visitor.getUID()); @@ -92,49 +75,14 @@ public class PM { response.setContentType("text/html; charset=UTF-8"); try (PrintWriter out = response.getWriter()) { - PageTemplates.pageHead(out, visitor, title, null); - PageTemplates.pageNavigation(out, visitor, null); - PageTemplates.pageHomeColumn(out, sql, visitor); - - out.println("<section 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\"></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 (com.juick.Message msg : msgs) { - - 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>"); - 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=\"" + 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>"); - } - 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.pageFooter(request, out, visitor, false); - PageTemplates.pageEnd(out); + PebbleTemplate template = Utils.getEngine().getTemplate("views/pm_sent.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)); + context.put("uname", uname); + template.evaluate(out, context); } } |