+ private void handlePossibleIdentityFailure(final SendMessageResult r) {
+ if (r.getIdentityFailure() != null) {
+ final var recipientId = resolveRecipient(r.getAddress());
+ final var identityKey = r.getIdentityFailure().getIdentityKey();
+ if (identityKey != null) {
+ final var newIdentity = account.getIdentityKeyStore()
+ .saveIdentity(recipientId, identityKey, new Date());
+ if (newIdentity) {
+ account.getSessionStore().archiveSessions(recipientId);
+ }
+ } else {
+ // Retrieve profile to get the current identity key from the server
+ retrieveEncryptedProfile(recipientId);
+ }
+ }
+ }
+