Add support for invalid pre key failure when sending message

This commit is contained in:
AsamK 2023-06-11 17:47:48 +02:00
parent da25b2a763
commit 0c5993c0ad
2 changed files with 9 additions and 23 deletions

View file

@ -2,7 +2,6 @@ package org.asamk.signal.manager.api;
import org.asamk.signal.manager.helper.RecipientAddressResolver; import org.asamk.signal.manager.helper.RecipientAddressResolver;
import org.asamk.signal.manager.storage.recipients.RecipientResolver; import org.asamk.signal.manager.storage.recipients.RecipientResolver;
import org.signal.libsignal.protocol.IdentityKey;
public record SendMessageResult( public record SendMessageResult(
RecipientAddress address, RecipientAddress address,
@ -11,29 +10,12 @@ public record SendMessageResult(
boolean isUnregisteredFailure, boolean isUnregisteredFailure,
boolean isIdentityFailure, boolean isIdentityFailure,
boolean isRateLimitFailure, boolean isRateLimitFailure,
ProofRequiredException proofRequiredFailure ProofRequiredException proofRequiredFailure,
boolean isInvalidPreKeyFailure
) { ) {
public static SendMessageResult success(RecipientAddress address) {
return new SendMessageResult(address, true, false, false, false, false, null);
}
public static SendMessageResult networkFailure(RecipientAddress address) {
return new SendMessageResult(address, false, true, false, false, false, null);
}
public static SendMessageResult unregisteredFailure(RecipientAddress address) { public static SendMessageResult unregisteredFailure(RecipientAddress address) {
return new SendMessageResult(address, false, false, true, false, false, null); return new SendMessageResult(address, false, false, true, false, false, null, false);
}
public static SendMessageResult identityFailure(RecipientAddress address, IdentityKey identityKey) {
return new SendMessageResult(address, false, false, false, true, false, null);
}
public static SendMessageResult proofRequiredFailure(
RecipientAddress address, ProofRequiredException proofRequiredException
) {
return new SendMessageResult(address, false, true, false, false, false, proofRequiredException);
} }
public static SendMessageResult from( public static SendMessageResult from(
@ -50,6 +32,7 @@ public record SendMessageResult(
sendMessageResult.getRateLimitFailure() != null || sendMessageResult.getProofRequiredFailure() != null, sendMessageResult.getRateLimitFailure() != null || sendMessageResult.getProofRequiredFailure() != null,
sendMessageResult.getProofRequiredFailure() == null sendMessageResult.getProofRequiredFailure() == null
? null ? null
: new ProofRequiredException(sendMessageResult.getProofRequiredFailure())); : new ProofRequiredException(sendMessageResult.getProofRequiredFailure()),
sendMessageResult.isInvalidPreKeyFailure());
} }
} }

View file

@ -28,6 +28,8 @@ public record JsonSendMessageResult(
? Type.NETWORK_FAILURE ? Type.NETWORK_FAILURE
: result.isUnregisteredFailure() : result.isUnregisteredFailure()
? Type.UNREGISTERED_FAILURE ? Type.UNREGISTERED_FAILURE
: result.isInvalidPreKeyFailure()
? Type.INVALID_PRE_KEY_FAILURE
: Type.IDENTITY_FAILURE, : Type.IDENTITY_FAILURE,
result.proofRequiredFailure() != null ? result.proofRequiredFailure().getToken() : null, result.proofRequiredFailure() != null ? result.proofRequiredFailure().getToken() : null,
result.proofRequiredFailure() != null ? result.proofRequiredFailure().getRetryAfterSeconds() : null); result.proofRequiredFailure() != null ? result.proofRequiredFailure().getRetryAfterSeconds() : null);
@ -39,5 +41,6 @@ public record JsonSendMessageResult(
UNREGISTERED_FAILURE, UNREGISTERED_FAILURE,
IDENTITY_FAILURE, IDENTITY_FAILURE,
RATE_LIMIT_FAILURE, RATE_LIMIT_FAILURE,
INVALID_PRE_KEY_FAILURE,
} }
} }