mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 06:18:06 +01:00
Assume all accounts have primary devices
This commit is contained in:
committed by
Jon Chambers
parent
69990c23a5
commit
00e72a30c9
@@ -45,7 +45,7 @@ public class PushChallengeManager {
|
||||
}
|
||||
|
||||
public void sendChallenge(final Account account) throws NotPushRegisteredException {
|
||||
final Device primaryDevice = account.getPrimaryDevice().orElseThrow(NotPushRegisteredException::new);
|
||||
final Device primaryDevice = account.getPrimaryDevice();
|
||||
|
||||
final byte[] token = new byte[CHALLENGE_TOKEN_LENGTH];
|
||||
random.nextBytes(token);
|
||||
@@ -86,16 +86,15 @@ public class PushChallengeManager {
|
||||
} catch (final IllegalArgumentException ignored) {
|
||||
}
|
||||
|
||||
final String platform = account.getPrimaryDevice().map(primaryDevice -> {
|
||||
if (StringUtils.isNotBlank(primaryDevice.getGcmId())) {
|
||||
return ClientPlatform.ANDROID.name().toLowerCase();
|
||||
} else if (StringUtils.isNotBlank(primaryDevice.getApnId())) {
|
||||
return ClientPlatform.IOS.name().toLowerCase();
|
||||
} else {
|
||||
return "unknown";
|
||||
}
|
||||
}).orElse("unknown");
|
||||
final String platform;
|
||||
|
||||
if (StringUtils.isNotBlank(account.getPrimaryDevice().getGcmId())) {
|
||||
platform = ClientPlatform.ANDROID.name().toLowerCase();
|
||||
} else if (StringUtils.isNotBlank(account.getPrimaryDevice().getApnId())) {
|
||||
platform = ClientPlatform.IOS.name().toLowerCase();
|
||||
} else {
|
||||
platform = "unknown";
|
||||
}
|
||||
|
||||
Metrics.counter(CHALLENGE_ANSWERED_COUNTER_NAME,
|
||||
PLATFORM_TAG_NAME, platform,
|
||||
|
||||
@@ -62,7 +62,7 @@ public class PushNotificationManager {
|
||||
public void sendRateLimitChallengeNotification(final Account destination, final String challengeToken)
|
||||
throws NotPushRegisteredException {
|
||||
|
||||
final Device device = destination.getDevice(Device.PRIMARY_ID).orElseThrow(NotPushRegisteredException::new);
|
||||
final Device device = destination.getPrimaryDevice();
|
||||
final Pair<String, PushNotification.TokenType> tokenAndType = getToken(device);
|
||||
|
||||
sendNotification(new PushNotification(tokenAndType.first(), tokenAndType.second(),
|
||||
|
||||
@@ -235,10 +235,11 @@ public class Account {
|
||||
return devices;
|
||||
}
|
||||
|
||||
public Optional<Device> getPrimaryDevice() {
|
||||
public Device getPrimaryDevice() {
|
||||
requireNotStale();
|
||||
|
||||
return getDevice(Device.PRIMARY_ID);
|
||||
return getDevice(Device.PRIMARY_ID)
|
||||
.orElseThrow(() -> new IllegalStateException("All accounts must have a primary device"));
|
||||
}
|
||||
|
||||
public Optional<Device> getDevice(final byte deviceId) {
|
||||
@@ -256,7 +257,9 @@ public class Account {
|
||||
public boolean isTransferSupported() {
|
||||
requireNotStale();
|
||||
|
||||
return getPrimaryDevice().map(Device::getCapabilities).map(Device.DeviceCapabilities::transfer).orElse(false);
|
||||
return Optional.ofNullable(getPrimaryDevice().getCapabilities())
|
||||
.map(Device.DeviceCapabilities::transfer)
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
public boolean isPniSupported() {
|
||||
@@ -278,7 +281,7 @@ public class Account {
|
||||
public boolean isEnabled() {
|
||||
requireNotStale();
|
||||
|
||||
return getPrimaryDevice().map(Device::isEnabled).orElse(false);
|
||||
return getPrimaryDevice().isEnabled();
|
||||
}
|
||||
|
||||
public byte getNextDeviceId() {
|
||||
|
||||
Reference in New Issue
Block a user