mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Use record classes
This commit is contained in:
parent
ce70a623c2
commit
ce7aa580b6
66 changed files with 754 additions and 1877 deletions
|
@ -1,43 +1,25 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||
|
||||
class JsonAttachment {
|
||||
|
||||
@JsonProperty
|
||||
final String contentType;
|
||||
|
||||
@JsonProperty
|
||||
final String filename;
|
||||
|
||||
@JsonProperty
|
||||
final String id;
|
||||
|
||||
@JsonProperty
|
||||
final Long size;
|
||||
|
||||
JsonAttachment(SignalServiceAttachment attachment) {
|
||||
this.contentType = attachment.getContentType();
|
||||
record JsonAttachment(String contentType, String filename, String id, Long size) {
|
||||
|
||||
static JsonAttachment from(SignalServiceAttachment attachment) {
|
||||
if (attachment.isPointer()) {
|
||||
final var pointer = attachment.asPointer();
|
||||
this.id = pointer.getRemoteId().toString();
|
||||
this.filename = pointer.getFileName().orNull();
|
||||
this.size = pointer.getSize().transform(Integer::longValue).orNull();
|
||||
final var id = pointer.getRemoteId().toString();
|
||||
final var filename = pointer.getFileName().orNull();
|
||||
final var size = pointer.getSize().transform(Integer::longValue).orNull();
|
||||
return new JsonAttachment(attachment.getContentType(), filename, id, size);
|
||||
} else {
|
||||
final var stream = attachment.asStream();
|
||||
this.id = null;
|
||||
this.filename = stream.getFileName().orNull();
|
||||
this.size = stream.getLength();
|
||||
final var filename = stream.getFileName().orNull();
|
||||
final var size = stream.getLength();
|
||||
return new JsonAttachment(attachment.getContentType(), filename, null, size);
|
||||
}
|
||||
}
|
||||
|
||||
JsonAttachment(String filename) {
|
||||
this.filename = filename;
|
||||
this.contentType = null;
|
||||
this.id = null;
|
||||
this.size = null;
|
||||
static JsonAttachment from(String filename) {
|
||||
return new JsonAttachment(filename, null, null, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.calls.AnswerMessage;
|
||||
import org.whispersystems.signalservice.api.messages.calls.BusyMessage;
|
||||
|
@ -12,33 +11,19 @@ import org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMess
|
|||
|
||||
import java.util.List;
|
||||
|
||||
class JsonCallMessage {
|
||||
record JsonCallMessage(
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) OfferMessage offerMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) AnswerMessage answerMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) BusyMessage busyMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) HangupMessage hangupMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<IceUpdateMessage> iceUpdateMessages
|
||||
) {
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final OfferMessage offerMessage;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final AnswerMessage answerMessage;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final BusyMessage busyMessage;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final HangupMessage hangupMessage;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<IceUpdateMessage> iceUpdateMessages;
|
||||
|
||||
JsonCallMessage(SignalServiceCallMessage callMessage) {
|
||||
this.offerMessage = callMessage.getOfferMessage().orNull();
|
||||
this.answerMessage = callMessage.getAnswerMessage().orNull();
|
||||
this.busyMessage = callMessage.getBusyMessage().orNull();
|
||||
this.hangupMessage = callMessage.getHangupMessage().orNull();
|
||||
this.iceUpdateMessages = callMessage.getIceUpdateMessages().orNull();
|
||||
static JsonCallMessage from(SignalServiceCallMessage callMessage) {
|
||||
return new JsonCallMessage(callMessage.getOfferMessage().orNull(),
|
||||
callMessage.getAnswerMessage().orNull(),
|
||||
callMessage.getBusyMessage().orNull(),
|
||||
callMessage.getHangupMessage().orNull(),
|
||||
callMessage.getIceUpdateMessages().orNull());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,48 +1,29 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||
|
||||
public class JsonContactAddress {
|
||||
public record JsonContactAddress(
|
||||
SharedContact.PostalAddress.Type type,
|
||||
String label,
|
||||
String street,
|
||||
String pobox,
|
||||
String neighborhood,
|
||||
String city,
|
||||
String region,
|
||||
String postcode,
|
||||
String country
|
||||
) {
|
||||
|
||||
@JsonProperty
|
||||
private final SharedContact.PostalAddress.Type type;
|
||||
|
||||
@JsonProperty
|
||||
private final String label;
|
||||
|
||||
@JsonProperty
|
||||
private final String street;
|
||||
|
||||
@JsonProperty
|
||||
private final String pobox;
|
||||
|
||||
@JsonProperty
|
||||
private final String neighborhood;
|
||||
|
||||
@JsonProperty
|
||||
private final String city;
|
||||
|
||||
@JsonProperty
|
||||
private final String region;
|
||||
|
||||
@JsonProperty
|
||||
private final String postcode;
|
||||
|
||||
@JsonProperty
|
||||
private final String country;
|
||||
|
||||
public JsonContactAddress(SharedContact.PostalAddress address) {
|
||||
type = address.getType();
|
||||
label = Util.getStringIfNotBlank(address.getLabel());
|
||||
street = Util.getStringIfNotBlank(address.getStreet());
|
||||
pobox = Util.getStringIfNotBlank(address.getPobox());
|
||||
neighborhood = Util.getStringIfNotBlank(address.getNeighborhood());
|
||||
city = Util.getStringIfNotBlank(address.getCity());
|
||||
region = Util.getStringIfNotBlank(address.getRegion());
|
||||
postcode = Util.getStringIfNotBlank(address.getPostcode());
|
||||
country = Util.getStringIfNotBlank(address.getCountry());
|
||||
static JsonContactAddress from(SharedContact.PostalAddress address) {
|
||||
return new JsonContactAddress(address.getType(),
|
||||
Util.getStringIfNotBlank(address.getLabel()),
|
||||
Util.getStringIfNotBlank(address.getStreet()),
|
||||
Util.getStringIfNotBlank(address.getPobox()),
|
||||
Util.getStringIfNotBlank(address.getNeighborhood()),
|
||||
Util.getStringIfNotBlank(address.getCity()),
|
||||
Util.getStringIfNotBlank(address.getRegion()),
|
||||
Util.getStringIfNotBlank(address.getPostcode()),
|
||||
Util.getStringIfNotBlank(address.getCountry()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,10 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||
|
||||
public class JsonContactAvatar {
|
||||
public record JsonContactAvatar(JsonAttachment attachment, boolean isProfile) {
|
||||
|
||||
@JsonProperty
|
||||
private final JsonAttachment attachment;
|
||||
|
||||
@JsonProperty
|
||||
private final boolean isProfile;
|
||||
|
||||
public JsonContactAvatar(SharedContact.Avatar avatar) {
|
||||
attachment = new JsonAttachment(avatar.getAttachment());
|
||||
isProfile = avatar.isProfile();
|
||||
static JsonContactAvatar from(SharedContact.Avatar avatar) {
|
||||
return new JsonContactAvatar(JsonAttachment.from(avatar.getAttachment()), avatar.isProfile());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,11 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||
|
||||
public class JsonContactEmail {
|
||||
public record JsonContactEmail(String value, SharedContact.Email.Type type, String label) {
|
||||
|
||||
@JsonProperty
|
||||
private final String value;
|
||||
|
||||
@JsonProperty
|
||||
private final SharedContact.Email.Type type;
|
||||
|
||||
@JsonProperty
|
||||
private final String label;
|
||||
|
||||
public JsonContactEmail(SharedContact.Email email) {
|
||||
value = email.getValue();
|
||||
type = email.getType();
|
||||
label = Util.getStringIfNotBlank(email.getLabel());
|
||||
static JsonContactEmail from(SharedContact.Email email) {
|
||||
return new JsonContactEmail(email.getValue(), email.getType(), Util.getStringIfNotBlank(email.getLabel()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,36 +1,18 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||
|
||||
public class JsonContactName {
|
||||
public record JsonContactName(
|
||||
String display, String given, String family, String prefix, String suffix, String middle
|
||||
) {
|
||||
|
||||
@JsonProperty
|
||||
private final String display;
|
||||
|
||||
@JsonProperty
|
||||
private final String given;
|
||||
|
||||
@JsonProperty
|
||||
private final String family;
|
||||
|
||||
@JsonProperty
|
||||
private final String prefix;
|
||||
|
||||
@JsonProperty
|
||||
private final String suffix;
|
||||
|
||||
@JsonProperty
|
||||
private final String middle;
|
||||
|
||||
public JsonContactName(SharedContact.Name name) {
|
||||
display = Util.getStringIfNotBlank(name.getDisplay());
|
||||
given = Util.getStringIfNotBlank(name.getGiven());
|
||||
family = Util.getStringIfNotBlank(name.getFamily());
|
||||
prefix = Util.getStringIfNotBlank(name.getPrefix());
|
||||
suffix = Util.getStringIfNotBlank(name.getSuffix());
|
||||
middle = Util.getStringIfNotBlank(name.getMiddle());
|
||||
static JsonContactName from(SharedContact.Name name) {
|
||||
return new JsonContactName(Util.getStringIfNotBlank(name.getDisplay()),
|
||||
Util.getStringIfNotBlank(name.getGiven()),
|
||||
Util.getStringIfNotBlank(name.getFamily()),
|
||||
Util.getStringIfNotBlank(name.getPrefix()),
|
||||
Util.getStringIfNotBlank(name.getSuffix()),
|
||||
Util.getStringIfNotBlank(name.getMiddle()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,11 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||
|
||||
public class JsonContactPhone {
|
||||
public record JsonContactPhone(String value, SharedContact.Phone.Type type, String label) {
|
||||
|
||||
@JsonProperty
|
||||
private final String value;
|
||||
|
||||
@JsonProperty
|
||||
private final SharedContact.Phone.Type type;
|
||||
|
||||
@JsonProperty
|
||||
private final String label;
|
||||
|
||||
public JsonContactPhone(SharedContact.Phone phone) {
|
||||
value = phone.getValue();
|
||||
type = phone.getType();
|
||||
label = Util.getStringIfNotBlank(phone.getLabel());
|
||||
static JsonContactPhone from(SharedContact.Phone phone) {
|
||||
return new JsonContactPhone(phone.getValue(), phone.getType(), Util.getStringIfNotBlank(phone.getLabel()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
|
@ -10,136 +9,124 @@ import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class JsonDataMessage {
|
||||
record JsonDataMessage(
|
||||
long timestamp,
|
||||
String message,
|
||||
Integer expiresInSeconds,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) Boolean viewOnce,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonReaction reaction,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonQuote quote,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonMention> mentions,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonAttachment> attachments,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonSticker sticker,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonRemoteDelete remoteDelete,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonSharedContact> contacts,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonGroupInfo groupInfo
|
||||
) {
|
||||
|
||||
@JsonProperty
|
||||
final long timestamp;
|
||||
|
||||
@JsonProperty
|
||||
final String message;
|
||||
|
||||
@JsonProperty
|
||||
final Integer expiresInSeconds;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final Boolean viewOnce;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonReaction reaction;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonQuote quote;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<JsonMention> mentions;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<JsonAttachment> attachments;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonSticker sticker;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonRemoteDelete remoteDelete;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<JsonSharedContact> contacts;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonGroupInfo groupInfo;
|
||||
|
||||
JsonDataMessage(SignalServiceDataMessage dataMessage, Manager m) {
|
||||
this.timestamp = dataMessage.getTimestamp();
|
||||
static JsonDataMessage from(SignalServiceDataMessage dataMessage, Manager m) {
|
||||
final var timestamp = dataMessage.getTimestamp();
|
||||
final JsonGroupInfo groupInfo;
|
||||
if (dataMessage.getGroupContext().isPresent()) {
|
||||
final var groupContext = dataMessage.getGroupContext().get();
|
||||
if (groupContext.getGroupV1().isPresent()) {
|
||||
var groupInfo = groupContext.getGroupV1().get();
|
||||
this.groupInfo = new JsonGroupInfo(groupInfo);
|
||||
var group = groupContext.getGroupV1().get();
|
||||
groupInfo = JsonGroupInfo.from(group);
|
||||
} else if (groupContext.getGroupV2().isPresent()) {
|
||||
var groupInfo = groupContext.getGroupV2().get();
|
||||
this.groupInfo = new JsonGroupInfo(groupInfo);
|
||||
var group = groupContext.getGroupV2().get();
|
||||
groupInfo = JsonGroupInfo.from(group);
|
||||
} else {
|
||||
this.groupInfo = null;
|
||||
groupInfo = null;
|
||||
}
|
||||
} else {
|
||||
this.groupInfo = null;
|
||||
groupInfo = null;
|
||||
}
|
||||
this.message = dataMessage.getBody().orNull();
|
||||
this.expiresInSeconds = dataMessage.getExpiresInSeconds();
|
||||
this.viewOnce = dataMessage.isViewOnce();
|
||||
this.reaction = dataMessage.getReaction().isPresent()
|
||||
? new JsonReaction(dataMessage.getReaction().get(), m)
|
||||
: null;
|
||||
this.quote = dataMessage.getQuote().isPresent() ? new JsonQuote(dataMessage.getQuote().get(), m) : null;
|
||||
final var message = dataMessage.getBody().orNull();
|
||||
final var expiresInSeconds = dataMessage.getExpiresInSeconds();
|
||||
final var viewOnce = dataMessage.isViewOnce();
|
||||
final var reaction = dataMessage.getReaction().isPresent() ? JsonReaction.from(dataMessage.getReaction().get(),
|
||||
m) : null;
|
||||
final var quote = dataMessage.getQuote().isPresent() ? JsonQuote.from(dataMessage.getQuote().get(), m) : null;
|
||||
final List<JsonMention> mentions;
|
||||
if (dataMessage.getMentions().isPresent()) {
|
||||
this.mentions = dataMessage.getMentions()
|
||||
mentions = dataMessage.getMentions()
|
||||
.get()
|
||||
.stream()
|
||||
.map(mention -> new JsonMention(mention, m))
|
||||
.map(mention -> JsonMention.from(mention, m))
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
this.mentions = List.of();
|
||||
mentions = List.of();
|
||||
}
|
||||
remoteDelete = dataMessage.getRemoteDelete().isPresent() ? new JsonRemoteDelete(dataMessage.getRemoteDelete()
|
||||
.get()) : null;
|
||||
final var remoteDelete = dataMessage.getRemoteDelete().isPresent()
|
||||
? JsonRemoteDelete.from(dataMessage.getRemoteDelete().get())
|
||||
: null;
|
||||
final List<JsonAttachment> attachments;
|
||||
if (dataMessage.getAttachments().isPresent()) {
|
||||
this.attachments = dataMessage.getAttachments()
|
||||
attachments = dataMessage.getAttachments()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonAttachment::new)
|
||||
.map(JsonAttachment::from)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
this.attachments = List.of();
|
||||
attachments = List.of();
|
||||
}
|
||||
this.sticker = dataMessage.getSticker().isPresent() ? new JsonSticker(dataMessage.getSticker().get()) : null;
|
||||
final var sticker = dataMessage.getSticker().isPresent()
|
||||
? JsonSticker.from(dataMessage.getSticker().get())
|
||||
: null;
|
||||
|
||||
final List<JsonSharedContact> contacts;
|
||||
if (dataMessage.getSharedContacts().isPresent()) {
|
||||
this.contacts = dataMessage.getSharedContacts()
|
||||
contacts = dataMessage.getSharedContacts()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonSharedContact::new)
|
||||
.map(JsonSharedContact::from)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
this.contacts = List.of();
|
||||
contacts = List.of();
|
||||
}
|
||||
return new JsonDataMessage(timestamp,
|
||||
message,
|
||||
expiresInSeconds,
|
||||
viewOnce,
|
||||
reaction,
|
||||
quote,
|
||||
mentions,
|
||||
attachments,
|
||||
sticker,
|
||||
remoteDelete,
|
||||
contacts,
|
||||
groupInfo);
|
||||
}
|
||||
|
||||
public JsonDataMessage(Signal.MessageReceived messageReceived) {
|
||||
timestamp = messageReceived.getTimestamp();
|
||||
message = messageReceived.getMessage();
|
||||
groupInfo = messageReceived.getGroupId().length > 0 ? new JsonGroupInfo(messageReceived.getGroupId()) : null;
|
||||
expiresInSeconds = null;
|
||||
viewOnce = null;
|
||||
remoteDelete = null;
|
||||
reaction = null; // TODO Replace these 5 with the proper commands
|
||||
quote = null;
|
||||
mentions = null;
|
||||
sticker = null;
|
||||
contacts = null;
|
||||
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
|
||||
static JsonDataMessage from(Signal.MessageReceived messageReceived) {
|
||||
return new JsonDataMessage(messageReceived.getTimestamp(),
|
||||
messageReceived.getMessage(),
|
||||
// TODO Replace these with the proper commands
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
messageReceived.getAttachments().stream().map(JsonAttachment::from).collect(Collectors.toList()),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
messageReceived.getGroupId().length > 0 ? JsonGroupInfo.from(messageReceived.getGroupId()) : null);
|
||||
}
|
||||
|
||||
public JsonDataMessage(Signal.SyncMessageReceived messageReceived) {
|
||||
timestamp = messageReceived.getTimestamp();
|
||||
message = messageReceived.getMessage();
|
||||
groupInfo = messageReceived.getGroupId().length > 0 ? new JsonGroupInfo(messageReceived.getGroupId()) : null;
|
||||
expiresInSeconds = null;
|
||||
viewOnce = null;
|
||||
remoteDelete = null;
|
||||
reaction = null; // TODO Replace these 5 with the proper commands
|
||||
quote = null;
|
||||
mentions = null;
|
||||
sticker = null;
|
||||
contacts = null;
|
||||
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
|
||||
static JsonDataMessage from(Signal.SyncMessageReceived messageReceived) {
|
||||
return new JsonDataMessage(messageReceived.getTimestamp(),
|
||||
messageReceived.getMessage(),
|
||||
// TODO Replace these with the proper commands
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
messageReceived.getAttachments().stream().map(JsonAttachment::from).collect(Collectors.toList()),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
messageReceived.getGroupId().length > 0 ? JsonGroupInfo.from(messageReceived.getGroupId()) : null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,8 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
public record JsonError(String message, String type) {
|
||||
|
||||
public class JsonError {
|
||||
|
||||
@JsonProperty
|
||||
final String message;
|
||||
|
||||
@JsonProperty
|
||||
final String type;
|
||||
|
||||
public JsonError(Throwable exception) {
|
||||
this.message = exception.getMessage();
|
||||
this.type = exception.getClass().getSimpleName();
|
||||
public static JsonError from(Throwable exception) {
|
||||
return new JsonError(exception.getMessage(), exception.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.asamk.signal.manager.groups.GroupUtils;
|
||||
import org.asamk.signal.util.Util;
|
||||
|
@ -12,48 +11,32 @@ import java.util.Base64;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class JsonGroupInfo {
|
||||
record JsonGroupInfo(
|
||||
String groupId,
|
||||
String type,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) String name,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<String> members
|
||||
) {
|
||||
|
||||
@JsonProperty
|
||||
final String groupId;
|
||||
|
||||
@JsonProperty
|
||||
final String type;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final String name;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<String> members;
|
||||
|
||||
JsonGroupInfo(SignalServiceGroup groupInfo) {
|
||||
this.groupId = Base64.getEncoder().encodeToString(groupInfo.getGroupId());
|
||||
this.type = groupInfo.getType().toString();
|
||||
this.name = groupInfo.getName().orNull();
|
||||
if (groupInfo.getMembers().isPresent()) {
|
||||
this.members = groupInfo.getMembers()
|
||||
.get()
|
||||
.stream()
|
||||
.map(Util::getLegacyIdentifier)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
this.members = null;
|
||||
}
|
||||
static JsonGroupInfo from(SignalServiceGroup groupInfo) {
|
||||
return new JsonGroupInfo(Base64.getEncoder().encodeToString(groupInfo.getGroupId()),
|
||||
groupInfo.getType().toString(),
|
||||
groupInfo.getName().orNull(),
|
||||
groupInfo.getMembers().isPresent() ? groupInfo.getMembers()
|
||||
.get()
|
||||
.stream()
|
||||
.map(Util::getLegacyIdentifier)
|
||||
.collect(Collectors.toList()) : null);
|
||||
}
|
||||
|
||||
JsonGroupInfo(SignalServiceGroupV2 groupInfo) {
|
||||
this.groupId = GroupUtils.getGroupIdV2(groupInfo.getMasterKey()).toBase64();
|
||||
this.type = groupInfo.hasSignedGroupChange() ? "UPDATE" : "DELIVER";
|
||||
this.members = null;
|
||||
this.name = null;
|
||||
static JsonGroupInfo from(SignalServiceGroupV2 groupInfo) {
|
||||
return new JsonGroupInfo(GroupUtils.getGroupIdV2(groupInfo.getMasterKey()).toBase64(),
|
||||
groupInfo.hasSignedGroupChange() ? "UPDATE" : "DELIVER",
|
||||
null,
|
||||
null);
|
||||
}
|
||||
|
||||
JsonGroupInfo(byte[] groupId) {
|
||||
this.groupId = Base64.getEncoder().encodeToString(groupId);
|
||||
this.type = "DELIVER";
|
||||
this.members = null;
|
||||
this.name = null;
|
||||
static JsonGroupInfo from(byte[] groupId) {
|
||||
return new JsonGroupInfo(Base64.getEncoder().encodeToString(groupId), "DELIVER", null, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,37 +1,19 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
|
||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
||||
|
||||
public class JsonMention {
|
||||
public record JsonMention(@Deprecated String name, String number, String uuid, int start, int length) {
|
||||
|
||||
@JsonProperty
|
||||
@Deprecated
|
||||
final String name;
|
||||
|
||||
@JsonProperty
|
||||
final String number;
|
||||
|
||||
@JsonProperty
|
||||
final String uuid;
|
||||
|
||||
@JsonProperty
|
||||
final int start;
|
||||
|
||||
@JsonProperty
|
||||
final int length;
|
||||
|
||||
JsonMention(SignalServiceDataMessage.Mention mention, Manager m) {
|
||||
static JsonMention from(SignalServiceDataMessage.Mention mention, Manager m) {
|
||||
final var address = m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid()));
|
||||
this.name = getLegacyIdentifier(address);
|
||||
this.number = address.getNumber().orNull();
|
||||
this.uuid = address.getUuid().toString();
|
||||
this.start = mention.getStart();
|
||||
this.length = mention.getLength();
|
||||
return new JsonMention(getLegacyIdentifier(address),
|
||||
address.getNumber().orNull(),
|
||||
address.getUuid().toString(),
|
||||
mention.getStart(),
|
||||
mention.getLength());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
|
@ -15,143 +14,133 @@ import java.util.List;
|
|||
|
||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
||||
|
||||
public class JsonMessageEnvelope {
|
||||
public record JsonMessageEnvelope(
|
||||
@Deprecated String source,
|
||||
String sourceNumber,
|
||||
String sourceUuid,
|
||||
String sourceName,
|
||||
Integer sourceDevice,
|
||||
long timestamp,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonDataMessage dataMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonSyncMessage syncMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonCallMessage callMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonReceiptMessage receiptMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonTypingMessage typingMessage
|
||||
) {
|
||||
|
||||
@JsonProperty
|
||||
@Deprecated
|
||||
final String source;
|
||||
|
||||
@JsonProperty
|
||||
final String sourceNumber;
|
||||
|
||||
@JsonProperty
|
||||
final String sourceUuid;
|
||||
|
||||
@JsonProperty
|
||||
final String sourceName;
|
||||
|
||||
@JsonProperty
|
||||
final Integer sourceDevice;
|
||||
|
||||
@JsonProperty
|
||||
final long timestamp;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonDataMessage dataMessage;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonSyncMessage syncMessage;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonCallMessage callMessage;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonReceiptMessage receiptMessage;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonTypingMessage typingMessage;
|
||||
|
||||
public JsonMessageEnvelope(
|
||||
public static JsonMessageEnvelope from(
|
||||
SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception, Manager m
|
||||
) {
|
||||
final String source;
|
||||
final String sourceNumber;
|
||||
final String sourceUuid;
|
||||
final Integer sourceDevice;
|
||||
if (!envelope.isUnidentifiedSender() && envelope.hasSourceUuid()) {
|
||||
var source = m.resolveSignalServiceAddress(envelope.getSourceAddress());
|
||||
this.source = getLegacyIdentifier(source);
|
||||
this.sourceNumber = source.getNumber().orNull();
|
||||
this.sourceUuid = source.getUuid().toString();
|
||||
this.sourceDevice = envelope.getSourceDevice();
|
||||
final var sourceAddress = m.resolveSignalServiceAddress(envelope.getSourceAddress());
|
||||
source = getLegacyIdentifier(sourceAddress);
|
||||
sourceNumber = sourceAddress.getNumber().orNull();
|
||||
sourceUuid = sourceAddress.getUuid().toString();
|
||||
sourceDevice = envelope.getSourceDevice();
|
||||
} else if (envelope.isUnidentifiedSender() && content != null) {
|
||||
final var source = m.resolveSignalServiceAddress(content.getSender());
|
||||
this.source = getLegacyIdentifier(source);
|
||||
this.sourceNumber = source.getNumber().orNull();
|
||||
this.sourceUuid = source.getUuid().toString();
|
||||
this.sourceDevice = content.getSenderDevice();
|
||||
final var sender = m.resolveSignalServiceAddress(content.getSender());
|
||||
source = getLegacyIdentifier(sender);
|
||||
sourceNumber = sender.getNumber().orNull();
|
||||
sourceUuid = sender.getUuid().toString();
|
||||
sourceDevice = content.getSenderDevice();
|
||||
} else if (exception instanceof UntrustedIdentityException e) {
|
||||
final var source = m.resolveSignalServiceAddress(e.getSender());
|
||||
this.source = getLegacyIdentifier(source);
|
||||
this.sourceNumber = source.getNumber().orNull();
|
||||
this.sourceUuid = source.getUuid().toString();
|
||||
this.sourceDevice = e.getSenderDevice();
|
||||
final var sender = m.resolveSignalServiceAddress(e.getSender());
|
||||
source = getLegacyIdentifier(sender);
|
||||
sourceNumber = sender.getNumber().orNull();
|
||||
sourceUuid = sender.getUuid().toString();
|
||||
sourceDevice = e.getSenderDevice();
|
||||
} else {
|
||||
this.source = null;
|
||||
this.sourceNumber = null;
|
||||
this.sourceUuid = null;
|
||||
this.sourceDevice = null;
|
||||
source = null;
|
||||
sourceNumber = null;
|
||||
sourceUuid = null;
|
||||
sourceDevice = null;
|
||||
}
|
||||
String name;
|
||||
try {
|
||||
name = m.getContactOrProfileName(RecipientIdentifier.Single.fromString(this.source, m.getSelfNumber()));
|
||||
name = m.getContactOrProfileName(RecipientIdentifier.Single.fromString(source, m.getSelfNumber()));
|
||||
} catch (InvalidNumberException | NullPointerException e) {
|
||||
name = null;
|
||||
}
|
||||
this.sourceName = name;
|
||||
this.timestamp = envelope.getTimestamp();
|
||||
final var sourceName = name;
|
||||
final var timestamp = envelope.getTimestamp();
|
||||
final JsonReceiptMessage receiptMessage;
|
||||
if (envelope.isReceipt()) {
|
||||
this.receiptMessage = JsonReceiptMessage.deliveryReceipt(timestamp, List.of(timestamp));
|
||||
receiptMessage = JsonReceiptMessage.deliveryReceipt(timestamp, List.of(timestamp));
|
||||
} else if (content != null && content.getReceiptMessage().isPresent()) {
|
||||
this.receiptMessage = new JsonReceiptMessage(content.getReceiptMessage().get());
|
||||
receiptMessage = JsonReceiptMessage.from(content.getReceiptMessage().get());
|
||||
} else {
|
||||
this.receiptMessage = null;
|
||||
receiptMessage = null;
|
||||
}
|
||||
this.typingMessage = content != null && content.getTypingMessage().isPresent()
|
||||
? new JsonTypingMessage(content.getTypingMessage().get())
|
||||
final var typingMessage = content != null && content.getTypingMessage().isPresent() ? JsonTypingMessage.from(
|
||||
content.getTypingMessage().get()) : null;
|
||||
|
||||
final var dataMessage = content != null && content.getDataMessage().isPresent()
|
||||
? JsonDataMessage.from(content.getDataMessage().get(), m)
|
||||
: null;
|
||||
final var syncMessage = content != null && content.getSyncMessage().isPresent()
|
||||
? JsonSyncMessage.from(content.getSyncMessage().get(), m)
|
||||
: null;
|
||||
final var callMessage = content != null && content.getCallMessage().isPresent()
|
||||
? JsonCallMessage.from(content.getCallMessage().get())
|
||||
: null;
|
||||
|
||||
this.dataMessage = content != null && content.getDataMessage().isPresent()
|
||||
? new JsonDataMessage(content.getDataMessage().get(), m)
|
||||
: null;
|
||||
this.syncMessage = content != null && content.getSyncMessage().isPresent()
|
||||
? new JsonSyncMessage(content.getSyncMessage().get(), m)
|
||||
: null;
|
||||
this.callMessage = content != null && content.getCallMessage().isPresent()
|
||||
? new JsonCallMessage(content.getCallMessage().get())
|
||||
: null;
|
||||
return new JsonMessageEnvelope(source,
|
||||
sourceNumber,
|
||||
sourceUuid,
|
||||
sourceName,
|
||||
sourceDevice,
|
||||
timestamp,
|
||||
dataMessage,
|
||||
syncMessage,
|
||||
callMessage,
|
||||
receiptMessage,
|
||||
typingMessage);
|
||||
}
|
||||
|
||||
public JsonMessageEnvelope(Signal.MessageReceived messageReceived) {
|
||||
source = messageReceived.getSender();
|
||||
sourceNumber = null;
|
||||
sourceUuid = null;
|
||||
sourceName = null;
|
||||
sourceDevice = null;
|
||||
timestamp = messageReceived.getTimestamp();
|
||||
receiptMessage = null;
|
||||
dataMessage = new JsonDataMessage(messageReceived);
|
||||
syncMessage = null;
|
||||
callMessage = null;
|
||||
typingMessage = null;
|
||||
public static JsonMessageEnvelope from(Signal.MessageReceived messageReceived) {
|
||||
return new JsonMessageEnvelope(messageReceived.getSource(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
messageReceived.getTimestamp(),
|
||||
JsonDataMessage.from(messageReceived),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
|
||||
public JsonMessageEnvelope(Signal.ReceiptReceived receiptReceived) {
|
||||
source = receiptReceived.getSender();
|
||||
sourceNumber = null;
|
||||
sourceUuid = null;
|
||||
sourceName = null;
|
||||
sourceDevice = null;
|
||||
timestamp = receiptReceived.getTimestamp();
|
||||
receiptMessage = JsonReceiptMessage.deliveryReceipt(timestamp, List.of(timestamp));
|
||||
dataMessage = null;
|
||||
syncMessage = null;
|
||||
callMessage = null;
|
||||
typingMessage = null;
|
||||
public static JsonMessageEnvelope from(Signal.ReceiptReceived receiptReceived) {
|
||||
return new JsonMessageEnvelope(receiptReceived.getSender(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
receiptReceived.getTimestamp(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
JsonReceiptMessage.deliveryReceipt(receiptReceived.getTimestamp(),
|
||||
List.of(receiptReceived.getTimestamp())),
|
||||
null);
|
||||
}
|
||||
|
||||
public JsonMessageEnvelope(Signal.SyncMessageReceived messageReceived) {
|
||||
source = messageReceived.getSource();
|
||||
sourceNumber = null;
|
||||
sourceUuid = null;
|
||||
sourceName = null;
|
||||
sourceDevice = null;
|
||||
timestamp = messageReceived.getTimestamp();
|
||||
receiptMessage = null;
|
||||
dataMessage = null;
|
||||
syncMessage = new JsonSyncMessage(messageReceived);
|
||||
callMessage = null;
|
||||
typingMessage = null;
|
||||
public static JsonMessageEnvelope from(Signal.SyncMessageReceived messageReceived) {
|
||||
return new JsonMessageEnvelope(messageReceived.getSource(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
messageReceived.getTimestamp(),
|
||||
null,
|
||||
JsonSyncMessage.from(messageReceived),
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
|
@ -12,55 +11,41 @@ import java.util.stream.Collectors;
|
|||
|
||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
||||
|
||||
public class JsonQuote {
|
||||
public record JsonQuote(
|
||||
long id,
|
||||
@Deprecated String author,
|
||||
String authorNumber,
|
||||
String authorUuid,
|
||||
String text,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonMention> mentions,
|
||||
List<JsonQuotedAttachment> attachments
|
||||
) {
|
||||
|
||||
@JsonProperty
|
||||
final long id;
|
||||
|
||||
@JsonProperty
|
||||
@Deprecated
|
||||
final String author;
|
||||
|
||||
@JsonProperty
|
||||
final String authorNumber;
|
||||
|
||||
@JsonProperty
|
||||
final String authorUuid;
|
||||
|
||||
@JsonProperty
|
||||
final String text;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<JsonMention> mentions;
|
||||
|
||||
@JsonProperty
|
||||
final List<JsonQuotedAttachment> attachments;
|
||||
|
||||
JsonQuote(SignalServiceDataMessage.Quote quote, Manager m) {
|
||||
this.id = quote.getId();
|
||||
static JsonQuote from(SignalServiceDataMessage.Quote quote, Manager m) {
|
||||
final var id = quote.getId();
|
||||
final var address = m.resolveSignalServiceAddress(quote.getAuthor());
|
||||
this.author = getLegacyIdentifier(address);
|
||||
this.authorNumber = address.getNumber().orNull();
|
||||
this.authorUuid = address.getUuid().toString();
|
||||
this.text = quote.getText();
|
||||
final var author = getLegacyIdentifier(address);
|
||||
final var authorNumber = address.getNumber().orNull();
|
||||
final var authorUuid = address.getUuid().toString();
|
||||
final var text = quote.getText();
|
||||
|
||||
final List<JsonMention> mentions;
|
||||
if (quote.getMentions() != null && quote.getMentions().size() > 0) {
|
||||
this.mentions = quote.getMentions()
|
||||
mentions = quote.getMentions()
|
||||
.stream()
|
||||
.map(quotedMention -> new JsonMention(quotedMention, m))
|
||||
.map(quotedMention -> JsonMention.from(quotedMention, m))
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
this.mentions = null;
|
||||
mentions = null;
|
||||
}
|
||||
|
||||
final List<JsonQuotedAttachment> attachments;
|
||||
if (quote.getAttachments().size() > 0) {
|
||||
this.attachments = quote.getAttachments()
|
||||
.stream()
|
||||
.map(JsonQuotedAttachment::new)
|
||||
.collect(Collectors.toList());
|
||||
attachments = quote.getAttachments().stream().map(JsonQuotedAttachment::from).collect(Collectors.toList());
|
||||
} else {
|
||||
this.attachments = new ArrayList<>();
|
||||
attachments = new ArrayList<>();
|
||||
}
|
||||
|
||||
return new JsonQuote(id, author, authorNumber, authorUuid, text, mentions, attachments);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +1,22 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
|
||||
public class JsonQuotedAttachment {
|
||||
public record JsonQuotedAttachment(
|
||||
String contentType, String filename, @JsonInclude(JsonInclude.Include.NON_NULL) JsonAttachment thumbnail
|
||||
) {
|
||||
|
||||
@JsonProperty
|
||||
final String contentType;
|
||||
|
||||
@JsonProperty
|
||||
final String filename;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonAttachment thumbnail;
|
||||
|
||||
JsonQuotedAttachment(SignalServiceDataMessage.Quote.QuotedAttachment quotedAttachment) {
|
||||
contentType = quotedAttachment.getContentType();
|
||||
filename = quotedAttachment.getFileName();
|
||||
static JsonQuotedAttachment from(SignalServiceDataMessage.Quote.QuotedAttachment quotedAttachment) {
|
||||
final var contentType = quotedAttachment.getContentType();
|
||||
final var filename = quotedAttachment.getFileName();
|
||||
final JsonAttachment thumbnail;
|
||||
if (quotedAttachment.getThumbnail() != null) {
|
||||
thumbnail = new JsonAttachment(quotedAttachment.getThumbnail());
|
||||
thumbnail = JsonAttachment.from(quotedAttachment.getThumbnail());
|
||||
} else {
|
||||
thumbnail = null;
|
||||
}
|
||||
return new JsonQuotedAttachment(contentType, filename, thumbnail);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,40 +1,32 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Reaction;
|
||||
|
||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
||||
|
||||
public class JsonReaction {
|
||||
public record JsonReaction(
|
||||
String emoji,
|
||||
@Deprecated String targetAuthor,
|
||||
String targetAuthorNumber,
|
||||
String targetAuthorUuid,
|
||||
long targetSentTimestamp,
|
||||
boolean isRemove
|
||||
) {
|
||||
|
||||
@JsonProperty
|
||||
final String emoji;
|
||||
|
||||
@JsonProperty
|
||||
@Deprecated
|
||||
final String targetAuthor;
|
||||
|
||||
@JsonProperty
|
||||
final String targetAuthorNumber;
|
||||
|
||||
@JsonProperty
|
||||
final String targetAuthorUuid;
|
||||
|
||||
@JsonProperty
|
||||
final long targetSentTimestamp;
|
||||
|
||||
@JsonProperty
|
||||
final boolean isRemove;
|
||||
|
||||
JsonReaction(Reaction reaction, Manager m) {
|
||||
this.emoji = reaction.getEmoji();
|
||||
static JsonReaction from(Reaction reaction, Manager m) {
|
||||
final var emoji = reaction.getEmoji();
|
||||
final var address = m.resolveSignalServiceAddress(reaction.getTargetAuthor());
|
||||
this.targetAuthor = getLegacyIdentifier(address);
|
||||
this.targetAuthorNumber = address.getNumber().orNull();
|
||||
this.targetAuthorUuid = address.getUuid().toString();
|
||||
this.targetSentTimestamp = reaction.getTargetSentTimestamp();
|
||||
this.isRemove = reaction.isRemove();
|
||||
final var targetAuthor = getLegacyIdentifier(address);
|
||||
final var targetAuthorNumber = address.getNumber().orNull();
|
||||
final var targetAuthorUuid = address.getUuid().toString();
|
||||
final var targetSentTimestamp = reaction.getTargetSentTimestamp();
|
||||
final var isRemove = reaction.isRemove();
|
||||
return new JsonReaction(emoji,
|
||||
targetAuthor,
|
||||
targetAuthorNumber,
|
||||
targetAuthorUuid,
|
||||
targetSentTimestamp,
|
||||
isRemove);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,39 +1,17 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class JsonReceiptMessage {
|
||||
record JsonReceiptMessage(long when, boolean isDelivery, boolean isRead, List<Long> timestamps) {
|
||||
|
||||
@JsonProperty
|
||||
final long when;
|
||||
|
||||
@JsonProperty
|
||||
final boolean isDelivery;
|
||||
|
||||
@JsonProperty
|
||||
final boolean isRead;
|
||||
|
||||
@JsonProperty
|
||||
final List<Long> timestamps;
|
||||
|
||||
JsonReceiptMessage(SignalServiceReceiptMessage receiptMessage) {
|
||||
this.when = receiptMessage.getWhen();
|
||||
this.isDelivery = receiptMessage.isDeliveryReceipt();
|
||||
this.isRead = receiptMessage.isReadReceipt();
|
||||
this.timestamps = receiptMessage.getTimestamps();
|
||||
}
|
||||
|
||||
private JsonReceiptMessage(
|
||||
final long when, final boolean isDelivery, final boolean isRead, final List<Long> timestamps
|
||||
) {
|
||||
this.when = when;
|
||||
this.isDelivery = isDelivery;
|
||||
this.isRead = isRead;
|
||||
this.timestamps = timestamps;
|
||||
static JsonReceiptMessage from(SignalServiceReceiptMessage receiptMessage) {
|
||||
final var when = receiptMessage.getWhen();
|
||||
final var isDelivery = receiptMessage.isDeliveryReceipt();
|
||||
final var isRead = receiptMessage.isReadReceipt();
|
||||
final var timestamps = receiptMessage.getTimestamps();
|
||||
return new JsonReceiptMessage(when, isDelivery, isRead, timestamps);
|
||||
}
|
||||
|
||||
static JsonReceiptMessage deliveryReceipt(final long when, final List<Long> timestamps) {
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
|
||||
class JsonRemoteDelete {
|
||||
record JsonRemoteDelete(long timestamp) {
|
||||
|
||||
@JsonProperty
|
||||
final long timestamp;
|
||||
|
||||
JsonRemoteDelete(SignalServiceDataMessage.RemoteDelete remoteDelete) {
|
||||
this.timestamp = remoteDelete.getTargetSentTimestamp();
|
||||
static JsonRemoteDelete from(SignalServiceDataMessage.RemoteDelete remoteDelete) {
|
||||
return new JsonRemoteDelete(remoteDelete.getTargetSentTimestamp());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,62 +1,45 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JsonSharedContact {
|
||||
public record JsonSharedContact(
|
||||
JsonContactName name,
|
||||
JsonContactAvatar avatar,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonContactPhone> phone,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonContactEmail> email,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonContactAddress> address,
|
||||
String organization
|
||||
) {
|
||||
|
||||
@JsonProperty
|
||||
final JsonContactName name;
|
||||
static JsonSharedContact from(SharedContact contact) {
|
||||
final var name = JsonContactName.from(contact.getName());
|
||||
final var avatar = contact.getAvatar().isPresent() ? JsonContactAvatar.from(contact.getAvatar().get()) : null;
|
||||
|
||||
@JsonProperty
|
||||
final JsonContactAvatar avatar;
|
||||
final var phone = contact.getPhone().isPresent() ? contact.getPhone()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonContactPhone::from)
|
||||
.collect(Collectors.toList()) : null;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<JsonContactPhone> phone;
|
||||
final var email = contact.getEmail().isPresent() ? contact.getEmail()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonContactEmail::from)
|
||||
.collect(Collectors.toList()) : null;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<JsonContactEmail> email;
|
||||
final var address = contact.getAddress().isPresent() ? contact.getAddress()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonContactAddress::from)
|
||||
.collect(Collectors.toList()) : null;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<JsonContactAddress> address;
|
||||
final var organization = contact.getOrganization().orNull();
|
||||
|
||||
@JsonProperty
|
||||
final String organization;
|
||||
|
||||
public JsonSharedContact(SharedContact contact) {
|
||||
name = new JsonContactName(contact.getName());
|
||||
if (contact.getAvatar().isPresent()) {
|
||||
avatar = new JsonContactAvatar(contact.getAvatar().get());
|
||||
} else {
|
||||
avatar = null;
|
||||
}
|
||||
|
||||
if (contact.getPhone().isPresent()) {
|
||||
phone = contact.getPhone().get().stream().map(JsonContactPhone::new).collect(Collectors.toList());
|
||||
} else {
|
||||
phone = null;
|
||||
}
|
||||
|
||||
if (contact.getEmail().isPresent()) {
|
||||
email = contact.getEmail().get().stream().map(JsonContactEmail::new).collect(Collectors.toList());
|
||||
} else {
|
||||
email = null;
|
||||
}
|
||||
|
||||
if (contact.getAddress().isPresent()) {
|
||||
address = contact.getAddress().get().stream().map(JsonContactAddress::new).collect(Collectors.toList());
|
||||
} else {
|
||||
address = null;
|
||||
}
|
||||
|
||||
organization = contact.getOrganization().orNull();
|
||||
return new JsonSharedContact(name, avatar, phone, email, address, organization);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,15 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
public class JsonSticker {
|
||||
public record JsonSticker(String packId, String packKey, int stickerId) {
|
||||
|
||||
@JsonProperty
|
||||
final String packId;
|
||||
|
||||
@JsonProperty
|
||||
final String packKey;
|
||||
|
||||
@JsonProperty
|
||||
final int stickerId;
|
||||
|
||||
public JsonSticker(SignalServiceDataMessage.Sticker sticker) {
|
||||
this.packId = Base64.getEncoder().encodeToString(sticker.getPackId());
|
||||
this.packKey = Base64.getEncoder().encodeToString(sticker.getPackKey());
|
||||
this.stickerId = sticker.getStickerId();
|
||||
static JsonSticker from(SignalServiceDataMessage.Sticker sticker) {
|
||||
final var packId = Base64.getEncoder().encodeToString(sticker.getPackId());
|
||||
final var packKey = Base64.getEncoder().encodeToString(sticker.getPackKey());
|
||||
final var stickerId = sticker.getStickerId();
|
||||
return new JsonSticker(packId, packKey, stickerId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
|
@ -8,37 +8,30 @@ import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptM
|
|||
|
||||
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);
|
||||
record JsonSyncDataMessage(
|
||||
@Deprecated String destination,
|
||||
String destinationNumber,
|
||||
String destinationUuid,
|
||||
@JsonUnwrapped JsonDataMessage dataMessage
|
||||
) {
|
||||
|
||||
static JsonSyncDataMessage from(SentTranscriptMessage transcriptMessage, Manager m) {
|
||||
if (transcriptMessage.getDestination().isPresent()) {
|
||||
final var address = transcriptMessage.getDestination().get();
|
||||
this.destination = getLegacyIdentifier(address);
|
||||
this.destinationNumber = address.getNumber().orNull();
|
||||
this.destinationUuid = address.getUuid().toString();
|
||||
return new JsonSyncDataMessage(getLegacyIdentifier(address),
|
||||
address.getNumber().orNull(),
|
||||
address.getUuid().toString(),
|
||||
JsonDataMessage.from(transcriptMessage.getMessage(), m));
|
||||
|
||||
} else {
|
||||
this.destination = null;
|
||||
this.destinationNumber = null;
|
||||
this.destinationUuid = null;
|
||||
return new JsonSyncDataMessage(null, null, null, JsonDataMessage.from(transcriptMessage.getMessage(), m));
|
||||
}
|
||||
}
|
||||
|
||||
JsonSyncDataMessage(Signal.SyncMessageReceived messageReceived) {
|
||||
super(messageReceived);
|
||||
this.destination = messageReceived.getDestination();
|
||||
this.destinationNumber = null;
|
||||
this.destinationUuid = null;
|
||||
static JsonSyncDataMessage from(Signal.SyncMessageReceived messageReceived) {
|
||||
return new JsonSyncDataMessage(messageReceived.getDestination(),
|
||||
null,
|
||||
null,
|
||||
JsonDataMessage.from(messageReceived));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
|
@ -18,76 +17,72 @@ enum JsonSyncMessageType {
|
|||
REQUEST_SYNC
|
||||
}
|
||||
|
||||
class JsonSyncMessage {
|
||||
record JsonSyncMessage(
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonSyncDataMessage sentMessage,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<String> blockedNumbers,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<String> blockedGroupIds,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonSyncReadMessage> readMessages,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonSyncMessageType type
|
||||
) {
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonSyncDataMessage sentMessage;
|
||||
JsonSyncMessage(
|
||||
final JsonSyncDataMessage sentMessage,
|
||||
final List<String> blockedNumbers,
|
||||
final List<String> blockedGroupIds,
|
||||
final List<JsonSyncReadMessage> readMessages,
|
||||
final JsonSyncMessageType type
|
||||
) {
|
||||
this.sentMessage = sentMessage;
|
||||
this.blockedNumbers = blockedNumbers;
|
||||
this.blockedGroupIds = blockedGroupIds;
|
||||
this.readMessages = readMessages;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<String> blockedNumbers;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<String> blockedGroupIds;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<JsonSyncReadMessage> readMessages;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonSyncMessageType type;
|
||||
|
||||
JsonSyncMessage(SignalServiceSyncMessage syncMessage, Manager m) {
|
||||
this.sentMessage = syncMessage.getSent().isPresent()
|
||||
? new JsonSyncDataMessage(syncMessage.getSent().get(), m)
|
||||
: null;
|
||||
static JsonSyncMessage from(SignalServiceSyncMessage syncMessage, Manager m) {
|
||||
final var sentMessage = syncMessage.getSent().isPresent() ? JsonSyncDataMessage.from(syncMessage.getSent()
|
||||
.get(), m) : null;
|
||||
final List<String> blockedNumbers;
|
||||
final List<String> blockedGroupIds;
|
||||
if (syncMessage.getBlockedList().isPresent()) {
|
||||
final var base64 = Base64.getEncoder();
|
||||
this.blockedNumbers = syncMessage.getBlockedList()
|
||||
blockedNumbers = syncMessage.getBlockedList()
|
||||
.get()
|
||||
.getAddresses()
|
||||
.stream()
|
||||
.map(Util::getLegacyIdentifier)
|
||||
.collect(Collectors.toList());
|
||||
this.blockedGroupIds = syncMessage.getBlockedList()
|
||||
blockedGroupIds = syncMessage.getBlockedList()
|
||||
.get()
|
||||
.getGroupIds()
|
||||
.stream()
|
||||
.map(base64::encodeToString)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
this.blockedNumbers = null;
|
||||
this.blockedGroupIds = null;
|
||||
}
|
||||
if (syncMessage.getRead().isPresent()) {
|
||||
this.readMessages = syncMessage.getRead()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonSyncReadMessage::new)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
this.readMessages = null;
|
||||
blockedNumbers = null;
|
||||
blockedGroupIds = null;
|
||||
}
|
||||
|
||||
final var readMessages = syncMessage.getRead().isPresent() ? syncMessage.getRead()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonSyncReadMessage::from)
|
||||
.collect(Collectors.toList()) : null;
|
||||
|
||||
final JsonSyncMessageType type;
|
||||
if (syncMessage.getContacts().isPresent()) {
|
||||
this.type = JsonSyncMessageType.CONTACTS_SYNC;
|
||||
type = JsonSyncMessageType.CONTACTS_SYNC;
|
||||
} else if (syncMessage.getGroups().isPresent()) {
|
||||
this.type = JsonSyncMessageType.GROUPS_SYNC;
|
||||
type = JsonSyncMessageType.GROUPS_SYNC;
|
||||
} else if (syncMessage.getRequest().isPresent()) {
|
||||
this.type = JsonSyncMessageType.REQUEST_SYNC;
|
||||
type = JsonSyncMessageType.REQUEST_SYNC;
|
||||
} else {
|
||||
this.type = null;
|
||||
type = null;
|
||||
}
|
||||
return new JsonSyncMessage(sentMessage, blockedNumbers, blockedGroupIds, readMessages, type);
|
||||
}
|
||||
|
||||
JsonSyncMessage(Signal.SyncMessageReceived messageReceived) {
|
||||
this.sentMessage = new JsonSyncDataMessage(messageReceived);
|
||||
this.blockedNumbers = null;
|
||||
this.blockedGroupIds = null;
|
||||
this.readMessages = null;
|
||||
this.type = null;
|
||||
static JsonSyncMessage from(Signal.SyncMessageReceived messageReceived) {
|
||||
return new JsonSyncMessage(JsonSyncDataMessage.from(messageReceived), null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,19 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
|
||||
|
||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
||||
|
||||
class JsonSyncReadMessage {
|
||||
record JsonSyncReadMessage(
|
||||
@Deprecated String sender, String senderNumber, String senderUuid, long timestamp
|
||||
) {
|
||||
|
||||
@JsonProperty
|
||||
@Deprecated
|
||||
final String sender;
|
||||
|
||||
@JsonProperty
|
||||
final String senderNumber;
|
||||
|
||||
@JsonProperty
|
||||
final String senderUuid;
|
||||
|
||||
@JsonProperty
|
||||
final long timestamp;
|
||||
|
||||
public JsonSyncReadMessage(final ReadMessage readMessage) {
|
||||
final var sender = readMessage.getSender();
|
||||
this.sender = getLegacyIdentifier(sender);
|
||||
this.senderNumber = sender.getNumber().orNull();
|
||||
this.senderUuid = sender.getUuid().toString();
|
||||
this.timestamp = readMessage.getTimestamp();
|
||||
static JsonSyncReadMessage from(final ReadMessage readMessage) {
|
||||
final var senderAddress = readMessage.getSender();
|
||||
final var sender = getLegacyIdentifier(senderAddress);
|
||||
final var senderNumber = senderAddress.getNumber().orNull();
|
||||
final var senderUuid = senderAddress.getUuid().toString();
|
||||
final var timestamp = readMessage.getTimestamp();
|
||||
return new JsonSyncReadMessage(sender, senderNumber, senderUuid, timestamp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,26 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
class JsonTypingMessage {
|
||||
record JsonTypingMessage(
|
||||
String action, long timestamp, @JsonInclude(JsonInclude.Include.NON_NULL) String groupId
|
||||
) {
|
||||
|
||||
@JsonProperty
|
||||
final String action;
|
||||
JsonTypingMessage(final String action, final long timestamp, final String groupId) {
|
||||
this.action = action;
|
||||
this.timestamp = timestamp;
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
@JsonProperty
|
||||
final long timestamp;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final String groupId;
|
||||
|
||||
JsonTypingMessage(SignalServiceTypingMessage typingMessage) {
|
||||
this.action = typingMessage.getAction().name();
|
||||
this.timestamp = typingMessage.getTimestamp();
|
||||
static JsonTypingMessage from(SignalServiceTypingMessage typingMessage) {
|
||||
final var action = typingMessage.getAction().name();
|
||||
final var timestamp = typingMessage.getTimestamp();
|
||||
final var encoder = Base64.getEncoder();
|
||||
this.groupId = typingMessage.getGroupId().transform(encoder::encodeToString).orNull();
|
||||
final var groupId = typingMessage.getGroupId().transform(encoder::encodeToString).orNull();
|
||||
return new JsonTypingMessage(action, timestamp, groupId);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue