Disable unidentified access for recipient if it fails once

This commit is contained in:
AsamK 2021-12-25 16:19:21 +01:00
parent ceb6084eda
commit a0593f4031

View file

@ -526,6 +526,34 @@ public class SendHelper {
} }
private void handleSendMessageResult(final SendMessageResult r) { private void handleSendMessageResult(final SendMessageResult r) {
if (r.isSuccess() && !r.getSuccess().isUnidentified()) {
final var recipientId = recipientResolver.resolveRecipient(r.getAddress());
final var profile = account.getRecipientStore().getProfile(recipientId);
if (profile != null && (
profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.ENABLED
|| profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.UNRESTRICTED
)) {
account.getRecipientStore()
.storeProfile(recipientId,
Profile.newBuilder(profile)
.withUnidentifiedAccessMode(Profile.UnidentifiedAccessMode.UNKNOWN)
.build());
}
}
if (r.isUnregisteredFailure()) {
final var recipientId = recipientResolver.resolveRecipient(r.getAddress());
final var profile = account.getRecipientStore().getProfile(recipientId);
if (profile != null && (
profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.ENABLED
|| profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.UNRESTRICTED
)) {
account.getRecipientStore()
.storeProfile(recipientId,
Profile.newBuilder(profile)
.withUnidentifiedAccessMode(Profile.UnidentifiedAccessMode.UNKNOWN)
.build());
}
}
if (r.getIdentityFailure() != null) { if (r.getIdentityFailure() != null) {
final var recipientId = recipientResolver.resolveRecipient(r.getAddress()); final var recipientId = recipientResolver.resolveRecipient(r.getAddress());
identityFailureHandler.handleIdentityFailure(recipientId, r.getIdentityFailure()); identityFailureHandler.handleIdentityFailure(recipientId, r.getIdentityFailure());