]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/util/SendMessageResultUtils.java
Bump version to 0.12.3
[signal-cli] / src / main / java / org / asamk / signal / util / SendMessageResultUtils.java
index 74f49534f164747008564d95a1a3ebe4a1971bb4..ecc669e863b6ebfd1699d05f4bff8597a20a12d8 100644 (file)
@@ -1,10 +1,12 @@
 package org.asamk.signal.util;
 
 import org.asamk.signal.commands.exceptions.CommandException;
+import org.asamk.signal.commands.exceptions.RateLimitErrorException;
 import org.asamk.signal.commands.exceptions.UntrustedKeyErrorException;
 import org.asamk.signal.commands.exceptions.UserErrorException;
 import org.asamk.signal.json.JsonSendMessageResult;
 import org.asamk.signal.manager.api.ProofRequiredException;
+import org.asamk.signal.manager.api.RateLimitException;
 import org.asamk.signal.manager.api.RecipientIdentifier;
 import org.asamk.signal.manager.api.SendGroupMessageResults;
 import org.asamk.signal.manager.api.SendMessageResult;
@@ -51,6 +53,9 @@ public class SendMessageResultUtils {
         if (!sendMessageResults.hasSuccess()) {
             if (sendMessageResults.hasOnlyUntrustedIdentity()) {
                 throw new UntrustedKeyErrorException("Failed to send message due to untrusted identities");
+            } else if (sendMessageResults.hasOnlyRateLimitFailure()) {
+                throw new RateLimitErrorException("Failed to send message due to rate limiting",
+                        new RateLimitException(0));
             } else {
                 throw new UserErrorException("Failed to send message");
             }
@@ -84,11 +89,11 @@ public class SendMessageResultUtils {
                             + (
                             failure.getOptions().contains(ProofRequiredException.Option.RECAPTCHA)
                                     ? """
-                                    To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html
-                                    Check the developer tools (F12) console for a failed redirect to signalcaptcha://
-                                    Everything after signalcaptcha:// is the captcha token.
-                                    Use the following command to submit the captcha token:
-                                    signal-cli submitRateLimitChallenge --challenge CHALLENGE_TOKEN --captcha CAPTCHA_TOKEN"""
+                                      To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html
+                                      Check the developer tools (F12) console for a failed redirect to signalcaptcha://
+                                      Everything after signalcaptcha:// is the captcha token.
+                                      Use the following command to submit the captcha token:
+                                      signal-cli submitRateLimitChallenge --challenge CHALLENGE_TOKEN --captcha CAPTCHA_TOKEN"""
                                     : ""
                     ),
                     identifier,
@@ -100,6 +105,8 @@ public class SendMessageResultUtils {
                     failure.getRetryAfterSeconds());
         } else if (result.isNetworkFailure()) {
             return String.format("Network failure for \"%s\"", identifier);
+        } else if (result.isRateLimitFailure()) {
+            return String.format("Rate limit failure for \"%s\"", identifier);
         } else if (result.isUnregisteredFailure()) {
             return String.format("Unregistered user \"%s\"", identifier);
         } else if (result.isIdentityFailure()) {
@@ -109,7 +116,7 @@ public class SendMessageResultUtils {
     }
 
     public static void printSendMessageResultErrors(PlainTextWriter writer, List<String> errors) {
-        if (errors.size() == 0) {
+        if (errors.isEmpty()) {
             return;
         }
         writer.println("Failed to send (some) messages:");