From 7c9ae3561df6048f1afc8f87c1f2f72009601f7d Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Fri, 11 Mar 2022 13:46:59 -0800 Subject: [PATCH] Send delivery receipts asynchronously --- .../textsecuregcm/WhisperServerService.java | 4 ++- .../textsecuregcm/push/ReceiptSender.java | 31 ++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index c63301c90..3bdf62676 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -399,6 +399,8 @@ public class WhisperServerService extends Application sendReceipt(AuthenticatedAccount source, UUID destinationUuid, long messageId) throws NoSuchUserException { final Account sourceAccount = source.getAccount(); if (sourceAccount.getUuid().equals(destinationUuid)) { - return; + return CompletableFuture.completedFuture(null); } final Account destinationAccount = accountManager.getByAccountIdentifier(destinationUuid) @@ -45,12 +50,16 @@ public class ReceiptSender { .setTimestamp(messageId) .setType(Envelope.Type.SERVER_DELIVERY_RECEIPT); - for (final Device destinationDevice : destinationAccount.getDevices()) { - try { - messageSender.sendMessage(destinationAccount, destinationDevice, message.build(), false); - } catch (final NotPushRegisteredException e) { - logger.info("User no longer push registered for delivery receipt: " + e.getMessage()); + return CompletableFuture.runAsync(() -> { + for (final Device destinationDevice : destinationAccount.getDevices()) { + try { + messageSender.sendMessage(destinationAccount, destinationDevice, message.build(), false); + } catch (final NotPushRegisteredException e) { + logger.info("User no longer push registered for delivery receipt: " + e.getMessage()); + } catch (final Exception e) { + logger.warn("Could not send delivery receipt", e); + } } - } + }, executor); } }