final var profile = profileAndCredential.getProfile();
try {
- account.getIdentityKeyStore()
+ var newIdentity = account.getIdentityKeyStore()
.saveIdentity(recipientId,
new IdentityKey(Base64.getDecoder().decode(profile.getIdentityKey())),
new Date());
+
+ if (newIdentity) {
+ account.getSessionStore().archiveSessions(recipientId);
+ }
} catch (InvalidKeyException ignored) {
logger.warn("Got invalid identity key in profile for {}",
resolveSignalServiceAddress(recipientId).getLegacyIdentifier());
for (var r : result) {
if (r.getIdentityFailure() != null) {
- account.getIdentityKeyStore().
- saveIdentity(resolveRecipient(r.getAddress()),
- r.getIdentityFailure().getIdentityKey(),
- new Date());
+ final var recipientId = resolveRecipient(r.getAddress());
+ final var newIdentity = account.getIdentityKeyStore()
+ .saveIdentity(recipientId, r.getIdentityFailure().getIdentityKey(), new Date());
+ if (newIdentity) {
+ account.getSessionStore().archiveSessions(recipientId);
+ }
}
}