Handle send failures as non fatal and return detailed results in json output

Fixes #348
This commit is contained in:
AsamK 2021-12-11 12:44:11 +01:00
parent ceafe96e81
commit 06e93b84da
13 changed files with 191 additions and 138 deletions

View file

@ -0,0 +1,12 @@
package org.asamk.signal.json;
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
import java.util.UUID;
public record JsonRecipientAddress(String uuid, String number) {
public static JsonRecipientAddress from(RecipientAddress address) {
return new JsonRecipientAddress(address.uuid().map(UUID::toString).orElse(null), address.number().orElse(null));
}
}

View file

@ -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,
}
}