From 0c5993c0adde6b64206ba4f328a5b74e296791f3 Mon Sep 17 00:00:00 2001 From: AsamK Date: Sun, 11 Jun 2023 17:47:48 +0200 Subject: [PATCH] Add support for invalid pre key failure when sending message --- .../signal/manager/api/SendMessageResult.java | 27 ++++--------------- .../signal/json/JsonSendMessageResult.java | 5 +++- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/lib/src/main/java/org/asamk/signal/manager/api/SendMessageResult.java b/lib/src/main/java/org/asamk/signal/manager/api/SendMessageResult.java index 1507390bba..4158b60e7d 100644 --- a/lib/src/main/java/org/asamk/signal/manager/api/SendMessageResult.java +++ b/lib/src/main/java/org/asamk/signal/manager/api/SendMessageResult.java @@ -2,7 +2,6 @@ import org.asamk.signal.manager.helper.RecipientAddressResolver; import org.asamk.signal.manager.storage.recipients.RecipientResolver; -import org.signal.libsignal.protocol.IdentityKey; public record SendMessageResult( RecipientAddress address, @@ -11,29 +10,12 @@ public record SendMessageResult( boolean isUnregisteredFailure, boolean isIdentityFailure, 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) { - return new SendMessageResult(address, false, false, true, false, false, null); - } - - 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); + return new SendMessageResult(address, false, false, true, false, false, null, false); } public static SendMessageResult from( @@ -50,6 +32,7 @@ public static SendMessageResult from( sendMessageResult.getRateLimitFailure() != null || sendMessageResult.getProofRequiredFailure() != null, sendMessageResult.getProofRequiredFailure() == null ? null - : new ProofRequiredException(sendMessageResult.getProofRequiredFailure())); + : new ProofRequiredException(sendMessageResult.getProofRequiredFailure()), + sendMessageResult.isInvalidPreKeyFailure()); } } diff --git a/src/main/java/org/asamk/signal/json/JsonSendMessageResult.java b/src/main/java/org/asamk/signal/json/JsonSendMessageResult.java index 13b953fcee..f9ca8f86d2 100644 --- a/src/main/java/org/asamk/signal/json/JsonSendMessageResult.java +++ b/src/main/java/org/asamk/signal/json/JsonSendMessageResult.java @@ -28,7 +28,9 @@ public static JsonSendMessageResult from(SendMessageResult result, GroupId group ? Type.NETWORK_FAILURE : result.isUnregisteredFailure() ? Type.UNREGISTERED_FAILURE - : Type.IDENTITY_FAILURE, + : result.isInvalidPreKeyFailure() + ? Type.INVALID_PRE_KEY_FAILURE + : Type.IDENTITY_FAILURE, result.proofRequiredFailure() != null ? result.proofRequiredFailure().getToken() : null, result.proofRequiredFailure() != null ? result.proofRequiredFailure().getRetryAfterSeconds() : null); } @@ -39,5 +41,6 @@ public enum Type { UNREGISTERED_FAILURE, IDENTITY_FAILURE, RATE_LIMIT_FAILURE, + INVALID_PRE_KEY_FAILURE, } }