diff options
Diffstat (limited to 'juick-notifications/src/main/java/com/juick/components/CleanUp.java')
-rw-r--r-- | juick-notifications/src/main/java/com/juick/components/CleanUp.java | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/juick-notifications/src/main/java/com/juick/components/CleanUp.java b/juick-notifications/src/main/java/com/juick/components/CleanUp.java index c78b3f77..7b800fec 100644 --- a/juick-notifications/src/main/java/com/juick/components/CleanUp.java +++ b/juick-notifications/src/main/java/com/juick/components/CleanUp.java @@ -1,17 +1,11 @@ package com.juick.components; -import com.juick.TokensList; +import com.juick.components.service.TokenService; import com.notnoop.apns.ApnsService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; import javax.inject.Inject; import java.util.ArrayList; @@ -28,7 +22,10 @@ public class CleanUp { @Inject ApnsService apns; @Inject - RestTemplate rest; + TokenService tokenService; + + @Inject + Notifications push; @Scheduled(fixedRate = 600000) public void cleanupTokens() { @@ -37,16 +34,12 @@ public class CleanUp { int count = devices.size(); if (count > 0) { logger.info("{} tokens to delete", count); - TokensList list = new TokensList(); - list.setType("apns"); - list.setTokens(new ArrayList<>(devices)); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON_UTF8); - rest.exchange("http://api.juick.com/notifications", - HttpMethod.DELETE, new HttpEntity<>(list, headers), new ParameterizedTypeReference<Void>() { - }); + tokenService.deleteTokens("apns", new ArrayList<>(devices)); } else { logger.info("No APNS tokens to delete"); } + logger.debug("initializing GCM tokens cleanup: {} tokens", push.getInvalidGCMTokens().size()); + tokenService.deleteTokens("gcm", push.getInvalidGCMTokens()); + push.cleanupGCMTokens(); } } |