mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Improve exit code for message sending
Exit with 0 status code if the message was sent successfully to at least one recipient, otherwise exit with status code 2 or 4 (for untrusted). Fixes #828
This commit is contained in:
parent
4aa8e3f2f2
commit
9a72733c4f
4 changed files with 64 additions and 35 deletions
|
@ -3,4 +3,20 @@ package org.asamk.signal.manager.api;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public record SendMessageResults(long timestamp, Map<RecipientIdentifier, List<SendMessageResult>> results) {}
|
||||
public record SendMessageResults(long timestamp, Map<RecipientIdentifier, List<SendMessageResult>> results) {
|
||||
|
||||
public boolean hasSuccess() {
|
||||
return results.values()
|
||||
.stream()
|
||||
.flatMap(res -> res.stream().map(SendMessageResult::isSuccess))
|
||||
.anyMatch(success -> success) || results.values().stream().mapToInt(List::size).sum() == 0;
|
||||
}
|
||||
|
||||
public boolean hasOnlyUntrustedIdentity() {
|
||||
return results.values()
|
||||
.stream()
|
||||
.flatMap(res -> res.stream().map(SendMessageResult::isIdentityFailure))
|
||||
.allMatch(identityFailure -> identityFailure)
|
||||
&& results.values().stream().mapToInt(List::size).sum() > 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue