aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/www/api')
-rw-r--r--src/main/java/com/juick/www/api/Notifications.java19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/main/java/com/juick/www/api/Notifications.java b/src/main/java/com/juick/www/api/Notifications.java
index ac5a635b5..df2fb5072 100644
--- a/src/main/java/com/juick/www/api/Notifications.java
+++ b/src/main/java/com/juick/www/api/Notifications.java
@@ -123,9 +123,7 @@ public class Notifications {
if (!visitor.equals(serviceUser)) {
throw new HttpForbiddenException();
}
- list.forEach(t -> {
- userService.deleteToken(t.type(), t.token());
- });
+ list.forEach(t -> userService.deleteToken(t.type(), t.token()));
return Status.OK;
}
@@ -135,8 +133,11 @@ public class Notifications {
public Status doPut(
@Parameter(hidden = true) User visitor,
@RequestBody List<ExternalToken> list) {
+ var userTokens = collectTokens(visitor.getUid());
list.forEach(t -> {
- userService.addToken(visitor.getUid(), t.type(), t.token());
+ if (userTokens.getTokens().stream().noneMatch(existing -> existing.token().equals(t.token()))) {
+ userService.addToken(visitor.getUid(), t.type(), t.token());
+ }
});
return Status.OK;
}
@@ -146,7 +147,10 @@ public class Notifications {
public Status doAndroidRegister(
@Parameter(hidden = true) User visitor,
@RequestParam(name = "regid") String regId) {
- userService.addToken(visitor.getUid(),"fcm", regId);
+ var userTokens = collectTokens(visitor.getUid());
+ if (userTokens.getTokens().stream().noneMatch(existing -> existing.token().equals(regId))) {
+ userService.addToken(visitor.getUid(), "fcm", regId);
+ }
return Status.OK;
}
@@ -155,7 +159,10 @@ public class Notifications {
public Status doWinphoneRegister(
@Parameter(hidden = true) User visitor,
@RequestParam(name = "url") String regId) {
- userService.addToken(visitor.getUid(), "mpns", regId);
+ var userTokens = collectTokens(visitor.getUid());
+ if (userTokens.getTokens().stream().noneMatch(existing -> existing.token().equals(regId))) {
+ userService.addToken(visitor.getUid(), "mpns", regId);
+ }
return Status.OK;
}
}