Extend json output with number and uuid fields

This commit is contained in:
AsamK 2021-08-22 11:28:09 +02:00
parent 73e137137d
commit 5bbfd32598
9 changed files with 148 additions and 32 deletions

View file

@ -6,13 +6,22 @@ import org.asamk.signal.manager.Manager;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.UUID;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class JsonMention {
@JsonProperty
@Deprecated
final String name;
@JsonProperty
final String number;
@JsonProperty
final String uuid;
@JsonProperty
final int start;
@ -20,8 +29,10 @@ public class JsonMention {
final int length;
JsonMention(SignalServiceDataMessage.Mention mention, Manager m) {
this.name = getLegacyIdentifier(m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid(),
null)));
final var address = m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid(), null));
this.name = getLegacyIdentifier(address);
this.number = address.getNumber().orNull();
this.uuid = address.getUuid().transform(UUID::toString).orNull();
this.start = mention.getStart();
this.length = mention.getLength();
}

View file

@ -10,14 +10,22 @@ import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
import java.util.List;
import java.util.UUID;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class JsonMessageEnvelope {
@JsonProperty
@Deprecated
final String source;
@JsonProperty
final String sourceNumber;
@JsonProperty
final String sourceUuid;
@JsonProperty
final String sourceName;
@ -55,14 +63,21 @@ public class JsonMessageEnvelope {
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
var source = envelope.getSourceAddress();
this.source = getLegacyIdentifier(source);
this.sourceNumber = source.getNumber().orNull();
this.sourceUuid = source.getUuid().transform(UUID::toString).orNull();
this.sourceDevice = envelope.getSourceDevice();
this.relay = source.getRelay().orNull();
} else if (envelope.isUnidentifiedSender() && content != null) {
this.source = getLegacyIdentifier(content.getSender());
final var source = content.getSender();
this.source = getLegacyIdentifier(source);
this.sourceNumber = source.getNumber().orNull();
this.sourceUuid = source.getUuid().transform(UUID::toString).orNull();
this.sourceDevice = content.getSenderDevice();
this.relay = null;
} else {
this.source = null;
this.sourceNumber = null;
this.sourceUuid = null;
this.sourceDevice = null;
this.relay = null;
}
@ -98,6 +113,8 @@ public class JsonMessageEnvelope {
public JsonMessageEnvelope(Signal.MessageReceived messageReceived) {
source = messageReceived.getSender();
sourceNumber = null;
sourceUuid = null;
sourceName = null;
sourceDevice = null;
relay = null;
@ -111,6 +128,8 @@ public class JsonMessageEnvelope {
public JsonMessageEnvelope(Signal.ReceiptReceived receiptReceived) {
source = receiptReceived.getSender();
sourceNumber = null;
sourceUuid = null;
sourceName = null;
sourceDevice = null;
relay = null;
@ -124,6 +143,8 @@ public class JsonMessageEnvelope {
public JsonMessageEnvelope(Signal.SyncMessageReceived messageReceived) {
source = messageReceived.getSource();
sourceNumber = null;
sourceUuid = null;
sourceName = null;
sourceDevice = null;
relay = null;

View file

@ -8,6 +8,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
@ -18,8 +19,15 @@ public class JsonQuote {
final long id;
@JsonProperty
@Deprecated
final String author;
@JsonProperty
final String authorNumber;
@JsonProperty
final String authorUuid;
@JsonProperty
final String text;
@ -32,7 +40,10 @@ public class JsonQuote {
JsonQuote(SignalServiceDataMessage.Quote quote, Manager m) {
this.id = quote.getId();
this.author = getLegacyIdentifier(m.resolveSignalServiceAddress(quote.getAuthor()));
final var address = m.resolveSignalServiceAddress(quote.getAuthor());
this.author = getLegacyIdentifier(address);
this.authorNumber = address.getNumber().orNull();
this.authorUuid = address.getUuid().transform(UUID::toString).orNull();
this.text = quote.getText();
if (quote.getMentions() != null && quote.getMentions().size() > 0) {

View file

@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.asamk.signal.manager.Manager;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Reaction;
import java.util.UUID;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class JsonReaction {
@ -13,8 +15,15 @@ public class JsonReaction {
final String emoji;
@JsonProperty
@Deprecated
final String targetAuthor;
@JsonProperty
final String targetAuthorNumber;
@JsonProperty
final String targetAuthorUuid;
@JsonProperty
final long targetSentTimestamp;
@ -23,7 +32,10 @@ public class JsonReaction {
JsonReaction(Reaction reaction, Manager m) {
this.emoji = reaction.getEmoji();
this.targetAuthor = getLegacyIdentifier(m.resolveSignalServiceAddress(reaction.getTargetAuthor()));
final var address = m.resolveSignalServiceAddress(reaction.getTargetAuthor());
this.targetAuthor = getLegacyIdentifier(address);
this.targetAuthorNumber = address.getNumber().orNull();
this.targetAuthorUuid = address.getUuid().transform(UUID::toString).orNull();
this.targetSentTimestamp = reaction.getTargetSentTimestamp();
this.isRemove = reaction.isRemove();
}

View file

@ -4,22 +4,43 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.asamk.Signal;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.util.Util;
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
import java.util.UUID;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
class JsonSyncDataMessage extends JsonDataMessage {
@JsonProperty
@Deprecated
final String destination;
@JsonProperty
final String destinationNumber;
@JsonProperty
final String destinationUuid;
JsonSyncDataMessage(SentTranscriptMessage transcriptMessage, Manager m) {
super(transcriptMessage.getMessage(), m);
this.destination = transcriptMessage.getDestination().transform(Util::getLegacyIdentifier).orNull();
if (transcriptMessage.getDestination().isPresent()) {
final var address = transcriptMessage.getDestination().get();
this.destination = getLegacyIdentifier(address);
this.destinationNumber = address.getNumber().orNull();
this.destinationUuid = address.getUuid().transform(UUID::toString).orNull();
} else {
this.destination = null;
this.destinationNumber = null;
this.destinationUuid = null;
}
}
JsonSyncDataMessage(Signal.SyncMessageReceived messageReceived) {
super(messageReceived);
destination = messageReceived.getDestination();
this.destination = messageReceived.getDestination();
this.destinationNumber = null;
this.destinationUuid = null;
}
}

View file

@ -12,8 +12,6 @@ import java.util.Base64;
import java.util.List;
import java.util.stream.Collectors;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
enum JsonSyncMessageType {
CONTACTS_SYNC,
GROUPS_SYNC,
@ -68,8 +66,7 @@ class JsonSyncMessage {
this.readMessages = syncMessage.getRead()
.get()
.stream()
.map(message -> new JsonSyncReadMessage(getLegacyIdentifier(message.getSender()),
message.getTimestamp()))
.map(JsonSyncReadMessage::new)
.collect(Collectors.toList());
} else {
this.readMessages = null;

View file

@ -2,16 +2,32 @@ package org.asamk.signal.json;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
import java.util.UUID;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
class JsonSyncReadMessage {
@JsonProperty
@Deprecated
final String sender;
@JsonProperty
final String senderNumber;
@JsonProperty
final String senderUuid;
@JsonProperty
final long timestamp;
public JsonSyncReadMessage(final String sender, final long timestamp) {
this.sender = sender;
this.timestamp = timestamp;
public JsonSyncReadMessage(final ReadMessage readMessage) {
final var sender = readMessage.getSender();
this.sender = getLegacyIdentifier(sender);
this.senderNumber = sender.getNumber().orNull();
this.senderUuid = sender.getUuid().transform(UUID::toString).orNull();
this.timestamp = readMessage.getTimestamp();
}
}