aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-22 17:49:03 +0300
committerGravatar Vitaly Takmazov2016-11-22 17:49:03 +0300
commitaa3c1a06ed46f49b617e2956b6cf9a1b0d367fb0 (patch)
tree722163db0e9b060a5c4f7902fd422c0c2b13032e /juick-api/src
parent8b267a3b630f5843623801f42eb90d0ad6a9d849 (diff)
add APNS feedback component
Diffstat (limited to 'juick-api/src')
-rw-r--r--juick-api/src/main/java/com/juick/api/Main.java25
-rw-r--r--juick-api/src/main/java/com/juick/api/Notifications.java17
2 files changed, 42 insertions, 0 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 2bb42e3a..dffb9d66 100644
--- a/juick-api/src/main/java/com/juick/api/Main.java
+++ b/juick-api/src/main/java/com/juick/api/Main.java
@@ -477,6 +477,31 @@ public class Main extends HttpServlet {
Main.replyJSON(request, response, serializer.serialize(jmsg).toString());
}
+ @Override
+ protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ if (req.getCharacterEncoding() == null) {
+ req.setCharacterEncoding("UTF-8");
+ }
+
+ int vuid = Utils.getHttpAuthUID(jdbc, req);
+ if (vuid == 0) {
+ vuid = Utils.getVisitorQueryStringUID(jdbc, req);
+ }
+ if (vuid == 0) {
+ resp.sendError(401);
+ return;
+ }
+ String uri = req.getRequestURI();
+ switch (uri) {
+ case "/notifications":
+ notifications.doDelete(req, resp, vuid);
+ break;
+ default:
+ resp.sendError(400);
+ break;
+ }
+ }
+
public static void replyJSON(HttpServletRequest request, HttpServletResponse response, String json) throws IOException {
response.setContentType("application/json; charset=UTF-8");
response.setHeader("Access-Control-Allow-Origin", "*");
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 a0c9cae9..707df6e4 100644
--- a/juick-api/src/main/java/com/juick/api/Notifications.java
+++ b/juick-api/src/main/java/com/juick/api/Notifications.java
@@ -1,5 +1,6 @@
package com.juick.api;
+import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.juick.Message;
import com.juick.User;
@@ -7,8 +8,10 @@ import com.juick.server.MessagesQueries;
import com.juick.server.PushQueries;
import com.juick.server.SubscriptionsQueries;
import com.juick.server.UserQueries;
+import com.juick.server.helpers.TokensList;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.jdbc.core.JdbcTemplate;
+import spark.utils.IOUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -89,4 +92,18 @@ public class Notifications {
}
}
}
+
+ public void doDelete(HttpServletRequest request, HttpServletResponse response, int vuid) throws IOException {
+ User visitor = UserQueries.getUserByUID(jdbc, vuid).orElse(new User());
+ if ((visitor.getUid() == 0) || !(visitor.getName().equals("juick"))) {
+ response.sendError(403);
+ return;
+ }
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
+ TokensList list = mapper.readValue(IOUtils.toString(request.getInputStream()), TokensList.class);
+ list.getTokens().forEach(t -> PushQueries.deleteAPNSToken(jdbc, t));
+ }
}