mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 11:28:05 +01:00
Remove ZeroTtlDevicePushNotificationExperiment
This commit is contained in:
@@ -78,13 +78,11 @@ public class FcmSender implements PushNotificationSender {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<SendPushNotificationResult> sendNotification(PushNotification pushNotification) {
|
||||
final AndroidConfig.Builder androidConfig = AndroidConfig.builder()
|
||||
.setPriority(pushNotification.urgent() ? AndroidConfig.Priority.HIGH : AndroidConfig.Priority.NORMAL);
|
||||
pushNotification.ttl().ifPresent(androidConfig::setTtl);
|
||||
|
||||
Message.Builder builder = Message.builder()
|
||||
.setToken(pushNotification.deviceToken())
|
||||
.setAndroidConfig(androidConfig.build());
|
||||
.setAndroidConfig(AndroidConfig.builder()
|
||||
.setPriority(pushNotification.urgent() ? AndroidConfig.Priority.HIGH : AndroidConfig.Priority.NORMAL)
|
||||
.build());
|
||||
|
||||
final String key = switch (pushNotification.notificationType()) {
|
||||
case NOTIFICATION -> "newMessageAlert";
|
||||
|
||||
@@ -8,7 +8,6 @@ package org.whispersystems.textsecuregcm.push;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
|
||||
public record PushNotification(String deviceToken,
|
||||
TokenType tokenType,
|
||||
@@ -16,8 +15,7 @@ public record PushNotification(String deviceToken,
|
||||
@Nullable String data,
|
||||
@Nullable Account destination,
|
||||
@Nullable Device destinationDevice,
|
||||
boolean urgent,
|
||||
Optional<Long> ttl) {
|
||||
boolean urgent) {
|
||||
|
||||
public enum NotificationType {
|
||||
NOTIFICATION,
|
||||
|
||||
@@ -51,19 +51,11 @@ public class PushNotificationManager {
|
||||
final Pair<String, PushNotification.TokenType> tokenAndType = getToken(device);
|
||||
|
||||
return sendNotification(new PushNotification(tokenAndType.first(), tokenAndType.second(),
|
||||
PushNotification.NotificationType.NOTIFICATION, null, destination, device, urgent, Optional.empty()));
|
||||
}
|
||||
|
||||
public CompletableFuture<Optional<SendPushNotificationResult>> sendNewMessageNotificationWithTtl(final Account destination, final byte destinationDeviceId, final boolean urgent, long ttl) throws NotPushRegisteredException {
|
||||
final Device device = destination.getDevice(destinationDeviceId).orElseThrow(NotPushRegisteredException::new);
|
||||
final Pair<String, PushNotification.TokenType> tokenAndType = getToken(device);
|
||||
|
||||
return sendNotification(new PushNotification(tokenAndType.first(), tokenAndType.second(),
|
||||
PushNotification.NotificationType.NOTIFICATION, null, destination, device, urgent, Optional.of(ttl)));
|
||||
PushNotification.NotificationType.NOTIFICATION, null, destination, device, urgent));
|
||||
}
|
||||
|
||||
public CompletableFuture<SendPushNotificationResult> sendRegistrationChallengeNotification(final String deviceToken, final PushNotification.TokenType tokenType, final String challengeToken) {
|
||||
return sendNotification(new PushNotification(deviceToken, tokenType, PushNotification.NotificationType.CHALLENGE, challengeToken, null, null, true, Optional.empty()))
|
||||
return sendNotification(new PushNotification(deviceToken, tokenType, PushNotification.NotificationType.CHALLENGE, challengeToken, null, null, true))
|
||||
.thenApply(maybeResponse -> maybeResponse.orElseThrow(() -> new AssertionError("Responses must be present for urgent notifications")));
|
||||
}
|
||||
|
||||
@@ -74,7 +66,7 @@ public class PushNotificationManager {
|
||||
final Pair<String, PushNotification.TokenType> tokenAndType = getToken(device);
|
||||
|
||||
return sendNotification(new PushNotification(tokenAndType.first(), tokenAndType.second(),
|
||||
PushNotification.NotificationType.RATE_LIMIT_CHALLENGE, challengeToken, destination, device, true, Optional.empty()))
|
||||
PushNotification.NotificationType.RATE_LIMIT_CHALLENGE, challengeToken, destination, device, true))
|
||||
.thenApply(maybeResponse -> maybeResponse.orElseThrow(() -> new AssertionError("Responses must be present for urgent notifications")));
|
||||
}
|
||||
|
||||
@@ -84,7 +76,7 @@ public class PushNotificationManager {
|
||||
|
||||
return sendNotification(new PushNotification(tokenAndType.first(), tokenAndType.second(),
|
||||
PushNotification.NotificationType.ATTEMPT_LOGIN_NOTIFICATION_HIGH_PRIORITY,
|
||||
context, destination, device, true, Optional.empty()))
|
||||
context, destination, device, true))
|
||||
.thenApply(maybeResponse -> maybeResponse.orElseThrow(() -> new AssertionError("Responses must be present for urgent notifications")));
|
||||
}
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ public class PushNotificationScheduler implements Managed {
|
||||
return pushSchedulingCluster.withCluster(connection -> connection.async().set(
|
||||
getLastBackgroundApnsNotificationTimestampKey(account, device),
|
||||
String.valueOf(clock.millis()), new SetArgs().ex(BACKGROUND_NOTIFICATION_PERIOD)))
|
||||
.thenCompose(ignored -> apnSender.sendNotification(new PushNotification(device.getApnId(), PushNotification.TokenType.APN, PushNotification.NotificationType.NOTIFICATION, null, account, device, false, Optional.empty())))
|
||||
.thenCompose(ignored -> apnSender.sendNotification(new PushNotification(device.getApnId(), PushNotification.TokenType.APN, PushNotification.NotificationType.NOTIFICATION, null, account, device, false)))
|
||||
.thenAccept(response -> Metrics.counter(BACKGROUND_NOTIFICATION_SENT_COUNTER_NAME,
|
||||
ACCEPTED_TAG, String.valueOf(response.accepted()))
|
||||
.increment())
|
||||
@@ -308,8 +308,7 @@ public class PushNotificationScheduler implements Managed {
|
||||
null,
|
||||
account,
|
||||
device,
|
||||
true,
|
||||
Optional.empty());
|
||||
true);
|
||||
|
||||
final PushNotificationSender pushNotificationSender = isApnsDevice ? apnSender : fcmSender;
|
||||
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
package org.whispersystems.textsecuregcm.push;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import java.io.IOException;
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalTime;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import javax.annotation.Nullable;
|
||||
import org.whispersystems.textsecuregcm.identity.IdentityType;
|
||||
import org.whispersystems.textsecuregcm.scheduler.JobScheduler;
|
||||
import org.whispersystems.textsecuregcm.scheduler.SchedulingUtil;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
|
||||
|
||||
public class ZeroTtlNotificationScheduler extends JobScheduler {
|
||||
|
||||
private final AccountsManager accountsManager;
|
||||
private final PushNotificationManager pushNotificationManager;
|
||||
private final Clock clock;
|
||||
|
||||
@VisibleForTesting
|
||||
record JobDescriptor(UUID accountIdentifier, byte deviceId, long lastSeen, boolean zeroTtl) {}
|
||||
|
||||
public ZeroTtlNotificationScheduler(
|
||||
final AccountsManager accountsManager,
|
||||
final PushNotificationManager pushNotificationManager,
|
||||
final DynamoDbAsyncClient dynamoDbAsyncClient,
|
||||
final String tableName,
|
||||
final Duration jobExpiration,
|
||||
final Clock clock) {
|
||||
|
||||
super(dynamoDbAsyncClient, tableName, jobExpiration, clock);
|
||||
|
||||
this.accountsManager = accountsManager;
|
||||
this.pushNotificationManager = pushNotificationManager;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSchedulerName() {
|
||||
return "ZeroTtlNotification";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CompletableFuture<String> processJob(@Nullable final byte[] jobData) {
|
||||
final JobDescriptor jobDescriptor;
|
||||
|
||||
try {
|
||||
jobDescriptor = SystemMapper.jsonMapper().readValue(jobData, JobDescriptor.class);
|
||||
} catch (final IOException e) {
|
||||
return CompletableFuture.failedFuture(e);
|
||||
}
|
||||
|
||||
return accountsManager.getByAccountIdentifierAsync(jobDescriptor.accountIdentifier())
|
||||
.thenCompose(maybeAccount -> maybeAccount.map(account ->
|
||||
account.getDevice(jobDescriptor.deviceId()).map(device -> {
|
||||
if (jobDescriptor.lastSeen() != device.getLastSeen()) {
|
||||
return CompletableFuture.completedFuture("deviceSeenRecently");
|
||||
}
|
||||
|
||||
try {
|
||||
return sendNotification(account, jobDescriptor)
|
||||
.thenApply(ignored -> "sent");
|
||||
} catch (final NotPushRegisteredException e) {
|
||||
return CompletableFuture.completedFuture("deviceTokenDeleted");
|
||||
}
|
||||
})
|
||||
.orElse(CompletableFuture.completedFuture("deviceDeleted")))
|
||||
.orElse(CompletableFuture.completedFuture("accountDeleted")));
|
||||
}
|
||||
|
||||
private CompletableFuture<Optional<SendPushNotificationResult>> sendNotification(final Account account,
|
||||
final JobDescriptor jobDescriptor) throws NotPushRegisteredException {
|
||||
return jobDescriptor.zeroTtl()
|
||||
? pushNotificationManager.sendNewMessageNotificationWithTtl(account, jobDescriptor.deviceId(), true, 0L)
|
||||
: pushNotificationManager.sendNewMessageNotification(account, jobDescriptor.deviceId(), true);
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> scheduleNotification(final Account account, final Device device,
|
||||
final LocalTime preferredDeliveryTime, boolean zeroTtl) {
|
||||
final Instant runAt = SchedulingUtil.getNextRecommendedNotificationTime(account, preferredDeliveryTime, clock);
|
||||
|
||||
try {
|
||||
return scheduleJob(runAt, SystemMapper.jsonMapper().writeValueAsBytes(
|
||||
new JobDescriptor(account.getIdentifier(IdentityType.ACI), device.getId(), device.getLastSeen(), zeroTtl)));
|
||||
} catch (final JsonProcessingException e) {
|
||||
// This should never happen when serializing an `AccountAndDeviceIdentifier`
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user