package org.asamk.signal.util;
+import org.asamk.signal.commands.exceptions.CommandException;
+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.RecipientIdentifier;
}
}
- public static void outputResult(final OutputWriter outputWriter, final SendMessageResults sendMessageResults) {
+ public static void outputResult(
+ final OutputWriter outputWriter, final SendMessageResults sendMessageResults
+ ) throws CommandException {
if (outputWriter instanceof PlainTextWriter writer) {
var errors = getErrorMessagesFromSendMessageResults(sendMessageResults.results());
printSendMessageResultErrors(writer, errors);
var results = getJsonSendMessageResults(sendMessageResults.results());
writer.write(Map.of("timestamp", sendMessageResults.timestamp(), "results", results));
}
+ if (!sendMessageResults.hasSuccess()) {
+ if (sendMessageResults.hasOnlyUntrustedIdentity()) {
+ throw new UntrustedKeyErrorException("Failed to send message due to untrusted identities");
+ } else {
+ throw new UserErrorException("Failed to send message");
+ }
+ }
}
public static List<String> getErrorMessagesFromSendMessageResults(final Map<RecipientIdentifier, List<SendMessageResult>> mapResults) {
.map(SendMessageResultUtils::getErrorMessageFromSendMessageResult)
.filter(Objects::nonNull)
.map(error -> entry.getKey().getIdentifier() + ": " + error))
- .collect(Collectors.toList());
+ .toList();
}
public static List<String> getErrorMessagesFromSendMessageResults(Collection<SendMessageResult> results) {
return results.stream()
.map(SendMessageResultUtils::getErrorMessageFromSendMessageResult)
.filter(Objects::nonNull)
- .collect(Collectors.toList());
+ .toList();
}
public static String getErrorMessageFromSendMessageResult(SendMessageResult result) {
+ (
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,
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()) {
}
}
- public static List<JsonSendMessageResult> getJsonSendMessageResults(final Map<RecipientIdentifier, List<SendMessageResult>> mapResults) {
+ private static List<JsonSendMessageResult> getJsonSendMessageResults(final Map<RecipientIdentifier, List<SendMessageResult>> mapResults) {
return mapResults.entrySet().stream().flatMap(entry -> {
final var groupId = entry.getKey() instanceof RecipientIdentifier.Group g ? g.groupId() : null;
return entry.getValue().stream().map(r -> JsonSendMessageResult.from(r, groupId));
- }).collect(Collectors.toList());
+ }).toList();
}
public static List<JsonSendMessageResult> getJsonSendMessageResults(Collection<SendMessageResult> results) {
- return results.stream().map(JsonSendMessageResult::from).collect(Collectors.toList());
+ return results.stream().map(JsonSendMessageResult::from).toList();
}
}