APNS: include a collapse-id for non-VOIP notifications
This has two benefits: - The APNS server should only send an iOS client a single push notification for any missed messages while the device is offline (server-side coalescing). Note that the client can still turn that into multiple "user notifications" as it pulls from its queue. - If multiple notifications get delivered but iOS is unable to process them (say, because the phone just restarted and hasn't been unlocked yet), the user should only get one "You may have received messages" notification (client-side coalescing).
This commit is contained in:
parent
d259ef0348
commit
c367a71223
|
@ -82,7 +82,8 @@ public class APNSender implements Managed {
|
|||
ListenableFuture<ApnResult> future = apnsClient.send(message.getApnId(), topic,
|
||||
message.getMessage(),
|
||||
Instant.ofEpochMilli(message.getExpirationTime()),
|
||||
message.isVoip());
|
||||
message.isVoip(),
|
||||
message.getCollapseId());
|
||||
|
||||
Futures.addCallback(future, new FutureCallback<>() {
|
||||
@Override
|
||||
|
|
|
@ -66,6 +66,14 @@ public class ApnMessage {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getCollapseId() {
|
||||
if (type == Type.NOTIFICATION && !isVoip) {
|
||||
return "incoming-message";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public Optional<String> getChallengeData() {
|
||||
return challengeData;
|
||||
|
|
|
@ -67,9 +67,9 @@ public class RetryingApnsClient {
|
|||
this.apnsClient = apnsClient;
|
||||
}
|
||||
|
||||
ListenableFuture<ApnResult> send(final String apnId, final String topic, final String payload, final Instant expiration, final boolean isVoip) {
|
||||
ListenableFuture<ApnResult> send(final String apnId, final String topic, final String payload, final Instant expiration, final boolean isVoip, final String collapseId) {
|
||||
SettableFuture<ApnResult> result = SettableFuture.create();
|
||||
SimpleApnsPushNotification notification = new SimpleApnsPushNotification(apnId, topic, payload, expiration, DeliveryPriority.IMMEDIATE, isVoip ? PushType.VOIP : PushType.ALERT);
|
||||
SimpleApnsPushNotification notification = new SimpleApnsPushNotification(apnId, topic, payload, expiration, DeliveryPriority.IMMEDIATE, isVoip ? PushType.VOIP : PushType.ALERT, collapseId);
|
||||
|
||||
apnsClient.sendNotification(notification).whenComplete(new ResponseHandler(result));
|
||||
|
||||
|
|
Loading…
Reference in New Issue