From de2cc2db73a5de42d9bfaeb92604f28abe2a328a Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 24 Oct 2017 17:18:29 +0300 Subject: crosspost: refactoring * spring-social * get tokens via service api --- .../src/main/java/com/juick/components/Notifications.java | 14 +++++++------- .../components/service/NotificationsTokenService.java | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'juick-notifications/src') 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 regids = users.stream().flatMap(u -> u.getDevices().stream()).filter(d -> d.getType().equals("gcm")) - .map(DeviceRegistration::getToken).collect(Collectors.toList()); + List 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 urls = users.stream().flatMap(u -> u.getDevices().stream()).filter(d -> d.getType().equals("mpns")) - .map(DeviceRegistration::getToken).collect(Collectors.toList()); + List 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 tokens = users.stream().flatMap(u -> u.getDevices().stream()).filter(d -> d.getType().equals("apns")) - .map(DeviceRegistration::getToken).collect(Collectors.toList()); + List 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 devices) { if (devices.size() > 0) { - List list = devices.stream() - .map(d -> new DeviceRegistration(type, d)).collect(Collectors.toList()); + List 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", -- cgit v1.2.3