aboutsummaryrefslogtreecommitdiff
path: root/src/java
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2013-11-16 03:22:57 +0700
committerGravatar Ugnich Anton2013-11-16 03:22:57 +0700
commit211edb389dcf5912b02346869264ea5dcd4cf75e (patch)
tree43c6c729d5293e3df9e88ab8f691c9f415a8ae31 /src/java
parent91bf74631157d8e559686ca25e4980f155d88438 (diff)
Messages.doGetHome
Diffstat (limited to 'src/java')
-rw-r--r--src/java/com/juick/api/Main.java10
-rw-r--r--src/java/com/juick/api/Messages.java39
-rw-r--r--src/java/com/juick/api/PM.java6
-rw-r--r--src/java/com/juick/api/Utils.java11
4 files changed, 62 insertions, 4 deletions
diff --git a/src/java/com/juick/api/Main.java b/src/java/com/juick/api/Main.java
index 718ca249..38716282 100644
--- a/src/java/com/juick/api/Main.java
+++ b/src/java/com/juick/api/Main.java
@@ -44,6 +44,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
Connection sql;
Connection sqlSearch;
Stream xmpp;
+ Messages messages;
Users users;
PM pm;
Others others;
@@ -59,6 +60,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", ""));
sqlSearch = DriverManager.getConnection("jdbc:mysql://127.0.0.1:9306/juick?autoReconnect=true&characterEncoding=utf8&maxAllowedPacket=512000&relaxAutoCommit=true&user=root&password=");
+ messages = new Messages(sql);
users = new Users(sql);
pm = new PM(sql);
others = new Others(sql);
@@ -138,7 +140,13 @@ public class Main extends HttpServlet implements Stream.StreamListener {
}
String uri = request.getRequestURI();
- if (uri.equals("/users")) {
+ if (uri.equals("/home")) {
+ if (vuid > 0) {
+ messages.doGetHome(request, response, vuid);
+ } else {
+ response.sendError(401);
+ }
+ } else if (uri.equals("/users")) {
users.doGetUsers(request, response, vuid);
} else if (uri.equals("/users/read")) {
users.doGetUserRead(request, response, vuid);
diff --git a/src/java/com/juick/api/Messages.java b/src/java/com/juick/api/Messages.java
new file mode 100644
index 00000000..5ecf503f
--- /dev/null
+++ b/src/java/com/juick/api/Messages.java
@@ -0,0 +1,39 @@
+package com.juick.api;
+
+import com.juick.server.MessagesQueries;
+import java.io.IOException;
+import java.sql.Connection;
+import java.util.ArrayList;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author ugnich
+ */
+public class Messages {
+
+ Connection sql;
+
+ public Messages(Connection sql) {
+ this.sql = sql;
+ }
+
+ public void doGetHome(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
+ int before_mid = Utils.parseInt(request.getParameter("before_mid"), 0);
+
+ ArrayList<Integer> mids = MessagesQueries.getMyFeed(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);
+ }
+ }
+}
diff --git a/src/java/com/juick/api/PM.java b/src/java/com/juick/api/PM.java
index 285f9ff6..700f1665 100644
--- a/src/java/com/juick/api/PM.java
+++ b/src/java/com/juick/api/PM.java
@@ -59,14 +59,12 @@ public class PM {
return;
}
- if (UserQueries.isInBL(sql, uid, vuid)) {
+ if (UserQueries.isInBL(sql, uid, vuid) || UserQueries.isInBL(sql, vuid, uid)) {
response.sendError(403);
return;
}
if (PMQueries.createPM(sql, vuid, uid, body)) {
- Main.replyJSON(request, response, "");
-
Message msg = new Message();
msg.from = new JID("juick", "juick.com", null);
msg.to = new JID(Integer.toString(uid), "push.juick.com", null);
@@ -80,6 +78,8 @@ public class PM {
msg.to.Host = "ws.juick.com";
xmpp.send(msg);
+ Main.replyJSON(request, response, com.juick.json.Message.toJSON(jmsg).toString());
+
String jid = UserQueries.getJIDbyUID(sql, uid);
if (jid != null) {
Message mm = new Message();
diff --git a/src/java/com/juick/api/Utils.java b/src/java/com/juick/api/Utils.java
index b406c362..10e0cccb 100644
--- a/src/java/com/juick/api/Utils.java
+++ b/src/java/com/juick/api/Utils.java
@@ -135,4 +135,15 @@ public class Utils {
ret = ret.replaceAll("@", "\\\\@");
return ret;
}
+
+ public static int parseInt(String str, int def) {
+ int ret = def;
+ if (str != null) {
+ try {
+ ret = Integer.parseInt(str);
+ } catch (Exception e) {
+ }
+ }
+ return ret;
+ }
}