X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/30690785fd51f9ba841f6f57d5f403bd970f26e3..eee140f74fe9a01972b8d61193c1125c1d89e0df:/src/main/java/org/asamk/signal/util/ErrorUtils.java diff --git a/src/main/java/org/asamk/signal/util/ErrorUtils.java b/src/main/java/org/asamk/signal/util/ErrorUtils.java index fb0509c6..e2454925 100644 --- a/src/main/java/org/asamk/signal/util/ErrorUtils.java +++ b/src/main/java/org/asamk/signal/util/ErrorUtils.java @@ -1,15 +1,17 @@ package org.asamk.signal.util; -import org.asamk.signal.PlainTextWriter; import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.IOErrorException; +import org.asamk.signal.manager.api.RecipientIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.whispersystems.signalservice.api.messages.SendMessageResult; import org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import static org.asamk.signal.util.Util.getLegacyIdentifier; @@ -21,17 +23,28 @@ public class ErrorUtils { private ErrorUtils() { } - public static void handleTimestampAndSendMessageResults( - PlainTextWriter writer, long timestamp, List results + public static void handleSendMessageResults( + Map> mapResults + ) throws CommandException { + List errors = getErrorMessagesFromSendMessageResults(mapResults); + handleSendMessageResultErrors(errors); + } + + public static void handleSendMessageResults( + Collection results ) throws CommandException { - if (timestamp != 0) { - writer.println("{}", timestamp); - } var errors = getErrorMessagesFromSendMessageResults(results); handleSendMessageResultErrors(errors); } - public static List getErrorMessagesFromSendMessageResults(List results) { + public static List getErrorMessagesFromSendMessageResults(final Map> mapResults) { + return mapResults.values() + .stream() + .flatMap(results -> getErrorMessagesFromSendMessageResults(results).stream()) + .collect(Collectors.toList()); + } + + public static List getErrorMessagesFromSendMessageResults(Collection results) { var errors = new ArrayList(); for (var result : results) { var error = getErrorMessageFromSendMessageResult(result); @@ -54,7 +67,17 @@ public class ErrorUtils { } else if (result.getProofRequiredFailure() != null) { final var failure = result.getProofRequiredFailure(); return String.format( - "CAPTCHA proof required for sending to \"%s\", available options \"%s\" with token \"%s\", or wait \"%d\" seconds", + "CAPTCHA proof required for sending to \"%s\", available options \"%s\" with challenge token \"%s\", or wait \"%d\" seconds.\n" + + ( + failure.getOptions().contains(ProofRequiredException.Option.RECAPTCHA) + ? + "To get the captcha token, go to https://signalcaptchas.org/registration/generate.html\n" + + "Check the developer tools (F12) console for a failed redirect to signalcaptcha://\n" + + "Everything after signalcaptcha:// is the captcha token.\n" + + "Use the following command to submit the captcha token:\n" + + "signal-cli submitRateLimitChallenge --challenge CHALLENGE_TOKEN --captcha CAPTCHA_TOKEN" + : "" + ), identifier, failure.getOptions() .stream() @@ -75,6 +98,6 @@ public class ErrorUtils { for (var error : errors) { message.append(error).append("\n"); } - throw new IOErrorException(message.toString()); + throw new IOErrorException(message.toString(), null); } }