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.java45
1 files changed, 13 insertions, 32 deletions
diff --git a/src/main/java/com/juick/www/api/Notifications.java b/src/main/java/com/juick/www/api/Notifications.java
index e5e85eb7..1ebe3c61 100644
--- a/src/main/java/com/juick/www/api/Notifications.java
+++ b/src/main/java/com/juick/www/api/Notifications.java
@@ -19,10 +19,10 @@ package com.juick.www.api;
import com.juick.model.*;
import com.juick.service.*;
-import com.juick.util.HttpBadRequestException;
import com.juick.util.HttpForbiddenException;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Parameter;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
import javax.inject.Inject;
import java.util.Collections;
import java.util.List;
+import java.util.stream.Stream;
/**
* Created by vitalyster on 24.10.2016.
@@ -55,17 +56,12 @@ public class Notifications {
private User collectTokens(Integer uid) {
User user = userService.getUserByUID(uid).orElse(AnonymousUser.INSTANCE);
user.setUnreadCount(messagesService.getUnread(user).size());
- pushQueriesService.getGCMRegID(uid).forEach(t -> user.getTokens().add(new ExternalToken(null, "gcm", t, null)));
- pushQueriesService.getAPNSToken(uid).forEach(t -> user.getTokens().add(new ExternalToken(null, "apns", t, null)));
- pushQueriesService.getMPNSURL(uid).forEach(t -> user.getTokens().add(new ExternalToken(null, "mpns", t, null)));
- List<ExternalToken> xmppJids = userService.getJIDsbyUID(uid).stream()
- .map(jid -> new ExternalToken(null, "xmpp", jid, null))
- .toList();
- user.getTokens().addAll(xmppJids);
- List<ExternalToken> tgIds = telegramService.getTelegramIdentifiers(Collections.singletonList(user)).stream()
- .map(tgId -> new ExternalToken(null, "durov", String.valueOf(tgId), null))
- .toList();
- user.getTokens().addAll(tgIds);
+ var tokens = pushQueriesService.getTokens(List.of(user.getUid()));
+ var xmppJids = userService.getJIDsbyUID(uid).stream()
+ .map(jid -> new ExternalToken(null, "xmpp", jid, null));
+ var tgIds = telegramService.getTelegramIdentifiers(Collections.singletonList(user)).stream()
+ .map(tgId -> new ExternalToken(null, "durov", String.valueOf(tgId), null));
+ user.setTokens(Stream.concat(Stream.concat(tokens.stream(), xmppJids), tgIds).toList());
return user;
}
@@ -117,12 +113,7 @@ public class Notifications {
throw new HttpForbiddenException();
}
list.forEach(t -> {
- switch (t.type()) {
- case "gcm" -> pushQueriesService.deleteGCMToken(t.token());
- case "apns" -> pushQueriesService.deleteAPNSToken(t.token());
- case "mpns" -> pushQueriesService.deleteMPNSToken(t.token());
- default -> throw new HttpBadRequestException();
- }
+ pushQueriesService.deleteToken(t.type(), t.token());
});
return Status.OK;
@@ -136,12 +127,7 @@ public class Notifications {
throw new HttpForbiddenException();
}
list.forEach(t -> {
- switch (t.type()) {
- case "gcm" -> pushQueriesService.deleteGCMToken(t.token());
- case "apns" -> pushQueriesService.deleteAPNSToken(t.token());
- case "mpns" -> pushQueriesService.deleteMPNSToken(t.token());
- default -> throw new HttpBadRequestException();
- }
+ pushQueriesService.deleteToken(t.type(), t.token());
});
return Status.OK;
@@ -153,12 +139,7 @@ public class Notifications {
@Parameter(hidden = true) User visitor,
@RequestBody List<ExternalToken> list) {
list.forEach(t -> {
- switch (t.type()) {
- case "gcm" -> pushQueriesService.addGCMToken(visitor.getUid(), t.token());
- case "apns" -> pushQueriesService.addAPNSToken(visitor.getUid(), t.token());
- case "mpns" -> pushQueriesService.addMPNSToken(visitor.getUid(), t.token());
- default -> throw new HttpBadRequestException();
- }
+ pushQueriesService.addToken(visitor.getUid(), t.type(), t.token());
});
return Status.OK;
}
@@ -168,7 +149,7 @@ public class Notifications {
public Status doAndroidRegister(
@Parameter(hidden = true) User visitor,
@RequestParam(name = "regid") String regId) {
- pushQueriesService.addGCMToken(visitor.getUid(), regId);
+ pushQueriesService.addToken(visitor.getUid(),"fcm", regId);
return Status.OK;
}
@@ -177,7 +158,7 @@ public class Notifications {
public Status doWinphoneRegister(
@Parameter(hidden = true) User visitor,
@RequestParam(name = "url") String regId) {
- pushQueriesService.addMPNSToken(visitor.getUid(), regId);
+ pushQueriesService.addToken(visitor.getUid(), "mpns", regId);
return Status.OK;
}
}