mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-31 11:30:39 +00:00
43 lines
1.7 KiB
Java
43 lines
1.7 KiB
Java
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.isRateLimitFailure()
|
|
? Type.RATE_LIMIT_FAILURE
|
|
: 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,
|
|
RATE_LIMIT_FAILURE,
|
|
}
|
|
}
|