aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src/main/java/com/juick')
-rw-r--r--juick-api/src/main/java/com/juick/api/Main.java4
-rw-r--r--juick-api/src/main/java/com/juick/api/Notifications.java43
-rw-r--r--juick-api/src/main/java/com/juick/api/Subscriptions.java21
3 files changed, 64 insertions, 4 deletions
diff --git a/juick-api/src/main/java/com/juick/api/Main.java b/juick-api/src/main/java/com/juick/api/Main.java
index 3bd1e750..3c5c3303 100644
--- a/juick-api/src/main/java/com/juick/api/Main.java
+++ b/juick-api/src/main/java/com/juick/api/Main.java
@@ -71,6 +71,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
PM pm;
Others others;
Subscriptions subscriptions;
+ Notifications notifications;
TelegramBotHook tgb;
SkypeEndpoint sep;
@@ -92,6 +93,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
pm = new PM(jdbc);
others = new Others(jdbc);
subscriptions = new Subscriptions(jdbc);
+ notifications = new Notifications(jdbc);
tgb = new TelegramBotHook(jdbc, conf.getProperty("telegram_token", ""));
sep = new SkypeEndpoint();
setupXmppComponent(conf.getProperty("xmpp_host", "localhost"), Integer.parseInt(conf.getProperty("xmpp_port", "5347")),
@@ -187,6 +189,8 @@ public class Main extends HttpServlet implements Stream.StreamListener {
messages.doSetPrivacy(request, response, xmpp, vuid);
} else if (uri.equals("/subscriptions")) {
subscriptions.doGet(request, response, vuid);
+ } else if (uri.equals("/notifications")) {
+ notifications.doGet(request, response, vuid);
} else {
response.sendError(404);
}
diff --git a/juick-api/src/main/java/com/juick/api/Notifications.java b/juick-api/src/main/java/com/juick/api/Notifications.java
new file mode 100644
index 00000000..7cf27fc1
--- /dev/null
+++ b/juick-api/src/main/java/com/juick/api/Notifications.java
@@ -0,0 +1,43 @@
+package com.juick.api;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.juick.User;
+import com.juick.server.PushQueries;
+import com.juick.server.UserQueries;
+import org.apache.commons.lang3.math.NumberUtils;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Created by vitalyster on 24.10.2016.
+ */
+public class Notifications {
+ JdbcTemplate jdbc;
+ public Notifications(JdbcTemplate jdbc) {
+ this.jdbc = jdbc;
+ }
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response, int vuid) throws IOException {
+ User visitor = UserQueries.getUserByUID(jdbc, vuid).orElse(new User());
+ if ((visitor.getUID() == 0) && !(visitor.getUName().equals("juick"))) {
+ response.sendError(403);
+ return;
+ }
+ String type = request.getParameter("type");
+ int uid = NumberUtils.toInt(request.getParameter("uid"), 0);
+ int mid = NumberUtils.toInt(request.getParameter("mid"), 0);
+ if (uid > 0) {
+ switch (type) {
+ case "gcm":
+ List<String> tokens = PushQueries.getAndroidRegID(jdbc, uid);
+ ObjectMapper mapper = new ObjectMapper();
+ Main.replyJSON(request, response, mapper.writeValueAsString(tokens));
+ }
+
+ }
+ }
+}
diff --git a/juick-api/src/main/java/com/juick/api/Subscriptions.java b/juick-api/src/main/java/com/juick/api/Subscriptions.java
index 49990080..4c767dc9 100644
--- a/juick-api/src/main/java/com/juick/api/Subscriptions.java
+++ b/juick-api/src/main/java/com/juick/api/Subscriptions.java
@@ -1,7 +1,9 @@
package com.juick.api;
+import com.juick.Message;
import com.juick.User;
import com.juick.json.UserSerializer;
+import com.juick.server.MessagesQueries;
import com.juick.server.SubscriptionsQueries;
import com.juick.server.UserQueries;
import org.apache.commons.lang3.math.NumberUtils;
@@ -17,19 +19,30 @@ import java.util.List;
*/
public class Subscriptions {
JdbcTemplate jdbc;
+ UserSerializer userSerializer = new UserSerializer();
public Subscriptions(JdbcTemplate jdbc) {
this.jdbc = jdbc;
}
public void doGet(HttpServletRequest request, HttpServletResponse response, int vuid) throws IOException {
User visitor = UserQueries.getUserByUID(jdbc, vuid).orElse(new User());
- if (!(visitor.getUID() > 0) && !(visitor.getUName().equals("juick"))) {
+ if ((visitor.getUID() == 0) && !(visitor.getUName().equals("juick"))) {
response.sendError(403);
+ return;
}
int uid = NumberUtils.toInt(request.getParameter("uid"), 0);
int mid = NumberUtils.toInt(request.getParameter("mid"), 0);
- List<User> users = SubscriptionsQueries.getSubscribedUsers(jdbc, uid, mid);
- UserSerializer userSerializer = new UserSerializer();
- Main.replyJSON(request, response, userSerializer.serializeList(users));
+ if (uid > 0) {
+ List<User> users = SubscriptionsQueries.getSubscribedUsers(jdbc, uid, mid);
+ Main.replyJSON(request, response, userSerializer.serializeList(users));
+ } else {
+ // thread
+ Message msg = MessagesQueries.getMessage(jdbc, mid);
+ if (msg != null) {
+ List<User> users = SubscriptionsQueries.getUsersSubscribedToComments(jdbc, mid, msg.getUser().getUID());
+ Main.replyJSON(request, response, userSerializer.serializeList(users));
+ }
+ }
+ response.sendError(400);
}
}