diff options
author | Vitaly Takmazov | 2023-02-04 16:55:12 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-02-10 03:29:41 +0300 |
commit | acd23afcb7e61db7f83872991ae1a4e0f214d667 (patch) | |
tree | 4180f9df774d717c79c7202a280164593b3a475d /src | |
parent | 2d37085b6ed2d1e87b62c62fb5bc9eaaa22f1436 (diff) |
Notifications API: check if token is already exists
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/juick/www/api/Notifications.java | 19 |
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 ac5a635b..df2fb507 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; } } |