aboutsummaryrefslogtreecommitdiff
path: root/juick-notifications
diff options
context:
space:
mode:
Diffstat (limited to 'juick-notifications')
-rw-r--r--juick-notifications/src/main/java/com/juick/components/Notifications.java54
1 files changed, 22 insertions, 32 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 f41db9e31..e7adac74e 100644
--- a/juick-notifications/src/main/java/com/juick/components/Notifications.java
+++ b/juick-notifications/src/main/java/com/juick/components/Notifications.java
@@ -20,6 +20,7 @@ package com.juick.components;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.android.gcm.server.*;
+import com.juick.TokensList;
import com.juick.components.mpns.MPNSError;
import com.juick.components.mpns.MPNSToken;
import com.notnoop.apns.APNS;
@@ -109,20 +110,29 @@ public class Notifications implements AutoCloseable {
boolean isReply = jmsg.getRid() > 0;
int pmTo = NumberUtils.toInt(msg.getTo().getLocal(), 0);
- /*** ANDROID ***/
- final List<String> regids = new ArrayList<>();
+ final List<TokensList> tokensList = new ArrayList<>();
if (isPM) {
- regids.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=gcm&uid=%d",
+ tokensList.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=gcm&uid=%d",
pmTo),
- HttpMethod.GET, null, new ParameterizedTypeReference<List<String>>() {
+ HttpMethod.GET, null, new ParameterizedTypeReference<List<TokensList>>() {
}).getBody());
} else {
- regids.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=gcm&uid=%s&mid=%s",
- jmsg.getUser().getUid(), jmsg.getMid()),
- HttpMethod.GET, null, new ParameterizedTypeReference<List<String>>() {
- }).getBody());
+ if (isReply) {
+ tokensList.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=gcm&uid=%d&mid=%d&rid=%d",
+ jmsg.getUser().getUid(), jmsg.getMid(), jmsg.getRid()),
+ HttpMethod.GET, null, new ParameterizedTypeReference<List<TokensList>>() {
+ }).getBody());
+ } else {
+ tokensList.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=gcm&uid=%s&mid=%s",
+ jmsg.getUser().getUid(), jmsg.getMid()),
+ HttpMethod.GET, null, new ParameterizedTypeReference<List<TokensList>>() {
+ }).getBody());
+ }
}
+ // GCM
+ List<String> regids = tokensList.stream().filter(t -> t.getType().equals("gcm"))
+ .flatMap(t -> t.getTokens().stream()).collect(Collectors.toList());
if (!regids.isEmpty()) {
try {
ObjectMapper messageSerializer = new ObjectMapper();
@@ -156,18 +166,8 @@ public class Notifications implements AutoCloseable {
}
/*** WinPhone ***/
- final List<String> urls = new ArrayList<>();
- if (isPM) {
- urls.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=mpns&uid=%s",
- pmTo),
- HttpMethod.GET, null, new ParameterizedTypeReference<List<String>>() {
- }).getBody());
- } else {
- urls.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=mpns&uid=%s&mid=%s",
- jmsg.getUser().getUid(), jmsg.getMid()),
- HttpMethod.GET, null, new ParameterizedTypeReference<List<String>>() {
- }).getBody());
- }
+ List<String> urls = tokensList.stream().filter(t -> t.getType().equals("mpns"))
+ .flatMap(t -> t.getTokens().stream()).collect(Collectors.toList());
if (urls.isEmpty()) {
logger.info("WNS: no recipients");
@@ -203,18 +203,8 @@ public class Notifications implements AutoCloseable {
}
/*** iOS ***/
- final List<String> tokens = new ArrayList<>();
- if (isPM) {
- tokens.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=apns&uid=%s",
- pmTo),
- HttpMethod.GET, null, new ParameterizedTypeReference<List<String>>() {
- }).getBody());
- } else {
- tokens.addAll(rest.exchange(String.format("http://api.juick.com/notifications?type=apns&uid=%s&mid=%s",
- jmsg.getUser().getUid(), jmsg.getMid()),
- HttpMethod.GET, null, new ParameterizedTypeReference<List<String>>() {
- }).getBody());
- }
+ List<String> tokens = tokensList.stream().filter(t -> t.getType().equals("mpns"))
+ .flatMap(t -> t.getTokens().stream()).collect(Collectors.toList());
if (!tokens.isEmpty()) {
for (String token : tokens) {
String payload = APNS.newPayload().alertTitle("@" + jmsg.getUser().getName()).alertBody(jmsg.getText()).build();