Do a full recipients refresh every day

This commit is contained in:
AsamK 2023-10-16 17:43:03 +02:00
parent 505de39d2a
commit dd3326f038
3 changed files with 26 additions and 0 deletions

View file

@ -214,6 +214,7 @@ public class RecipientHelper {
}};
account.getCdsiStore().updateAfterFullCdsQuery(fullNumbers, seenNumbers);
account.setCdsiToken(newToken);
account.setLastRecipientsRefresh(System.currentTimeMillis());
}
});
} catch (CdsiInvalidTokenException e) {

View file

@ -115,6 +115,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
@ -215,6 +216,18 @@ public class ManagerImpl implements Manager {
public void checkAccountState() throws IOException {
context.getAccountHelper().checkAccountState();
final var lastRecipientsRefresh = account.getLastRecipientsRefresh();
if (lastRecipientsRefresh == null
|| lastRecipientsRefresh < System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) {
try {
context.getRecipientHelper().refreshUsers();
} catch (Exception e) {
logger.warn("Full CDSI recipients refresh failed, ignoring: {} ({})",
e.getMessage(),
e.getClass().getSimpleName());
logger.debug("Full CDSI refresh failed", e);
}
}
}
@Override

View file

@ -147,6 +147,8 @@ public class SignalAccount implements Closeable {
long.class,
0L);
private final KeyValueEntry<byte[]> cdsiToken = new KeyValueEntry<>("cdsi-token", byte[].class);
private final KeyValueEntry<Long> lastRecipientsRefresh = new KeyValueEntry<>("last-recipients-refresh",
long.class);
private final KeyValueEntry<Long> storageManifestVersion = new KeyValueEntry<>("storage-manifest-version",
long.class,
-1L);
@ -374,6 +376,7 @@ public class SignalAccount implements Closeable {
this.storageKey = null;
trustSelfIdentity(ServiceIdType.ACI);
trustSelfIdentity(ServiceIdType.PNI);
getKeyValueStore().storeEntry(lastRecipientsRefresh, null);
}
public void finishRegistration(
@ -406,6 +409,7 @@ public class SignalAccount implements Closeable {
getRecipientTrustedResolver().resolveSelfRecipientTrusted(getSelfRecipientAddress());
trustSelfIdentity(ServiceIdType.ACI);
trustSelfIdentity(ServiceIdType.PNI);
getKeyValueStore().storeEntry(lastRecipientsRefresh, null);
}
public void initDatabase() {
@ -1586,6 +1590,14 @@ public class SignalAccount implements Closeable {
getKeyValueStore().storeEntry(cdsiToken, value);
}
public Long getLastRecipientsRefresh() {
return getKeyValueStore().getEntry(lastRecipientsRefresh);
}
public void setLastRecipientsRefresh(final Long value) {
getKeyValueStore().storeEntry(lastRecipientsRefresh, value);
}
public ProfileKey getProfileKey() {
return profileKey;
}