aboutsummaryrefslogtreecommitdiff
path: root/juick-notifications/src/main/java/com/juick/components
diff options
context:
space:
mode:
Diffstat (limited to 'juick-notifications/src/main/java/com/juick/components')
-rw-r--r--juick-notifications/src/main/java/com/juick/components/Notifications.java29
-rw-r--r--juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java3
-rw-r--r--juick-notifications/src/main/java/com/juick/components/configuration/NotificationsMvcConfiguration.java28
-rw-r--r--juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java8
4 files changed, 21 insertions, 47 deletions
diff --git a/juick-notifications/src/main/java/com/juick/components/Notifications.java b/juick-notifications/src/main/java/com/juick/components/Notifications.java
index 0a315f76..f0ab3b81 100644
--- a/juick-notifications/src/main/java/com/juick/components/Notifications.java
+++ b/juick-notifications/src/main/java/com/juick/components/Notifications.java
@@ -19,7 +19,8 @@ package com.juick.components;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.android.gcm.server.*;
-import com.juick.TokensList;
+import com.juick.DeviceRegistration;
+import com.juick.User;
import com.notnoop.apns.APNS;
import com.notnoop.apns.ApnsService;
import org.apache.commons.lang3.math.NumberUtils;
@@ -72,29 +73,29 @@ public class Notifications implements NotificationClientListener, AutoCloseable
boolean isReply = jmsg.getRid() > 0;
int pmTo = NumberUtils.toInt(msg.getTo().getLocal(), 0);
- final List<TokensList> tokensList = new ArrayList<>();
+ final List<User> users = new ArrayList<>();
if (isPM) {
- tokensList.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=gcm&uid=%d",
+ users.addAll(rest.exchange(String.format("http://api.juick.com/notifications?uid=%d",
pmTo),
- HttpMethod.GET, null, new ParameterizedTypeReference<List<TokensList>>() {
+ HttpMethod.GET, null, new ParameterizedTypeReference<List<User>>() {
}).getBody());
} else {
if (isReply) {
- tokensList.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=gcm&uid=%d&mid=%d&rid=%d",
+ users.addAll(rest.exchange(String.format("http://api.juick.com/notifications?uid=%d&mid=%d&rid=%d",
jmsg.getUser().getUid(), jmsg.getMid(), jmsg.getRid()),
- HttpMethod.GET, null, new ParameterizedTypeReference<List<TokensList>>() {
+ HttpMethod.GET, null, new ParameterizedTypeReference<List<User>>() {
}).getBody());
} else {
- tokensList.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=gcm&uid=%s&mid=%s",
+ users.addAll(rest.exchange(String.format("http://api.juick.com/notifications?uid=%s&mid=%s",
jmsg.getUser().getUid(), jmsg.getMid()),
- HttpMethod.GET, null, new ParameterizedTypeReference<List<TokensList>>() {
+ HttpMethod.GET, null, new ParameterizedTypeReference<List<User>>() {
}).getBody());
}
}
// GCM
- List<String> regids = tokensList.stream().filter(t -> t.getType().equals("gcm"))
- .flatMap(t -> t.getTokens().stream()).collect(Collectors.toList());
+ List<String> regids = users.stream().flatMap(u -> u.getDevices().stream()).filter(d -> d.getType().equals("gcm"))
+ .map(DeviceRegistration::getToken).collect(Collectors.toList());
if (!regids.isEmpty()) {
try {
String json = jsonMapper.writeValueAsString(jmsg);
@@ -124,8 +125,8 @@ public class Notifications implements NotificationClientListener, AutoCloseable
}
/*** WinPhone ***/
- List<String> urls = tokensList.stream().filter(t -> t.getType().equals("mpns"))
- .flatMap(t -> t.getTokens().stream()).collect(Collectors.toList());
+ List<String> urls = users.stream().flatMap(u -> u.getDevices().stream()).filter(d -> d.getType().equals("mpns"))
+ .map(DeviceRegistration::getToken).collect(Collectors.toList());
if (urls.isEmpty()) {
logger.info("WNS: no recipients");
@@ -160,8 +161,8 @@ public class Notifications implements NotificationClientListener, AutoCloseable
}
/*** iOS ***/
- List<String> tokens = tokensList.stream().filter(t -> t.getType().equals("apns"))
- .flatMap(t -> t.getTokens().stream()).collect(Collectors.toList());
+ List<String> tokens = users.stream().flatMap(u -> u.getDevices().stream()).filter(d -> d.getType().equals("apns"))
+ .map(DeviceRegistration::getToken).collect(Collectors.toList());
if (!tokens.isEmpty()) {
for (String token : tokens) {
String payload = APNS.newPayload().alertTitle("@" + jmsg.getUser().getName()).alertBody(jmsg.getText()).build();
diff --git a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java
index 4249d988..8ecf72ea 100644
--- a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java
+++ b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java
@@ -1,5 +1,6 @@
package com.juick.components.configuration;
+import com.juick.server.configuration.BaseWebConfiguration;
import org.apache.commons.codec.CharEncoding;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
@@ -21,7 +22,7 @@ public class NotificationsInitializer extends AbstractAnnotationConfigDispatcher
@Override
protected Class<?>[] getServletConfigClasses() {
- return new Class<?>[]{NotificationsMvcConfiguration.class};
+ return new Class<?>[]{ BaseWebConfiguration.class };
}
@Override
diff --git a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsMvcConfiguration.java b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsMvcConfiguration.java
deleted file mode 100644
index 3d828832..00000000
--- a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsMvcConfiguration.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.juick.components.configuration;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.converter.HttpMessageConverter;
-import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
-
-import javax.inject.Inject;
-import java.util.List;
-
-/**
- * Created by vitalyster on 28.06.2016.
- */
-@Configuration
-@ComponentScan(basePackages = {"com.juick.components.controllers"})
-public class NotificationsMvcConfiguration extends WebMvcConfigurationSupport {
- @Inject
- ObjectMapper jsonMapper;
-
- @Override
- protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
- MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(jsonMapper);
- converters.add(converter);
- super.configureMessageConverters(converters);
- }
-}
diff --git a/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java b/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
index 4dd949c3..7b9a88a3 100644
--- a/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
+++ b/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
@@ -1,6 +1,6 @@
package com.juick.components.service;
-import com.juick.TokensList;
+import com.juick.DeviceRegistration;
import com.juick.service.BaseRestService;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
@@ -12,6 +12,7 @@ import org.springframework.web.client.RestTemplate;
import javax.inject.Inject;
import java.util.List;
+import java.util.stream.Collectors;
/**
* Created by vitalyster on 15.12.2016.
@@ -27,9 +28,8 @@ public class NotificationsTokenService extends BaseRestService implements TokenS
@Override
public void deleteTokens(String type, List<String> devices) {
if (devices.size() > 0) {
- TokensList list = new TokensList();
- list.setType(type);
- list.setTokens(devices);
+ List<DeviceRegistration> list = devices.stream()
+ .map(d -> new DeviceRegistration(type, d)).collect(Collectors.toList());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
getRest().exchange("http://api.juick.com/notifications",