diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/juick/api/Main.java | 6 | ||||
-rw-r--r-- | src/main/java/com/juick/api/Messages.java | 17 |
2 files changed, 23 insertions, 0 deletions
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<Integer> mids = MessagesQueries.getRecommended(sql, vuid, before_mid); + if (mids != null && !mids.isEmpty()) { + ArrayList<com.juick.Message> 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); |