Skip to content

Commit

Permalink
Add support for invalid pre key failure when sending message
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamK committed Jun 11, 2023
1 parent da25b2a commit 0c5993c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -39,5 +41,6 @@ public enum Type {
UNREGISTERED_FAILURE,
IDENTITY_FAILURE,
RATE_LIMIT_FAILURE,
INVALID_PRE_KEY_FAILURE,
}
}

0 comments on commit 0c5993c

Please sign in to comment.