mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Refactor JsonMessageEnvelope to remove unnecessary number canonicalization
This commit is contained in:
parent
380c892e24
commit
e284b99076
1 changed files with 19 additions and 19 deletions
|
@ -4,9 +4,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.UntrustedIdentityException;
|
||||
import org.asamk.signal.manager.api.InvalidNumberException;
|
||||
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -27,35 +27,35 @@ public record JsonMessageEnvelope(
|
|||
public static JsonMessageEnvelope from(
|
||||
MessageEnvelope envelope, Throwable exception, Manager m
|
||||
) {
|
||||
final RecipientAddress sourceAddress;
|
||||
final Integer sourceDevice;
|
||||
if (envelope.sourceAddress().isPresent()) {
|
||||
sourceAddress = envelope.sourceAddress().get();
|
||||
sourceDevice = envelope.sourceDevice();
|
||||
} else if (exception instanceof UntrustedIdentityException e) {
|
||||
sourceAddress = e.getSender();
|
||||
sourceDevice = e.getSenderDevice();
|
||||
} else {
|
||||
sourceAddress = null;
|
||||
sourceDevice = null;
|
||||
}
|
||||
|
||||
final String source;
|
||||
final String sourceNumber;
|
||||
final String sourceUuid;
|
||||
final Integer sourceDevice;
|
||||
if (envelope.sourceAddress().isPresent()) {
|
||||
final var sourceAddress = envelope.sourceAddress().get();
|
||||
final String sourceName;
|
||||
if (sourceAddress != null) {
|
||||
source = sourceAddress.getLegacyIdentifier();
|
||||
sourceNumber = sourceAddress.number().orElse(null);
|
||||
sourceUuid = sourceAddress.uuid().map(UUID::toString).orElse(null);
|
||||
sourceDevice = envelope.sourceDevice();
|
||||
} else if (exception instanceof UntrustedIdentityException e) {
|
||||
final var sender = e.getSender();
|
||||
source = sender.getLegacyIdentifier();
|
||||
sourceNumber = sender.number().orElse(null);
|
||||
sourceUuid = sender.uuid().map(UUID::toString).orElse(null);
|
||||
sourceDevice = e.getSenderDevice();
|
||||
sourceName = m.getContactOrProfileName(RecipientIdentifier.Single.fromAddress(envelope.sourceAddress()
|
||||
.get()));
|
||||
} else {
|
||||
source = null;
|
||||
sourceNumber = null;
|
||||
sourceUuid = null;
|
||||
sourceDevice = null;
|
||||
sourceName = null;
|
||||
}
|
||||
String name;
|
||||
try {
|
||||
name = m.getContactOrProfileName(RecipientIdentifier.Single.fromString(source, m.getSelfNumber()));
|
||||
} catch (InvalidNumberException | NullPointerException e) {
|
||||
name = null;
|
||||
}
|
||||
final var sourceName = name;
|
||||
final var timestamp = envelope.timestamp();
|
||||
final var receiptMessage = envelope.receipt().map(JsonReceiptMessage::from).orElse(null);
|
||||
final var typingMessage = envelope.typing().map(JsonTypingMessage::from).orElse(null);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue