aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-10-24 15:55:12 +0300
committerGravatar Vitaly Takmazov2016-10-24 15:55:12 +0300
commitd036163f4eebd357933d51db5e9d4c76a9ac54a9 (patch)
treeef519c9839eebccf9bb49ee23eedcabf49002c21 /juick-api/src/main
parentfee6237f70338f2f960bc3dc614263e2db5dccef (diff)
api: notifications, part 2
Diffstat (limited to 'juick-api/src/main')
-rw-r--r--juick-api/src/main/java/com/juick/api/Notifications.java46
1 files changed, 45 insertions, 1 deletions
diff --git a/juick-api/src/main/java/com/juick/api/Notifications.java b/juick-api/src/main/java/com/juick/api/Notifications.java
index 7cf27fc1..2c846d6f 100644
--- a/juick-api/src/main/java/com/juick/api/Notifications.java
+++ b/juick-api/src/main/java/com/juick/api/Notifications.java
@@ -1,8 +1,11 @@
package com.juick.api;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.juick.Message;
import com.juick.User;
+import com.juick.server.MessagesQueries;
import com.juick.server.PushQueries;
+import com.juick.server.SubscriptionsQueries;
import com.juick.server.UserQueries;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -11,12 +14,15 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
+import java.util.stream.Collectors;
/**
* Created by vitalyster on 24.10.2016.
*/
public class Notifications {
JdbcTemplate jdbc;
+ ObjectMapper mapper = new ObjectMapper();
+
public Notifications(JdbcTemplate jdbc) {
this.jdbc = jdbc;
}
@@ -34,10 +40,48 @@ public class Notifications {
switch (type) {
case "gcm":
List<String> tokens = PushQueries.getAndroidRegID(jdbc, uid);
- ObjectMapper mapper = new ObjectMapper();
Main.replyJSON(request, response, mapper.writeValueAsString(tokens));
+ case "apns":
+ List<String> apnsTokens = PushQueries.getAPNSToken(jdbc, uid);
+ Main.replyJSON(request, response, mapper.writeValueAsString(apnsTokens));
+ case "mpns":
+ List<String> mpnsTokens = PushQueries.getWinPhoneURL(jdbc, uid);
+ Main.replyJSON(request, response, mapper.writeValueAsString(mpnsTokens));
+ default:
+ response.sendError(400);
+ return;
}
+ } else {
+ if (mid > 0) {
+ Message msg = MessagesQueries.getMessage(jdbc, mid);
+ if (msg != null) {
+ List<User> users;
+ if (msg.getRID() > 0) {
+ users = SubscriptionsQueries.getUsersSubscribedToComments(jdbc, mid, msg.getUser().getUID());
+ } else {
+ users = SubscriptionsQueries.getSubscribedUsers(jdbc, msg.getUser().getUID(), mid);
+ }
+
+ List<Integer> uids = users.stream().map(User::getUID).collect(Collectors.toList());
+
+ switch (type) {
+ case "gcm":
+ List<String> tokens = PushQueries.getAndroidTokens(jdbc, uids);
+ Main.replyJSON(request, response, mapper.writeValueAsString(tokens));
+ case "apns":
+ List<String> apnsTokens = PushQueries.getAPNSTokens(jdbc, uids);
+ Main.replyJSON(request, response, mapper.writeValueAsString(apnsTokens));
+ case "mpns":
+ List<String> mpnsTokens = PushQueries.getWindowsTokens(jdbc, uids);
+ Main.replyJSON(request, response, mapper.writeValueAsString(mpnsTokens));
+ default:
+ response.sendError(400);
+ return;
+ }
+ }
+ }
}
+ response.sendError(400);
}
}