Add a dynamic configuration switch to send "you still have messages" notifications immediately

This commit is contained in:
Jon Chambers authored and Jon Chambers committed 2026-10-30 16:18:47 -04:00
1 parent 9049a63038
commit ce75147186
2 files changed
+17 -15

No files matched your search

@@ -5,17 +5,8 @@
package org.whispersystems.textsecuregcm.configuration.dynamic;
import jakarta.validation.constraints.NotNull;
import java.time.Duration;
public record DynamicNotificationConfiguration(@NotNull Duration undeliveredMessagesNotificationDelay) {
public record DynamicNotificationConfiguration(boolean sendRemainingMessagesNotificationImmediately) {
public static final DynamicNotificationConfiguration DEFAULT =
new DynamicNotificationConfiguration(Duration.ofMinutes(1));
public DynamicNotificationConfiguration {
if (undeliveredMessagesNotificationDelay == null) {
undeliveredMessagesNotificationDelay = DEFAULT.undeliveredMessagesNotificationDelay();
}
}
new DynamicNotificationConfiguration(false);
}
@@ -27,12 +27,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration;
import org.whispersystems.textsecuregcm.entities.MessageProtos.Envelope;
import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager;
import org.whispersystems.textsecuregcm.identity.AciServiceIdentifier;
import org.whispersystems.textsecuregcm.identity.ServiceIdentifier;
import org.whispersystems.textsecuregcm.metrics.MessageMetrics;
import org.whispersystems.textsecuregcm.metrics.MetricsUtil;
import org.whispersystems.textsecuregcm.metrics.UserAgentTagUtil;
import org.whispersystems.textsecuregcm.push.NotPushRegisteredException;
import org.whispersystems.textsecuregcm.push.PushNotificationManager;
import org.whispersystems.textsecuregcm.push.PushNotificationScheduler;
import org.whispersystems.textsecuregcm.push.ReceiptSender;
@@ -80,6 +80,8 @@ public class WebSocketConnection {
@VisibleForTesting
static final int MESSAGE_SENDER_MAX_CONCURRENCY = 256;
private static final Duration CLOSE_WITH_PENDING_MESSAGES_NOTIFICATION_DELAY = Duration.ofMinutes(1);
private static final Logger logger = LoggerFactory.getLogger(WebSocketConnection.class);
private static final Logger droppedErrorLogger = LoggerFactory.getLogger("droppedError");
@@ -193,9 +195,18 @@ public class WebSocketConnection {
messagesManager.mayHaveMessages(authenticatedAccount.getAccountIdentifier(), authenticatedDevice)
.thenAccept(mayHaveMessages -> {
if (mayHaveMessages) {
pushNotificationScheduler.scheduleDelayedNotification(authenticatedAccount,
authenticatedDevice,
dynamicConfigurationManager.getConfiguration().getNotificationConfiguration().undeliveredMessagesNotificationDelay());
if (dynamicConfigurationManager.getConfiguration().getNotificationConfiguration().sendRemainingMessagesNotificationImmediately()) {
try {
pushNotificationManager.sendNewMessageNotification(authenticatedAccount,
authenticatedDevice.getId(),
true);
} catch (NotPushRegisteredException _) {
}
} else {
pushNotificationScheduler.scheduleDelayedNotification(authenticatedAccount,
authenticatedDevice,
CLOSE_WITH_PENDING_MESSAGES_NOTIFICATION_DELAY);
}
}
});
}