From 0acc3ca041434ca5486e7def8cb75729995106d5 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 3 Nov 2015 16:38:52 +0300 Subject: /messages/recommended --- src/main/java/com/juick/api/Main.java | 6 ++++++ src/main/java/com/juick/api/Messages.java | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'src/main/java') diff --git a/src/main/java/com/juick/api/Main.java b/src/main/java/com/juick/api/Main.java index 5ee4027b..e10b9078 100644 --- a/src/main/java/com/juick/api/Main.java +++ b/src/main/java/com/juick/api/Main.java @@ -166,6 +166,12 @@ public class Main extends HttpServlet implements Stream.StreamListener { } else { response.sendError(401); } + } else if (uri.equals("/messages/recommended")) { + if (vuid > 0) { + messages.doGetRecommended(request, response, vuid); + } else { + response.sendError(401); + } } else if (uri.equals("/messages/set_popular") && vuid == 1) { messages.doSetPopular(request, response, xmpp); } else if (uri.equals("/messages/set_privacy") && vuid > 0) { diff --git a/src/main/java/com/juick/api/Messages.java b/src/main/java/com/juick/api/Messages.java index b5462258..76615e44 100644 --- a/src/main/java/com/juick/api/Messages.java +++ b/src/main/java/com/juick/api/Messages.java @@ -41,6 +41,23 @@ public class Messages { } } + public void doGetRecommended(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { + int before_mid = Utils.parseInt(request.getParameter("before_mid"), 0); + + ArrayList mids = MessagesQueries.getRecommended(sql, vuid, before_mid); + if (mids != null && !mids.isEmpty()) { + ArrayList msgs = MessagesQueries.getMessages(sql, mids); + if (msgs != null && !msgs.isEmpty()) { + String json = com.juick.json.Messages.arrayToString(msgs); + Main.replyJSON(request, response, json); + } else { + response.sendError(404); + } + } else { + response.sendError(404); + } + } + public void doSetPrivacy(HttpServletRequest request, HttpServletResponse response, Stream xmpp, int vuid) throws ServletException, IOException { int mid = Utils.parseInt(request.getParameter("mid"), 0); com.juick.User user = MessagesQueries.getMessageAuthor(sql, mid); -- cgit v1.2.3