Archive recipient's sessions after identity key switch

This commit is contained in:
AsamK 2021-05-04 20:38:00 +02:00
parent 57617accb2
commit 5427fa0132
2 changed files with 19 additions and 5 deletions

View file

@ -601,10 +601,14 @@ public class Manager implements Closeable {
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());
@ -1363,10 +1367,12 @@ public class Manager implements Closeable {
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);
}
}
}

View file

@ -133,6 +133,14 @@ public class SessionStore implements SignalServiceSessionStore {
}
}
public void archiveSessions(final RecipientId recipientId) {
synchronized (cachedSessions) {
getKeysLocked().stream()
.filter(key -> key.recipientId.equals(recipientId))
.forEach(this::archiveSessionLocked);
}
}
public void mergeRecipients(RecipientId recipientId, RecipientId toBeMergedRecipientId) {
synchronized (cachedSessions) {
final var otherHasSession = getKeysLocked(toBeMergedRecipientId).size() > 0;