diff options
author | 2017-10-24 17:18:29 +0300 | |
---|---|---|
committer | 2017-10-24 22:34:41 +0300 | |
commit | de2cc2db73a5de42d9bfaeb92604f28abe2a328a (patch) | |
tree | 352a3d76fcbc987f068527ff043174308a666654 /juick-notifications/src/main/java/com/juick | |
parent | 881a546bf7a56550eec1e38ce839f47a1cb1a750 (diff) |
crosspost: refactoring
* spring-social
* get tokens via service api
Diffstat (limited to 'juick-notifications/src/main/java/com/juick')
-rw-r--r-- | juick-notifications/src/main/java/com/juick/components/Notifications.java | 14 | ||||
-rw-r--r-- | juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java | 6 |
2 files changed, 10 insertions, 10 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 f9d8870f..d160cdc4 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,7 @@ package com.juick.components; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.android.gcm.server.*; -import com.juick.DeviceRegistration; +import com.juick.ExternalToken; import com.juick.User; import com.juick.formatters.PlainTextFormatter; import com.turo.pushy.apns.ApnsClient; @@ -103,8 +103,8 @@ public class Notifications implements NotificationClientListener, AutoCloseable } // GCM - List<String> regids = users.stream().flatMap(u -> u.getDevices().stream()).filter(d -> d.getType().equals("gcm")) - .map(DeviceRegistration::getToken).collect(Collectors.toList()); + List<String> regids = users.stream().flatMap(u -> u.getTokens().stream()).filter(d -> d.getType().equals("gcm")) + .map(ExternalToken::getToken).collect(Collectors.toList()); if (!regids.isEmpty()) { try { String json = jsonMapper.writeValueAsString(jmsg); @@ -134,8 +134,8 @@ public class Notifications implements NotificationClientListener, AutoCloseable } /*** WinPhone ***/ - List<String> urls = users.stream().flatMap(u -> u.getDevices().stream()).filter(d -> d.getType().equals("mpns")) - .map(DeviceRegistration::getToken).collect(Collectors.toList()); + List<String> urls = users.stream().flatMap(u -> u.getTokens().stream()).filter(d -> d.getType().equals("mpns")) + .map(ExternalToken::getToken).collect(Collectors.toList()); if (urls.isEmpty()) { logger.info("WNS: no recipients"); @@ -170,8 +170,8 @@ public class Notifications implements NotificationClientListener, AutoCloseable } /*** iOS ***/ - List<String> tokens = users.stream().flatMap(u -> u.getDevices().stream()).filter(d -> d.getType().equals("apns")) - .map(DeviceRegistration::getToken).collect(Collectors.toList()); + List<String> tokens = users.stream().flatMap(u -> u.getTokens().stream()).filter(d -> d.getType().equals("apns")) + .map(ExternalToken::getToken).collect(Collectors.toList()); if (!tokens.isEmpty()) { ApnsPayloadBuilder apnsPayloadBuilder = new ApnsPayloadBuilder(); String post = PlainTextFormatter.formatPost(jmsg); 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 7b9a88a3..fce52987 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.DeviceRegistration; +import com.juick.ExternalToken; import com.juick.service.BaseRestService; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; @@ -28,8 +28,8 @@ public class NotificationsTokenService extends BaseRestService implements TokenS @Override public void deleteTokens(String type, List<String> devices) { if (devices.size() > 0) { - List<DeviceRegistration> list = devices.stream() - .map(d -> new DeviceRegistration(type, d)).collect(Collectors.toList()); + List<ExternalToken> list = devices.stream() + .map(d -> new ExternalToken(null, null, type, d)).collect(Collectors.toList()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON_UTF8); getRest().exchange("http://api.juick.com/notifications", |