parent
26b552a12e
commit
7b60ae26fc
|
@ -87,11 +87,11 @@ public class PushSender implements Managed {
|
|||
}
|
||||
}
|
||||
|
||||
public void sendQueuedNotification(Account account, Device device, int messageQueueDepth)
|
||||
public void sendQueuedNotification(Account account, Device device, int messageQueueDepth, boolean fallback)
|
||||
throws NotPushRegisteredException, TransientPushFailureException
|
||||
{
|
||||
if (device.getGcmId() != null) sendGcmNotification(account, device);
|
||||
else if (device.getApnId() != null) sendApnNotification(account, device, messageQueueDepth);
|
||||
else if (device.getApnId() != null) sendApnNotification(account, device, messageQueueDepth, fallback);
|
||||
else if (!device.getFetchesMessages()) throw new NotPushRegisteredException("No notification possible!");
|
||||
}
|
||||
|
||||
|
@ -129,11 +129,12 @@ public class PushSender implements Managed {
|
|||
DeliveryStatus deliveryStatus = webSocketSender.sendMessage(account, device, outgoingMessage, WebsocketSender.Type.APN);
|
||||
|
||||
if (!deliveryStatus.isDelivered() && outgoingMessage.getType() != Envelope.Type.RECEIPT) {
|
||||
sendApnNotification(account, device, deliveryStatus.getMessageQueueDepth());
|
||||
boolean fallback = !outgoingMessage.getSource().equals(account.getNumber());
|
||||
sendApnNotification(account, device, deliveryStatus.getMessageQueueDepth(), fallback);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendApnNotification(Account account, Device device, int messageQueueDepth) {
|
||||
private void sendApnNotification(Account account, Device device, int messageQueueDepth, boolean fallback) {
|
||||
ApnMessage apnMessage;
|
||||
|
||||
if (!Util.isEmpty(device.getVoipApnId())) {
|
||||
|
@ -141,8 +142,10 @@ public class PushSender implements Managed {
|
|||
String.format(APN_PAYLOAD, messageQueueDepth),
|
||||
true, System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(30));
|
||||
|
||||
apnFallbackManager.schedule(new WebsocketAddress(account.getNumber(), device.getId()),
|
||||
new ApnFallbackTask(device.getApnId(), apnMessage));
|
||||
if (fallback) {
|
||||
apnFallbackManager.schedule(new WebsocketAddress(account.getNumber(), device.getId()),
|
||||
new ApnFallbackTask(device.getApnId(), apnMessage));
|
||||
}
|
||||
} else {
|
||||
apnMessage = new ApnMessage(device.getApnId(), account.getNumber(), (int)device.getId(),
|
||||
String.format(APN_PAYLOAD, messageQueueDepth),
|
||||
|
|
|
@ -140,10 +140,11 @@ public class WebSocketConnection implements DispatchChannel {
|
|||
}
|
||||
|
||||
private void requeueMessage(Envelope message) {
|
||||
int queueDepth = pushSender.getWebSocketSender().queueMessage(account, device, message);
|
||||
int queueDepth = pushSender.getWebSocketSender().queueMessage(account, device, message);
|
||||
boolean fallback = !message.getSource().equals(account.getNumber());
|
||||
|
||||
try {
|
||||
pushSender.sendQueuedNotification(account, device, queueDepth);
|
||||
pushSender.sendQueuedNotification(account, device, queueDepth, fallback);
|
||||
} catch (NotPushRegisteredException | TransientPushFailureException e) {
|
||||
logger.warn("requeueMessage", e);
|
||||
}
|
||||
|
|
|
@ -250,7 +250,7 @@ public class WebSocketConnectionTest {
|
|||
|
||||
verify(receiptSender, times(1)).sendReceipt(eq(account), eq("sender2"), eq(secondMessage.getTimestamp()), eq(Optional.<String>absent()));
|
||||
verify(websocketSender, times(1)).queueMessage(eq(account), eq(device), any(Envelope.class));
|
||||
verify(pushSender, times(1)).sendQueuedNotification(eq(account), eq(device), eq(10));
|
||||
verify(pushSender, times(1)).sendQueuedNotification(eq(account), eq(device), eq(10), eq(true));
|
||||
|
||||
connection.onDispatchUnsubscribed(websocketAddress.serialize());
|
||||
verify(client).close(anyInt(), anyString());
|
||||
|
|
Loading…
Reference in New Issue