aboutsummaryrefslogtreecommitdiff
path: root/juick-notifications/src/main/java/com/juick/components
diff options
context:
space:
mode:
Diffstat (limited to 'juick-notifications/src/main/java/com/juick/components')
-rw-r--r--juick-notifications/src/main/java/com/juick/components/APNSManager.java83
1 files changed, 38 insertions, 45 deletions
diff --git a/juick-notifications/src/main/java/com/juick/components/APNSManager.java b/juick-notifications/src/main/java/com/juick/components/APNSManager.java
index 314a0bd1..4e5fc01a 100644
--- a/juick-notifications/src/main/java/com/juick/components/APNSManager.java
+++ b/juick-notifications/src/main/java/com/juick/components/APNSManager.java
@@ -40,11 +40,11 @@ public class APNSManager implements NotificationListener {
private String teamId;
@Value("${ios_key_id:}")
private String keyId;
+ @Value("${ios_sandbox_user_id:}")
+ private Integer sandboxUserId;
@Inject
private NotificationsManager notificationsManager;
- private ApnsClient sandboxApns;
-
@PostConstruct
public void initialize() throws NoSuchAlgorithmException, InvalidKeyException, IOException {
apns = new ApnsClientBuilder()
@@ -52,11 +52,6 @@ public class APNSManager implements NotificationListener {
.setSigningKey(ApnsSigningKey.loadFromPkcs8File(new File(p8key),
teamId, keyId))
.build();
- sandboxApns = new ApnsClientBuilder()
- .setApnsServer(ApnsClientBuilder.DEVELOPMENT_APNS_HOST)
- .setSigningKey(ApnsSigningKey.loadFromPkcs8File(new File(p8key),
- teamId, keyId))
- .build();
}
@Override
public void processMessageEvent(MessageEvent messageEvent) {
@@ -71,14 +66,12 @@ public class APNSManager implements NotificationListener {
String post = PlainTextFormatter.formatPost(jmsg);
String[] parts = post.split("\n", 2);
apnsPayloadBuilder.setAlertTitle(parts[0]).setAlertBody(parts[1]);
- users.forEach( user -> {
+ users.stream().filter(u -> u.getUid() != sandboxUserId).forEach( user -> {
apnsPayloadBuilder.setBadgeNumber(user.getUnreadCount());
String payload = apnsPayloadBuilder.buildWithDefaultMaximumLength();
user.getTokens().stream().filter(t -> t.getType().equals("apns"))
.map(ExternalToken::getToken).forEach(token -> {
- Future<PushNotificationResponse<SimpleApnsPushNotification>> notification =
- user.getUid() == 3694 ? sandboxApns.sendNotification(
- new SimpleApnsPushNotification(token, topic, payload)) : apns.sendNotification(
+ Future<PushNotificationResponse<SimpleApnsPushNotification>> notification = apns.sendNotification(
new SimpleApnsPushNotification(token, topic, payload));
notification.addListener((PushNotificationResponseListener<SimpleApnsPushNotification>) future -> {
if (future.isSuccess()) {
@@ -109,47 +102,47 @@ public class APNSManager implements NotificationListener {
@Override
public void processMessageReadEvent(MessageReadEvent messageReadEvent) {
User user = messageReadEvent.getUser();
- ApnsPayloadBuilder apnsPayloadBuilder = new ApnsPayloadBuilder();
- apnsPayloadBuilder.setBadgeNumber(user.getUnreadCount());
- String payload = apnsPayloadBuilder.buildWithDefaultMaximumLength();
- user.getTokens().stream().filter(t -> t.getType().equals("apns"))
- .map(ExternalToken::getToken).forEach(token -> {
- Future<PushNotificationResponse<SimpleApnsPushNotification>> notification =
- user.getUid() == 3694 ? sandboxApns.sendNotification(
- new SimpleApnsPushNotification(token, topic, payload)) : apns.sendNotification(
- new SimpleApnsPushNotification(token, topic, payload));
- notification.addListener((PushNotificationResponseListener<SimpleApnsPushNotification>) future -> {
- if (future.isSuccess()) {
- processAPNSResponse(token, future.getNow());
- } else {
- logger.warn("APNS error ", future.cause());
- }
+ if (user.getUid() != sandboxUserId) {
+ ApnsPayloadBuilder apnsPayloadBuilder = new ApnsPayloadBuilder();
+ apnsPayloadBuilder.setBadgeNumber(user.getUnreadCount());
+ String payload = apnsPayloadBuilder.buildWithDefaultMaximumLength();
+ user.getTokens().stream().filter(t -> t.getType().equals("apns"))
+ .map(ExternalToken::getToken).forEach(token -> {
+ Future<PushNotificationResponse<SimpleApnsPushNotification>> notification = apns.sendNotification(
+ new SimpleApnsPushNotification(token, topic, payload));
+ notification.addListener((PushNotificationResponseListener<SimpleApnsPushNotification>) future -> {
+ if (future.isSuccess()) {
+ processAPNSResponse(token, future.getNow());
+ } else {
+ logger.warn("APNS error ", future.cause());
+ }
+ });
});
- });
+ }
}
@Override
public void processTopEvent(TopEvent topEvent) {
Message message = topEvent.getMessage();
- ApnsPayloadBuilder apnsPayloadBuilder = new ApnsPayloadBuilder();
- message.getUser().getTokens().stream().filter(t -> t.getType().equals("apns"))
- .map(ExternalToken::getToken).forEach( token -> {
- String payload = apnsPayloadBuilder.setAlertTitle("Top").setAlertBody("Your message became popular!")
- .addCustomProperty("mid", message.getMid())
- .addCustomProperty("uname", message.getUser().getName())
- .buildWithDefaultMaximumLength();
- Future<PushNotificationResponse<SimpleApnsPushNotification>> notification =
- message.getUser().getUid() == 3694 ? sandboxApns.sendNotification(
- new SimpleApnsPushNotification(token, topic, payload)) : apns.sendNotification(
- new SimpleApnsPushNotification(token, topic, payload));
- notification.addListener((PushNotificationResponseListener<SimpleApnsPushNotification>) future -> {
- if (future.isSuccess()) {
- processAPNSResponse(token, future.getNow());
- } else {
- logger.warn("APNS error ", future.cause());
- }
+ if (message.getUser().getUid() != sandboxUserId) {
+ ApnsPayloadBuilder apnsPayloadBuilder = new ApnsPayloadBuilder();
+ message.getUser().getTokens().stream().filter(t -> t.getType().equals("apns"))
+ .map(ExternalToken::getToken).forEach(token -> {
+ String payload = apnsPayloadBuilder.setAlertTitle("Top").setAlertBody("Your message became popular!")
+ .addCustomProperty("mid", message.getMid())
+ .addCustomProperty("uname", message.getUser().getName())
+ .buildWithDefaultMaximumLength();
+ Future<PushNotificationResponse<SimpleApnsPushNotification>> notification = apns.sendNotification(
+ new SimpleApnsPushNotification(token, topic, payload));
+ notification.addListener((PushNotificationResponseListener<SimpleApnsPushNotification>) future -> {
+ if (future.isSuccess()) {
+ processAPNSResponse(token, future.getNow());
+ } else {
+ logger.warn("APNS error ", future.cause());
+ }
+ });
});
- });
+ }
}
@PreDestroy