mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 15:48:05 +01:00
Send push notifications if websockets close before all messages are delivered
This commit is contained in:
@@ -138,21 +138,24 @@ public class MessageSender implements Managed {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
final boolean clientPresent = clientPresenceManager.isPresent(account.getUuid(), device.getId());
|
||||
final boolean clientPresent;
|
||||
|
||||
if (online) {
|
||||
clientPresent = clientPresenceManager.isPresent(account.getUuid(), device.getId());
|
||||
|
||||
if (clientPresent) {
|
||||
messagesManager.insertEphemeral(account.getUuid(), device.getId(), message);
|
||||
}
|
||||
} else {
|
||||
messagesManager.insert(account.getUuid(), device.getId(), message);
|
||||
|
||||
// We check for client presence after inserting the message to take a conservative view of notifications. If the
|
||||
// client wasn't present at the time of insertion but is now, they'll retrieve the message. If they were present
|
||||
// but disconnected before the message was delivered, we should send a notification.
|
||||
clientPresent = clientPresenceManager.isPresent(account.getUuid(), device.getId());
|
||||
|
||||
if (!clientPresent) {
|
||||
if (!Util.isEmpty(device.getGcmId())) {
|
||||
sendGcmNotification(account, device);
|
||||
} else if (!Util.isEmpty(device.getApnId()) || !Util.isEmpty(device.getVoipApnId())) {
|
||||
sendApnNotification(account, device);
|
||||
}
|
||||
sendNewMessageNotification(account, device);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,6 +167,14 @@ public class MessageSender implements Managed {
|
||||
Metrics.counter(SEND_COUNTER_NAME, tags).increment();
|
||||
}
|
||||
|
||||
public void sendNewMessageNotification(final Account account, final Device device) {
|
||||
if (!Util.isEmpty(device.getGcmId())) {
|
||||
sendGcmNotification(account, device);
|
||||
} else if (!Util.isEmpty(device.getApnId()) || !Util.isEmpty(device.getVoipApnId())) {
|
||||
sendApnNotification(account, device);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendGcmNotification(Account account, Device device) {
|
||||
GcmMessage gcmMessage = new GcmMessage(device.getGcmId(), account.getNumber(),
|
||||
(int)device.getId(), GcmMessage.Type.NOTIFICATION, Optional.empty());
|
||||
|
||||
Reference in New Issue
Block a user