Update `AccountsManager` mismatch comparison

This commit is contained in:
Chris Eager 2021-08-13 12:53:36 -05:00 committed by Chris Eager
parent 2e28fb97a4
commit a398e2269c
2 changed files with 13 additions and 6 deletions

View File

@ -665,11 +665,6 @@ public class AccountsManager {
dynamoAccount.getMasterDevice().get().getSignedPreKey())) {
return Optional.of("masterDeviceSignedPreKey");
}
if (!Objects.equals(databaseAccount.getMasterDevice().get().getPushTimestamp(),
dynamoAccount.getMasterDevice().get().getPushTimestamp())) {
return Optional.of("masterDevicePushTimestamp");
}
}
try {
@ -681,6 +676,15 @@ public class AccountsManager {
return Optional.of("version");
}
if (databaseAccount.getMasterDevice().isPresent() && dynamoAccount.getMasterDevice().isPresent()) {
if (Math.abs(databaseAccount.getMasterDevice().get().getPushTimestamp() -
dynamoAccount.getMasterDevice().get().getPushTimestamp()) > 60 * 1_000L) {
// These are generally few milliseconds off, because the setter uses System.currentTimeMillis() internally,
// but we can be more relaxed
return Optional.of("masterDevicePushTimestamp");
}
}
if (!serializedEquals(databaseAccount, dynamoAccount)) {
return Optional.of("serialization");
}
@ -756,6 +760,9 @@ public class AccountsManager {
@JsonIgnore
private long lastSeen;
@JsonIgnore
private long pushTimestamp;
}
private boolean serializedEquals(final Object database, final Object dynamo) throws JsonProcessingException {

View File

@ -513,7 +513,7 @@ class AccountsManagerTest {
Thread.sleep(5);
device2.setApnId("123");
assertEquals(Optional.of("masterDevicePushTimestamp"), accountsManager.compareAccounts(Optional.of(a1), Optional.of(a2)));
assertEquals(Optional.empty(), accountsManager.compareAccounts(Optional.of(a1), Optional.of(a2)));
a1.removeDevice(1L);
a2.removeDevice(1L);