mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-03 12:50:37 +00:00
Handle send failures as non fatal and return detailed results in json output
Fixes #348
This commit is contained in:
parent
ceafe96e81
commit
06e93b84da
13 changed files with 191 additions and 138 deletions
|
@ -0,0 +1,38 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import org.asamk.signal.manager.api.SendMessageResult;
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
|
||||
public record JsonSendMessageResult(
|
||||
JsonRecipientAddress recipientAddress,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) String groupId,
|
||||
Type type,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) String token,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) Long retryAfterSeconds
|
||||
) {
|
||||
|
||||
public static JsonSendMessageResult from(SendMessageResult result) {
|
||||
return from(result, null);
|
||||
}
|
||||
|
||||
public static JsonSendMessageResult from(SendMessageResult result, GroupId groupId) {
|
||||
return new JsonSendMessageResult(JsonRecipientAddress.from(result.address()),
|
||||
groupId != null ? groupId.toBase64() : null,
|
||||
result.isSuccess()
|
||||
? Type.SUCCESS
|
||||
: result.isNetworkFailure()
|
||||
? Type.NETWORK_FAILURE
|
||||
: result.isUnregisteredFailure() ? Type.UNREGISTERED_FAILURE : Type.IDENTITY_FAILURE,
|
||||
result.proofRequiredFailure() != null ? result.proofRequiredFailure().getToken() : null,
|
||||
result.proofRequiredFailure() != null ? result.proofRequiredFailure().getRetryAfterSeconds() : null);
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
SUCCESS,
|
||||
NETWORK_FAILURE,
|
||||
UNREGISTERED_FAILURE,
|
||||
IDENTITY_FAILURE,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue