mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Refactor receive api
This commit is contained in:
parent
b615a4b04d
commit
9075cc1a30
36 changed files with 1510 additions and 970 deletions
|
@ -25,7 +25,7 @@ public class AttachmentStore {
|
||||||
public void storeAttachment(
|
public void storeAttachment(
|
||||||
final SignalServiceAttachmentRemoteId attachmentId, final AttachmentStorer storer
|
final SignalServiceAttachmentRemoteId attachmentId, final AttachmentStorer storer
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
storeAttachment(getAttachmentFile(attachmentId), storer);
|
storeAttachment(getAttachmentFile(attachmentId.toString()), storer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeAttachment(final File attachmentFile, final AttachmentStorer storer) throws IOException {
|
private void storeAttachment(final File attachmentFile, final AttachmentStorer storer) throws IOException {
|
||||||
|
@ -39,8 +39,8 @@ public class AttachmentStore {
|
||||||
return new File(attachmentsPath, attachmentId.toString() + ".preview");
|
return new File(attachmentsPath, attachmentId.toString() + ".preview");
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId) {
|
public File getAttachmentFile(String attachmentId) {
|
||||||
return new File(attachmentsPath, attachmentId.toString());
|
return new File(attachmentsPath, attachmentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createAttachmentsDir() throws IOException {
|
private void createAttachmentsDir() throws IOException {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.asamk.signal.manager.api.Identity;
|
||||||
import org.asamk.signal.manager.api.InactiveGroupLinkException;
|
import org.asamk.signal.manager.api.InactiveGroupLinkException;
|
||||||
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
|
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
|
||||||
import org.asamk.signal.manager.api.Message;
|
import org.asamk.signal.manager.api.Message;
|
||||||
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.asamk.signal.manager.api.Pair;
|
import org.asamk.signal.manager.api.Pair;
|
||||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||||
import org.asamk.signal.manager.api.SendGroupMessageResults;
|
import org.asamk.signal.manager.api.SendGroupMessageResults;
|
||||||
|
@ -25,10 +26,6 @@ import org.asamk.signal.manager.storage.identities.TrustNewIdentity;
|
||||||
import org.asamk.signal.manager.storage.recipients.Contact;
|
import org.asamk.signal.manager.storage.recipients.Contact;
|
||||||
import org.asamk.signal.manager.storage.recipients.Profile;
|
import org.asamk.signal.manager.storage.recipients.Profile;
|
||||||
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
|
||||||
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
|
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
|
@ -221,7 +218,7 @@ public interface Manager extends Closeable {
|
||||||
|
|
||||||
boolean isContactBlocked(RecipientIdentifier.Single recipient);
|
boolean isContactBlocked(RecipientIdentifier.Single recipient);
|
||||||
|
|
||||||
File getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId);
|
File getAttachmentFile(String attachmentId);
|
||||||
|
|
||||||
void sendContacts() throws IOException;
|
void sendContacts() throws IOException;
|
||||||
|
|
||||||
|
@ -243,13 +240,11 @@ public interface Manager extends Closeable {
|
||||||
|
|
||||||
boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient);
|
boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient);
|
||||||
|
|
||||||
SignalServiceAddress resolveSignalServiceAddress(SignalServiceAddress address);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void close() throws IOException;
|
void close() throws IOException;
|
||||||
|
|
||||||
interface ReceiveMessageHandler {
|
interface ReceiveMessageHandler {
|
||||||
|
|
||||||
void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent decryptedContent, Throwable e);
|
void handleMessage(MessageEnvelope envelope, Throwable e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,6 @@ import org.whispersystems.libsignal.ecc.ECPublicKey;
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
import org.whispersystems.signalservice.api.SignalSessionLock;
|
import org.whispersystems.signalservice.api.SignalSessionLock;
|
||||||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
||||||
|
@ -904,11 +903,11 @@ public class ManagerImpl implements Manager {
|
||||||
receiveThread = new Thread(() -> {
|
receiveThread = new Thread(() -> {
|
||||||
while (!Thread.interrupted()) {
|
while (!Thread.interrupted()) {
|
||||||
try {
|
try {
|
||||||
receiveMessagesInternal(1L, TimeUnit.HOURS, false, (envelope, decryptedContent, e) -> {
|
receiveMessagesInternal(1L, TimeUnit.HOURS, false, (envelope, e) -> {
|
||||||
synchronized (messageHandlers) {
|
synchronized (messageHandlers) {
|
||||||
for (ReceiveMessageHandler h : messageHandlers) {
|
for (ReceiveMessageHandler h : messageHandlers) {
|
||||||
try {
|
try {
|
||||||
h.handleMessage(envelope, decryptedContent, e);
|
h.handleMessage(envelope, e);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.warn("Message handler failed, ignoring", ex);
|
logger.warn("Message handler failed, ignoring", ex);
|
||||||
}
|
}
|
||||||
|
@ -1140,7 +1139,7 @@ public class ManagerImpl implements Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId) {
|
public File getAttachmentFile(String attachmentId) {
|
||||||
return attachmentHelper.getAttachmentFile(attachmentId);
|
return attachmentHelper.getAttachmentFile(attachmentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1298,11 +1297,6 @@ public class ManagerImpl implements Manager {
|
||||||
this.identityHelper.handleIdentityFailure(recipientId, identityFailure);
|
this.identityHelper.handleIdentityFailure(recipientId, identityFailure);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SignalServiceAddress resolveSignalServiceAddress(SignalServiceAddress address) {
|
|
||||||
return resolveSignalServiceAddress(resolveRecipient(address));
|
|
||||||
}
|
|
||||||
|
|
||||||
private SignalServiceAddress resolveSignalServiceAddress(RecipientId recipientId) {
|
private SignalServiceAddress resolveSignalServiceAddress(RecipientId recipientId) {
|
||||||
final var address = account.getRecipientStore().resolveRecipientAddress(recipientId);
|
final var address = account.getRecipientStore().resolveRecipientAddress(recipientId);
|
||||||
if (address.getUuid().isPresent()) {
|
if (address.getUuid().isPresent()) {
|
||||||
|
@ -1347,6 +1341,10 @@ public class ManagerImpl implements Manager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RecipientId resolveRecipient(RecipientAddress address) {
|
||||||
|
return account.getRecipientStore().resolveRecipient(address);
|
||||||
|
}
|
||||||
|
|
||||||
private RecipientId resolveRecipient(SignalServiceAddress address) {
|
private RecipientId resolveRecipient(SignalServiceAddress address) {
|
||||||
return account.getRecipientStore().resolveRecipient(address);
|
return account.getRecipientStore().resolveRecipient(address);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
package org.asamk.signal.manager;
|
package org.asamk.signal.manager;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||||
|
|
||||||
public class UntrustedIdentityException extends Exception {
|
public class UntrustedIdentityException extends Exception {
|
||||||
|
|
||||||
private final SignalServiceAddress sender;
|
private final RecipientAddress sender;
|
||||||
private final Integer senderDevice;
|
private final Integer senderDevice;
|
||||||
|
|
||||||
public UntrustedIdentityException(final SignalServiceAddress sender) {
|
public UntrustedIdentityException(final RecipientAddress sender) {
|
||||||
this(sender, null);
|
this(sender, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UntrustedIdentityException(final SignalServiceAddress sender, final Integer senderDevice) {
|
public UntrustedIdentityException(final RecipientAddress sender, final Integer senderDevice) {
|
||||||
super("Untrusted identity: " + sender.getIdentifier());
|
super("Untrusted identity: " + sender.getIdentifier());
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.senderDevice = senderDevice;
|
this.senderDevice = senderDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SignalServiceAddress getSender() {
|
public RecipientAddress getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,810 @@
|
||||||
|
package org.asamk.signal.manager.api;
|
||||||
|
|
||||||
|
import org.asamk.signal.manager.groups.GroupId;
|
||||||
|
import org.asamk.signal.manager.groups.GroupUtils;
|
||||||
|
import org.asamk.signal.manager.helper.RecipientAddressResolver;
|
||||||
|
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||||
|
import org.asamk.signal.manager.storage.recipients.RecipientResolver;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroupContext;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.calls.AnswerMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.calls.BusyMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.calls.HangupMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.calls.OfferMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.calls.OpaqueMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.multidevice.MessageRequestResponseMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public record MessageEnvelope(
|
||||||
|
Optional<RecipientAddress> sourceAddress,
|
||||||
|
int sourceDevice,
|
||||||
|
long timestamp,
|
||||||
|
long serverReceivedTimestamp,
|
||||||
|
long serverDeliveredTimestamp,
|
||||||
|
boolean isUnidentifiedSender,
|
||||||
|
Optional<Receipt> receipt,
|
||||||
|
Optional<Typing> typing,
|
||||||
|
Optional<Data> data,
|
||||||
|
Optional<Sync> sync,
|
||||||
|
Optional<Call> call
|
||||||
|
) {
|
||||||
|
|
||||||
|
public static final record Receipt(long when, Type type, List<Long> timestamps) {
|
||||||
|
|
||||||
|
static Receipt from(final SignalServiceReceiptMessage receiptMessage) {
|
||||||
|
return new Receipt(receiptMessage.getWhen(),
|
||||||
|
Type.from(receiptMessage.getType()),
|
||||||
|
receiptMessage.getTimestamps());
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
DELIVERY,
|
||||||
|
READ,
|
||||||
|
VIEWED,
|
||||||
|
UNKNOWN;
|
||||||
|
|
||||||
|
static Type from(SignalServiceReceiptMessage.Type type) {
|
||||||
|
return switch (type) {
|
||||||
|
case DELIVERY -> DELIVERY;
|
||||||
|
case READ -> READ;
|
||||||
|
case VIEWED -> VIEWED;
|
||||||
|
case UNKNOWN -> UNKNOWN;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final record Typing(long timestamp, Type type, Optional<GroupId> groupId) {
|
||||||
|
|
||||||
|
public static Typing from(final SignalServiceTypingMessage typingMessage) {
|
||||||
|
return new Typing(typingMessage.getTimestamp(),
|
||||||
|
typingMessage.isTypingStarted() ? Type.STARTED : Type.STOPPED,
|
||||||
|
Optional.ofNullable(typingMessage.getGroupId().transform(GroupId::unknownVersion).orNull()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
STARTED,
|
||||||
|
STOPPED,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final record Data(
|
||||||
|
long timestamp,
|
||||||
|
Optional<GroupContext> groupContext,
|
||||||
|
Optional<GroupCallUpdate> groupCallUpdate,
|
||||||
|
Optional<String> body,
|
||||||
|
int expiresInSeconds,
|
||||||
|
boolean isExpirationUpdate,
|
||||||
|
boolean isViewOnce,
|
||||||
|
boolean isEndSession,
|
||||||
|
boolean hasProfileKey,
|
||||||
|
Optional<Reaction> reaction,
|
||||||
|
Optional<Quote> quote,
|
||||||
|
List<Attachment> attachments,
|
||||||
|
Optional<Long> remoteDeleteId,
|
||||||
|
Optional<Sticker> sticker,
|
||||||
|
List<SharedContact> sharedContacts,
|
||||||
|
List<Mention> mentions,
|
||||||
|
List<Preview> previews
|
||||||
|
) {
|
||||||
|
|
||||||
|
static Data from(
|
||||||
|
final SignalServiceDataMessage dataMessage,
|
||||||
|
RecipientResolver recipientResolver,
|
||||||
|
RecipientAddressResolver addressResolver
|
||||||
|
) {
|
||||||
|
return new Data(dataMessage.getTimestamp(),
|
||||||
|
Optional.ofNullable(dataMessage.getGroupContext().transform(GroupContext::from).orNull()),
|
||||||
|
Optional.ofNullable(dataMessage.getGroupCallUpdate().transform(GroupCallUpdate::from).orNull()),
|
||||||
|
Optional.ofNullable(dataMessage.getBody().orNull()),
|
||||||
|
dataMessage.getExpiresInSeconds(),
|
||||||
|
dataMessage.isExpirationUpdate(),
|
||||||
|
dataMessage.isViewOnce(),
|
||||||
|
dataMessage.isEndSession(),
|
||||||
|
dataMessage.getProfileKey().isPresent(),
|
||||||
|
Optional.ofNullable(dataMessage.getReaction()
|
||||||
|
.transform(r -> Reaction.from(r, recipientResolver, addressResolver))
|
||||||
|
.orNull()),
|
||||||
|
Optional.ofNullable(dataMessage.getQuote()
|
||||||
|
.transform(q -> Quote.from(q, recipientResolver, addressResolver))
|
||||||
|
.orNull()),
|
||||||
|
dataMessage.getAttachments()
|
||||||
|
.transform(a -> a.stream().map(Attachment::from).collect(Collectors.toList()))
|
||||||
|
.or(List.of()),
|
||||||
|
Optional.ofNullable(dataMessage.getRemoteDelete()
|
||||||
|
.transform(SignalServiceDataMessage.RemoteDelete::getTargetSentTimestamp)
|
||||||
|
.orNull()),
|
||||||
|
Optional.ofNullable(dataMessage.getSticker().transform(Sticker::from).orNull()),
|
||||||
|
dataMessage.getSharedContacts()
|
||||||
|
.transform(a -> a.stream().map(SharedContact::from).collect(Collectors.toList()))
|
||||||
|
.or(List.of()),
|
||||||
|
dataMessage.getMentions()
|
||||||
|
.transform(a -> a.stream()
|
||||||
|
.map(m -> Mention.from(m, recipientResolver, addressResolver))
|
||||||
|
.collect(Collectors.toList()))
|
||||||
|
.or(List.of()),
|
||||||
|
dataMessage.getPreviews()
|
||||||
|
.transform(a -> a.stream().map(Preview::from).collect(Collectors.toList()))
|
||||||
|
.or(List.of()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public record GroupContext(GroupId groupId, boolean isGroupUpdate, int revision) {
|
||||||
|
|
||||||
|
static GroupContext from(SignalServiceGroupContext groupContext) {
|
||||||
|
if (groupContext.getGroupV1().isPresent()) {
|
||||||
|
return new GroupContext(GroupId.v1(groupContext.getGroupV1().get().getGroupId()),
|
||||||
|
groupContext.getGroupV1Type() == SignalServiceGroup.Type.UPDATE,
|
||||||
|
0);
|
||||||
|
} else if (groupContext.getGroupV2().isPresent()) {
|
||||||
|
final var groupV2 = groupContext.getGroupV2().get();
|
||||||
|
return new GroupContext(GroupUtils.getGroupIdV2(groupV2.getMasterKey()),
|
||||||
|
groupV2.hasSignedGroupChange(),
|
||||||
|
groupV2.getRevision());
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Invalid group context state");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record GroupCallUpdate(String eraId) {
|
||||||
|
|
||||||
|
static GroupCallUpdate from(SignalServiceDataMessage.GroupCallUpdate groupCallUpdate) {
|
||||||
|
return new GroupCallUpdate(groupCallUpdate.getEraId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Reaction(
|
||||||
|
long targetSentTimestamp, RecipientAddress targetAuthor, String emoji, boolean isRemove
|
||||||
|
) {
|
||||||
|
|
||||||
|
static Reaction from(
|
||||||
|
SignalServiceDataMessage.Reaction reaction,
|
||||||
|
RecipientResolver recipientResolver,
|
||||||
|
RecipientAddressResolver addressResolver
|
||||||
|
) {
|
||||||
|
return new Reaction(reaction.getTargetSentTimestamp(),
|
||||||
|
addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(reaction.getTargetAuthor())),
|
||||||
|
reaction.getEmoji(),
|
||||||
|
reaction.isRemove());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Quote(
|
||||||
|
long id,
|
||||||
|
RecipientAddress author,
|
||||||
|
Optional<String> text,
|
||||||
|
List<Mention> mentions,
|
||||||
|
List<Attachment> attachments
|
||||||
|
) {
|
||||||
|
|
||||||
|
static Quote from(
|
||||||
|
SignalServiceDataMessage.Quote quote,
|
||||||
|
RecipientResolver recipientResolver,
|
||||||
|
RecipientAddressResolver addressResolver
|
||||||
|
) {
|
||||||
|
return new Quote(quote.getId(),
|
||||||
|
addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(quote.getAuthor())),
|
||||||
|
Optional.ofNullable(quote.getText()),
|
||||||
|
quote.getMentions()
|
||||||
|
.stream()
|
||||||
|
.map(m -> Mention.from(m, recipientResolver, addressResolver))
|
||||||
|
.collect(Collectors.toList()),
|
||||||
|
quote.getAttachments().stream().map(Attachment::from).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Mention(RecipientAddress recipient, int start, int length) {
|
||||||
|
|
||||||
|
static Mention from(
|
||||||
|
SignalServiceDataMessage.Mention mention,
|
||||||
|
RecipientResolver recipientResolver,
|
||||||
|
RecipientAddressResolver addressResolver
|
||||||
|
) {
|
||||||
|
return new Mention(addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(mention.getUuid())),
|
||||||
|
mention.getStart(),
|
||||||
|
mention.getLength());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Attachment(
|
||||||
|
Optional<String> id,
|
||||||
|
Optional<String> fileName,
|
||||||
|
String contentType,
|
||||||
|
Optional<Long> uploadTimestamp,
|
||||||
|
Optional<Long> size,
|
||||||
|
Optional<byte[]> preview,
|
||||||
|
Optional<Attachment> thumbnail,
|
||||||
|
Optional<String> caption,
|
||||||
|
Optional<Integer> width,
|
||||||
|
Optional<Integer> height,
|
||||||
|
boolean isVoiceNote,
|
||||||
|
boolean isGif,
|
||||||
|
boolean isBorderless
|
||||||
|
) {
|
||||||
|
|
||||||
|
static Attachment from(SignalServiceAttachment attachment) {
|
||||||
|
if (attachment.isPointer()) {
|
||||||
|
final var a = attachment.asPointer();
|
||||||
|
return new Attachment(Optional.of(a.getRemoteId().toString()),
|
||||||
|
Optional.ofNullable(a.getFileName().orNull()),
|
||||||
|
a.getContentType(),
|
||||||
|
a.getUploadTimestamp() == 0 ? Optional.empty() : Optional.of(a.getUploadTimestamp()),
|
||||||
|
Optional.ofNullable(a.getSize().transform(Integer::longValue).orNull()),
|
||||||
|
Optional.ofNullable(a.getPreview().orNull()),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.ofNullable(a.getCaption().orNull()),
|
||||||
|
a.getWidth() == 0 ? Optional.empty() : Optional.of(a.getWidth()),
|
||||||
|
a.getHeight() == 0 ? Optional.empty() : Optional.of(a.getHeight()),
|
||||||
|
a.getVoiceNote(),
|
||||||
|
a.isGif(),
|
||||||
|
a.isBorderless());
|
||||||
|
} else {
|
||||||
|
final var a = attachment.asStream();
|
||||||
|
return new Attachment(Optional.empty(),
|
||||||
|
Optional.ofNullable(a.getFileName().orNull()),
|
||||||
|
a.getContentType(),
|
||||||
|
a.getUploadTimestamp() == 0 ? Optional.empty() : Optional.of(a.getUploadTimestamp()),
|
||||||
|
Optional.of(a.getLength()),
|
||||||
|
Optional.ofNullable(a.getPreview().orNull()),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.ofNullable(a.getCaption().orNull()),
|
||||||
|
a.getWidth() == 0 ? Optional.empty() : Optional.of(a.getWidth()),
|
||||||
|
a.getHeight() == 0 ? Optional.empty() : Optional.of(a.getHeight()),
|
||||||
|
a.getVoiceNote(),
|
||||||
|
a.isGif(),
|
||||||
|
a.isBorderless());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Attachment from(SignalServiceDataMessage.Quote.QuotedAttachment a) {
|
||||||
|
return new Attachment(Optional.empty(),
|
||||||
|
Optional.ofNullable(a.getFileName()),
|
||||||
|
a.getContentType(),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.empty(),
|
||||||
|
a.getThumbnail() == null ? Optional.empty() : Optional.of(Attachment.from(a.getThumbnail())),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.empty(),
|
||||||
|
Optional.empty(),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Sticker(byte[] packId, byte[] packKey, int stickerId) {
|
||||||
|
|
||||||
|
static Sticker from(SignalServiceDataMessage.Sticker sticker) {
|
||||||
|
return new Sticker(sticker.getPackId(), sticker.getPackKey(), sticker.getStickerId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record SharedContact(
|
||||||
|
Name name,
|
||||||
|
Optional<Avatar> avatar,
|
||||||
|
List<Phone> phone,
|
||||||
|
List<Email> email,
|
||||||
|
List<Address> address,
|
||||||
|
Optional<String> organization
|
||||||
|
) {
|
||||||
|
|
||||||
|
static SharedContact from(org.whispersystems.signalservice.api.messages.shared.SharedContact sharedContact) {
|
||||||
|
return new SharedContact(Name.from(sharedContact.getName()),
|
||||||
|
Optional.ofNullable(sharedContact.getAvatar().transform(Avatar::from).orNull()),
|
||||||
|
sharedContact.getPhone()
|
||||||
|
.transform(p -> p.stream().map(Phone::from).collect(Collectors.toList()))
|
||||||
|
.or(List.of()),
|
||||||
|
sharedContact.getEmail()
|
||||||
|
.transform(p -> p.stream().map(Email::from).collect(Collectors.toList()))
|
||||||
|
.or(List.of()),
|
||||||
|
sharedContact.getAddress()
|
||||||
|
.transform(p -> p.stream().map(Address::from).collect(Collectors.toList()))
|
||||||
|
.or(List.of()),
|
||||||
|
Optional.ofNullable(sharedContact.getOrganization().orNull()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Name(
|
||||||
|
Optional<String> display,
|
||||||
|
Optional<String> given,
|
||||||
|
Optional<String> family,
|
||||||
|
Optional<String> prefix,
|
||||||
|
Optional<String> suffix,
|
||||||
|
Optional<String> middle
|
||||||
|
) {
|
||||||
|
|
||||||
|
static Name from(org.whispersystems.signalservice.api.messages.shared.SharedContact.Name name) {
|
||||||
|
return new Name(Optional.ofNullable(name.getDisplay().orNull()),
|
||||||
|
Optional.ofNullable(name.getGiven().orNull()),
|
||||||
|
Optional.ofNullable(name.getFamily().orNull()),
|
||||||
|
Optional.ofNullable(name.getPrefix().orNull()),
|
||||||
|
Optional.ofNullable(name.getSuffix().orNull()),
|
||||||
|
Optional.ofNullable(name.getMiddle().orNull()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Avatar(Attachment attachment, boolean isProfile) {
|
||||||
|
|
||||||
|
static Avatar from(org.whispersystems.signalservice.api.messages.shared.SharedContact.Avatar avatar) {
|
||||||
|
return new Avatar(Attachment.from(avatar.getAttachment()), avatar.isProfile());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Phone(
|
||||||
|
String value, Type type, Optional<String> label
|
||||||
|
) {
|
||||||
|
|
||||||
|
static Phone from(org.whispersystems.signalservice.api.messages.shared.SharedContact.Phone phone) {
|
||||||
|
return new Phone(phone.getValue(),
|
||||||
|
Type.from(phone.getType()),
|
||||||
|
Optional.ofNullable(phone.getLabel().orNull()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
HOME,
|
||||||
|
WORK,
|
||||||
|
MOBILE,
|
||||||
|
CUSTOM;
|
||||||
|
|
||||||
|
static Type from(org.whispersystems.signalservice.api.messages.shared.SharedContact.Phone.Type type) {
|
||||||
|
return switch (type) {
|
||||||
|
case HOME -> HOME;
|
||||||
|
case WORK -> WORK;
|
||||||
|
case MOBILE -> MOBILE;
|
||||||
|
case CUSTOM -> CUSTOM;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Email(
|
||||||
|
String value, Type type, Optional<String> label
|
||||||
|
) {
|
||||||
|
|
||||||
|
static Email from(org.whispersystems.signalservice.api.messages.shared.SharedContact.Email email) {
|
||||||
|
return new Email(email.getValue(),
|
||||||
|
Type.from(email.getType()),
|
||||||
|
Optional.ofNullable(email.getLabel().orNull()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
HOME,
|
||||||
|
WORK,
|
||||||
|
MOBILE,
|
||||||
|
CUSTOM;
|
||||||
|
|
||||||
|
static Type from(org.whispersystems.signalservice.api.messages.shared.SharedContact.Email.Type type) {
|
||||||
|
return switch (type) {
|
||||||
|
case HOME -> HOME;
|
||||||
|
case WORK -> WORK;
|
||||||
|
case MOBILE -> MOBILE;
|
||||||
|
case CUSTOM -> CUSTOM;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Address(
|
||||||
|
Type type,
|
||||||
|
Optional<String> label,
|
||||||
|
Optional<String> street,
|
||||||
|
Optional<String> pobox,
|
||||||
|
Optional<String> neighborhood,
|
||||||
|
Optional<String> city,
|
||||||
|
Optional<String> region,
|
||||||
|
Optional<String> postcode,
|
||||||
|
Optional<String> country
|
||||||
|
) {
|
||||||
|
|
||||||
|
static Address from(org.whispersystems.signalservice.api.messages.shared.SharedContact.PostalAddress address) {
|
||||||
|
return new Address(Address.Type.from(address.getType()),
|
||||||
|
Optional.ofNullable(address.getLabel().orNull()),
|
||||||
|
Optional.ofNullable(address.getLabel().orNull()),
|
||||||
|
Optional.ofNullable(address.getLabel().orNull()),
|
||||||
|
Optional.ofNullable(address.getLabel().orNull()),
|
||||||
|
Optional.ofNullable(address.getLabel().orNull()),
|
||||||
|
Optional.ofNullable(address.getLabel().orNull()),
|
||||||
|
Optional.ofNullable(address.getLabel().orNull()),
|
||||||
|
Optional.ofNullable(address.getLabel().orNull()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
HOME,
|
||||||
|
WORK,
|
||||||
|
CUSTOM;
|
||||||
|
|
||||||
|
static Type from(org.whispersystems.signalservice.api.messages.shared.SharedContact.PostalAddress.Type type) {
|
||||||
|
return switch (type) {
|
||||||
|
case HOME -> HOME;
|
||||||
|
case WORK -> WORK;
|
||||||
|
case CUSTOM -> CUSTOM;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Preview(String title, String description, long date, String url, Optional<Attachment> image) {
|
||||||
|
|
||||||
|
static Preview from(SignalServiceDataMessage.Preview preview) {
|
||||||
|
return new Preview(preview.getTitle(),
|
||||||
|
preview.getDescription(),
|
||||||
|
preview.getDate(),
|
||||||
|
preview.getUrl(),
|
||||||
|
Optional.ofNullable(preview.getImage().transform(Attachment::from).orNull()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final record Sync(
|
||||||
|
Optional<Sent> sent,
|
||||||
|
Optional<Blocked> blocked,
|
||||||
|
List<Read> read,
|
||||||
|
List<Viewed> viewed,
|
||||||
|
Optional<ViewOnceOpen> viewOnceOpen,
|
||||||
|
Optional<Contacts> contacts,
|
||||||
|
Optional<Groups> groups,
|
||||||
|
Optional<MessageRequestResponse> messageRequestResponse
|
||||||
|
) {
|
||||||
|
|
||||||
|
public static Sync from(
|
||||||
|
final SignalServiceSyncMessage syncMessage,
|
||||||
|
RecipientResolver recipientResolver,
|
||||||
|
RecipientAddressResolver addressResolver
|
||||||
|
) {
|
||||||
|
return new Sync(Optional.ofNullable(syncMessage.getSent()
|
||||||
|
.transform(s -> Sent.from(s, recipientResolver, addressResolver))
|
||||||
|
.orNull()),
|
||||||
|
Optional.ofNullable(syncMessage.getBlockedList()
|
||||||
|
.transform(b -> Blocked.from(b, recipientResolver, addressResolver))
|
||||||
|
.orNull()),
|
||||||
|
syncMessage.getRead()
|
||||||
|
.transform(r -> r.stream()
|
||||||
|
.map(rm -> Read.from(rm, recipientResolver, addressResolver))
|
||||||
|
.collect(Collectors.toList()))
|
||||||
|
.or(List.of()),
|
||||||
|
syncMessage.getViewed()
|
||||||
|
.transform(r -> r.stream()
|
||||||
|
.map(rm -> Viewed.from(rm, recipientResolver, addressResolver))
|
||||||
|
.collect(Collectors.toList()))
|
||||||
|
.or(List.of()),
|
||||||
|
Optional.ofNullable(syncMessage.getViewOnceOpen()
|
||||||
|
.transform(rm -> ViewOnceOpen.from(rm, recipientResolver, addressResolver))
|
||||||
|
.orNull()),
|
||||||
|
Optional.ofNullable(syncMessage.getContacts().transform(Contacts::from).orNull()),
|
||||||
|
Optional.ofNullable(syncMessage.getGroups().transform(Groups::from).orNull()),
|
||||||
|
Optional.ofNullable(syncMessage.getMessageRequestResponse()
|
||||||
|
.transform(m -> MessageRequestResponse.from(m, recipientResolver, addressResolver))
|
||||||
|
.orNull()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Sent(
|
||||||
|
long timestamp,
|
||||||
|
long expirationStartTimestamp,
|
||||||
|
Optional<RecipientAddress> destination,
|
||||||
|
Set<RecipientAddress> recipients,
|
||||||
|
Data message
|
||||||
|
) {
|
||||||
|
|
||||||
|
static Sent from(
|
||||||
|
SentTranscriptMessage sentMessage,
|
||||||
|
RecipientResolver recipientResolver,
|
||||||
|
RecipientAddressResolver addressResolver
|
||||||
|
) {
|
||||||
|
return new Sent(sentMessage.getTimestamp(),
|
||||||
|
sentMessage.getExpirationStartTimestamp(),
|
||||||
|
Optional.ofNullable(sentMessage.getDestination()
|
||||||
|
.transform(d -> addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(
|
||||||
|
d)))
|
||||||
|
.orNull()),
|
||||||
|
sentMessage.getRecipients()
|
||||||
|
.stream()
|
||||||
|
.map(d -> addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(d)))
|
||||||
|
.collect(Collectors.toSet()),
|
||||||
|
Data.from(sentMessage.getMessage(), recipientResolver, addressResolver));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Blocked(List<RecipientAddress> recipients, List<GroupId> groupIds) {
|
||||||
|
|
||||||
|
static Blocked from(
|
||||||
|
BlockedListMessage blockedListMessage,
|
||||||
|
RecipientResolver recipientResolver,
|
||||||
|
RecipientAddressResolver addressResolver
|
||||||
|
) {
|
||||||
|
return new Blocked(blockedListMessage.getAddresses()
|
||||||
|
.stream()
|
||||||
|
.map(d -> addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(d)))
|
||||||
|
.collect(Collectors.toList()),
|
||||||
|
blockedListMessage.getGroupIds()
|
||||||
|
.stream()
|
||||||
|
.map(GroupId::unknownVersion)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Read(RecipientAddress sender, long timestamp) {
|
||||||
|
|
||||||
|
static Read from(
|
||||||
|
ReadMessage readMessage,
|
||||||
|
RecipientResolver recipientResolver,
|
||||||
|
RecipientAddressResolver addressResolver
|
||||||
|
) {
|
||||||
|
return new Read(addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(readMessage.getSender())),
|
||||||
|
readMessage.getTimestamp());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Viewed(RecipientAddress sender, long timestamp) {
|
||||||
|
|
||||||
|
static Viewed from(
|
||||||
|
ViewedMessage readMessage,
|
||||||
|
RecipientResolver recipientResolver,
|
||||||
|
RecipientAddressResolver addressResolver
|
||||||
|
) {
|
||||||
|
return new Viewed(addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(readMessage.getSender())),
|
||||||
|
readMessage.getTimestamp());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record ViewOnceOpen(RecipientAddress sender, long timestamp) {
|
||||||
|
|
||||||
|
static ViewOnceOpen from(
|
||||||
|
ViewOnceOpenMessage readMessage,
|
||||||
|
RecipientResolver recipientResolver,
|
||||||
|
RecipientAddressResolver addressResolver
|
||||||
|
) {
|
||||||
|
return new ViewOnceOpen(addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(
|
||||||
|
readMessage.getSender())), readMessage.getTimestamp());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Contacts(boolean isComplete) {
|
||||||
|
|
||||||
|
static Contacts from(ContactsMessage contactsMessage) {
|
||||||
|
return new Contacts(contactsMessage.isComplete());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Groups() {
|
||||||
|
|
||||||
|
static Groups from(SignalServiceAttachment groupsMessage) {
|
||||||
|
return new Groups();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record MessageRequestResponse(Type type, Optional<GroupId> groupId, Optional<RecipientAddress> person) {
|
||||||
|
|
||||||
|
static MessageRequestResponse from(
|
||||||
|
MessageRequestResponseMessage messageRequestResponse,
|
||||||
|
RecipientResolver recipientResolver,
|
||||||
|
RecipientAddressResolver addressResolver
|
||||||
|
) {
|
||||||
|
return new MessageRequestResponse(Type.from(messageRequestResponse.getType()),
|
||||||
|
Optional.ofNullable(messageRequestResponse.getGroupId()
|
||||||
|
.transform(GroupId::unknownVersion)
|
||||||
|
.orNull()),
|
||||||
|
Optional.ofNullable(messageRequestResponse.getPerson()
|
||||||
|
.transform(p -> addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(
|
||||||
|
p)))
|
||||||
|
.orNull()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
UNKNOWN,
|
||||||
|
ACCEPT,
|
||||||
|
DELETE,
|
||||||
|
BLOCK,
|
||||||
|
BLOCK_AND_DELETE,
|
||||||
|
UNBLOCK_AND_ACCEPT;
|
||||||
|
|
||||||
|
static Type from(MessageRequestResponseMessage.Type type) {
|
||||||
|
return switch (type) {
|
||||||
|
case UNKNOWN -> UNKNOWN;
|
||||||
|
case ACCEPT -> ACCEPT;
|
||||||
|
case DELETE -> DELETE;
|
||||||
|
case BLOCK -> BLOCK;
|
||||||
|
case BLOCK_AND_DELETE -> BLOCK_AND_DELETE;
|
||||||
|
case UNBLOCK_AND_ACCEPT -> UNBLOCK_AND_ACCEPT;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final record Call(
|
||||||
|
Optional<Integer> destinationDeviceId,
|
||||||
|
Optional<GroupId> groupId,
|
||||||
|
Optional<Long> timestamp,
|
||||||
|
Optional<Offer> offer,
|
||||||
|
Optional<Answer> answer,
|
||||||
|
Optional<Hangup> hangup,
|
||||||
|
Optional<Busy> busy,
|
||||||
|
List<IceUpdate> iceUpdate,
|
||||||
|
Optional<Opaque> opaque
|
||||||
|
) {
|
||||||
|
|
||||||
|
public static Call from(final SignalServiceCallMessage callMessage) {
|
||||||
|
return new Call(Optional.ofNullable(callMessage.getDestinationDeviceId().orNull()),
|
||||||
|
Optional.ofNullable(callMessage.getGroupId().transform(GroupId::unknownVersion).orNull()),
|
||||||
|
Optional.ofNullable(callMessage.getTimestamp().orNull()),
|
||||||
|
Optional.ofNullable(callMessage.getOfferMessage().transform(Offer::from).orNull()),
|
||||||
|
Optional.ofNullable(callMessage.getAnswerMessage().transform(Answer::from).orNull()),
|
||||||
|
Optional.ofNullable(callMessage.getHangupMessage().transform(Hangup::from).orNull()),
|
||||||
|
Optional.ofNullable(callMessage.getBusyMessage().transform(Busy::from).orNull()),
|
||||||
|
callMessage.getIceUpdateMessages()
|
||||||
|
.transform(m -> m.stream().map(IceUpdate::from).collect(Collectors.toList()))
|
||||||
|
.or(List.of()),
|
||||||
|
Optional.ofNullable(callMessage.getOpaqueMessage().transform(Opaque::from).orNull()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Offer(long id, String sdp, Type type, byte[] opaque) {
|
||||||
|
|
||||||
|
static Offer from(OfferMessage offerMessage) {
|
||||||
|
return new Offer(offerMessage.getId(),
|
||||||
|
offerMessage.getSdp(),
|
||||||
|
Type.from(offerMessage.getType()),
|
||||||
|
offerMessage.getOpaque());
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
AUDIO_CALL,
|
||||||
|
VIDEO_CALL;
|
||||||
|
|
||||||
|
static Type from(OfferMessage.Type type) {
|
||||||
|
return switch (type) {
|
||||||
|
case AUDIO_CALL -> AUDIO_CALL;
|
||||||
|
case VIDEO_CALL -> VIDEO_CALL;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Answer(long id, String sdp, byte[] opaque) {
|
||||||
|
|
||||||
|
static Answer from(AnswerMessage answerMessage) {
|
||||||
|
return new Answer(answerMessage.getId(), answerMessage.getSdp(), answerMessage.getOpaque());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Busy(long id) {
|
||||||
|
|
||||||
|
static Offer from(OfferMessage offerMessage) {
|
||||||
|
return new Offer(offerMessage.getId(),
|
||||||
|
offerMessage.getSdp(),
|
||||||
|
Offer.Type.from(offerMessage.getType()),
|
||||||
|
offerMessage.getOpaque());
|
||||||
|
}
|
||||||
|
|
||||||
|
static Busy from(BusyMessage busyMessage) {
|
||||||
|
return new Busy(busyMessage.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Hangup(long id, Type type, int deviceId, boolean isLegacy) {
|
||||||
|
|
||||||
|
static Hangup from(HangupMessage hangupMessage) {
|
||||||
|
return new Hangup(hangupMessage.getId(),
|
||||||
|
Type.from(hangupMessage.getType()),
|
||||||
|
hangupMessage.getDeviceId(),
|
||||||
|
hangupMessage.isLegacy());
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
NORMAL,
|
||||||
|
ACCEPTED,
|
||||||
|
DECLINED,
|
||||||
|
BUSY,
|
||||||
|
NEED_PERMISSION;
|
||||||
|
|
||||||
|
static Type from(HangupMessage.Type type) {
|
||||||
|
return switch (type) {
|
||||||
|
case NORMAL -> NORMAL;
|
||||||
|
case ACCEPTED -> ACCEPTED;
|
||||||
|
case DECLINED -> DECLINED;
|
||||||
|
case BUSY -> BUSY;
|
||||||
|
case NEED_PERMISSION -> NEED_PERMISSION;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record IceUpdate(long id, String sdp, byte[] opaque) {
|
||||||
|
|
||||||
|
static IceUpdate from(IceUpdateMessage iceUpdateMessage) {
|
||||||
|
return new IceUpdate(iceUpdateMessage.getId(), iceUpdateMessage.getSdp(), iceUpdateMessage.getOpaque());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Opaque(byte[] opaque, Urgency urgency) {
|
||||||
|
|
||||||
|
static Opaque from(OpaqueMessage opaqueMessage) {
|
||||||
|
return new Opaque(opaqueMessage.getOpaque(), Urgency.from(opaqueMessage.getUrgency()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Urgency {
|
||||||
|
DROPPABLE,
|
||||||
|
HANDLE_IMMEDIATELY;
|
||||||
|
|
||||||
|
static Urgency from(OpaqueMessage.Urgency urgency) {
|
||||||
|
return switch (urgency) {
|
||||||
|
case DROPPABLE -> DROPPABLE;
|
||||||
|
case HANDLE_IMMEDIATELY -> HANDLE_IMMEDIATELY;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageEnvelope from(
|
||||||
|
SignalServiceEnvelope envelope,
|
||||||
|
SignalServiceContent content,
|
||||||
|
RecipientResolver recipientResolver,
|
||||||
|
RecipientAddressResolver addressResolver
|
||||||
|
) {
|
||||||
|
final var source = !envelope.isUnidentifiedSender() && envelope.hasSourceUuid()
|
||||||
|
? recipientResolver.resolveRecipient(envelope.getSourceAddress())
|
||||||
|
: envelope.isUnidentifiedSender() && content != null
|
||||||
|
? recipientResolver.resolveRecipient(content.getSender())
|
||||||
|
: null;
|
||||||
|
final var sourceDevice = envelope.hasSourceDevice()
|
||||||
|
? envelope.getSourceDevice()
|
||||||
|
: content != null ? content.getSenderDevice() : 0;
|
||||||
|
|
||||||
|
Optional<Receipt> receipt;
|
||||||
|
Optional<Typing> typing;
|
||||||
|
Optional<Data> data;
|
||||||
|
Optional<Sync> sync;
|
||||||
|
Optional<Call> call;
|
||||||
|
if (content != null) {
|
||||||
|
receipt = Optional.ofNullable(content.getReceiptMessage().transform(Receipt::from).orNull());
|
||||||
|
typing = Optional.ofNullable(content.getTypingMessage().transform(Typing::from).orNull());
|
||||||
|
data = Optional.ofNullable(content.getDataMessage()
|
||||||
|
.transform(dataMessage -> Data.from(dataMessage, recipientResolver, addressResolver))
|
||||||
|
.orNull());
|
||||||
|
sync = Optional.ofNullable(content.getSyncMessage()
|
||||||
|
.transform(s -> Sync.from(s, recipientResolver, addressResolver))
|
||||||
|
.orNull());
|
||||||
|
call = Optional.ofNullable(content.getCallMessage().transform(Call::from).orNull());
|
||||||
|
} else {
|
||||||
|
receipt = Optional.empty();
|
||||||
|
typing = Optional.empty();
|
||||||
|
data = Optional.empty();
|
||||||
|
sync = Optional.empty();
|
||||||
|
call = Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new MessageEnvelope(source == null
|
||||||
|
? Optional.empty()
|
||||||
|
: Optional.of(addressResolver.resolveRecipientAddress(source)),
|
||||||
|
sourceDevice,
|
||||||
|
envelope.getTimestamp(),
|
||||||
|
envelope.getServerReceivedTimestamp(),
|
||||||
|
envelope.getServerDeliveredTimestamp(),
|
||||||
|
envelope.isUnidentifiedSender(),
|
||||||
|
receipt,
|
||||||
|
typing,
|
||||||
|
data,
|
||||||
|
sync,
|
||||||
|
call);
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,6 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.whispersystems.libsignal.InvalidMessageException;
|
import org.whispersystems.libsignal.InvalidMessageException;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId;
|
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException;
|
import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -36,7 +35,7 @@ public class AttachmentHelper {
|
||||||
this.attachmentStore = attachmentStore;
|
this.attachmentStore = attachmentStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId) {
|
public File getAttachmentFile(String attachmentId) {
|
||||||
return attachmentStore.getAttachmentFile(attachmentId);
|
return attachmentStore.getAttachmentFile(attachmentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.asamk.signal.manager.actions.SendSyncConfigurationAction;
|
||||||
import org.asamk.signal.manager.actions.SendSyncContactsAction;
|
import org.asamk.signal.manager.actions.SendSyncContactsAction;
|
||||||
import org.asamk.signal.manager.actions.SendSyncGroupsAction;
|
import org.asamk.signal.manager.actions.SendSyncGroupsAction;
|
||||||
import org.asamk.signal.manager.actions.SendSyncKeysAction;
|
import org.asamk.signal.manager.actions.SendSyncKeysAction;
|
||||||
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.asamk.signal.manager.api.Pair;
|
import org.asamk.signal.manager.api.Pair;
|
||||||
import org.asamk.signal.manager.groups.GroupId;
|
import org.asamk.signal.manager.groups.GroupId;
|
||||||
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
||||||
|
@ -109,8 +110,8 @@ public final class IncomingMessageHandler {
|
||||||
content = dependencies.getCipher().decrypt(envelope);
|
content = dependencies.getCipher().decrypt(envelope);
|
||||||
} catch (ProtocolUntrustedIdentityException e) {
|
} catch (ProtocolUntrustedIdentityException e) {
|
||||||
final var recipientId = account.getRecipientStore().resolveRecipient(e.getSender());
|
final var recipientId = account.getRecipientStore().resolveRecipient(e.getSender());
|
||||||
final var exception = new UntrustedIdentityException(addressResolver.resolveSignalServiceAddress(
|
final var exception = new UntrustedIdentityException(account.getRecipientStore()
|
||||||
recipientId), e.getSenderDevice());
|
.resolveRecipientAddress(recipientId), e.getSenderDevice());
|
||||||
return new Pair<>(List.of(), exception);
|
return new Pair<>(List.of(), exception);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new Pair<>(List.of(), e);
|
return new Pair<>(List.of(), e);
|
||||||
|
@ -139,8 +140,8 @@ public final class IncomingMessageHandler {
|
||||||
} catch (ProtocolUntrustedIdentityException e) {
|
} catch (ProtocolUntrustedIdentityException e) {
|
||||||
final var recipientId = account.getRecipientStore().resolveRecipient(e.getSender());
|
final var recipientId = account.getRecipientStore().resolveRecipient(e.getSender());
|
||||||
actions.add(new RetrieveProfileAction(recipientId));
|
actions.add(new RetrieveProfileAction(recipientId));
|
||||||
exception = new UntrustedIdentityException(addressResolver.resolveSignalServiceAddress(recipientId),
|
exception = new UntrustedIdentityException(account.getRecipientStore()
|
||||||
e.getSenderDevice());
|
.resolveRecipientAddress(recipientId), e.getSenderDevice());
|
||||||
} catch (ProtocolInvalidKeyIdException | ProtocolInvalidKeyException | ProtocolNoSessionException | ProtocolInvalidMessageException e) {
|
} catch (ProtocolInvalidKeyIdException | ProtocolInvalidKeyException | ProtocolNoSessionException | ProtocolInvalidMessageException e) {
|
||||||
final var sender = account.getRecipientStore().resolveRecipient(e.getSender());
|
final var sender = account.getRecipientStore().resolveRecipient(e.getSender());
|
||||||
final var senderProfile = profileProvider.getProfile(sender);
|
final var senderProfile = profileProvider.getProfile(sender);
|
||||||
|
@ -196,7 +197,10 @@ public final class IncomingMessageHandler {
|
||||||
} else {
|
} else {
|
||||||
actions = List.of();
|
actions = List.of();
|
||||||
}
|
}
|
||||||
handler.handleMessage(envelope, content, exception);
|
handler.handleMessage(MessageEnvelope.from(envelope,
|
||||||
|
content,
|
||||||
|
recipientResolver,
|
||||||
|
account.getRecipientStore()::resolveRecipientAddress), exception);
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,9 +223,17 @@ public final class IncomingMessageHandler {
|
||||||
final var message = content.getSenderKeyDistributionMessage().get();
|
final var message = content.getSenderKeyDistributionMessage().get();
|
||||||
final var protocolAddress = new SignalProtocolAddress(addressResolver.resolveSignalServiceAddress(sender)
|
final var protocolAddress = new SignalProtocolAddress(addressResolver.resolveSignalServiceAddress(sender)
|
||||||
.getIdentifier(), senderDeviceId);
|
.getIdentifier(), senderDeviceId);
|
||||||
|
logger.debug("Received a sender key distribution message for distributionId {} from {}",
|
||||||
|
message.getDistributionId(),
|
||||||
|
protocolAddress);
|
||||||
dependencies.getMessageSender().processSenderKeyDistributionMessage(protocolAddress, message);
|
dependencies.getMessageSender().processSenderKeyDistributionMessage(protocolAddress, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (content.getDecryptionErrorMessage().isPresent()) {
|
||||||
|
var message = content.getDecryptionErrorMessage().get();
|
||||||
|
logger.debug("Received a decryption error message (resend request for {})", message.getTimestamp());
|
||||||
|
}
|
||||||
|
|
||||||
if (content.getDataMessage().isPresent()) {
|
if (content.getDataMessage().isPresent()) {
|
||||||
var message = content.getDataMessage().get();
|
var message = content.getDataMessage().get();
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ public class SendHelper {
|
||||||
try {
|
try {
|
||||||
messageSender.sendReceipt(address, unidentifiedAccessHelper.getAccessFor(recipientId), receiptMessage);
|
messageSender.sendReceipt(address, unidentifiedAccessHelper.getAccessFor(recipientId), receiptMessage);
|
||||||
} catch (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException e) {
|
} catch (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException e) {
|
||||||
throw new UntrustedIdentityException(address);
|
throw new UntrustedIdentityException(account.getRecipientStore().resolveRecipientAddress(recipientId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ public class SendHelper {
|
||||||
groupId.transform(GroupId::serialize),
|
groupId.transform(GroupId::serialize),
|
||||||
errorMessage);
|
errorMessage);
|
||||||
} catch (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException e) {
|
} catch (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException e) {
|
||||||
throw new UntrustedIdentityException(address);
|
throw new UntrustedIdentityException(account.getRecipientStore().resolveRecipientAddress(recipientId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ public class SendHelper {
|
||||||
messageSender.sendTyping(newAddress, unidentifiedAccessHelper.getAccessFor(newRecipientId), message);
|
messageSender.sendTyping(newAddress, unidentifiedAccessHelper.getAccessFor(newRecipientId), message);
|
||||||
}
|
}
|
||||||
} catch (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException e) {
|
} catch (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException e) {
|
||||||
throw new UntrustedIdentityException(address);
|
throw new UntrustedIdentityException(account.getRecipientStore().resolveRecipientAddress(recipientId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,17 +2,12 @@ package org.asamk.signal;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.asamk.signal.manager.groups.GroupUtils;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.manager.groups.GroupId;
|
||||||
|
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||||
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
||||||
import org.freedesktop.dbus.exceptions.DBusException;
|
import org.freedesktop.dbus.exceptions.DBusException;
|
||||||
import org.freedesktop.dbus.types.Variant;
|
import org.freedesktop.dbus.types.Variant;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -21,8 +16,6 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
|
||||||
|
|
||||||
public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
|
|
||||||
private final Manager m;
|
private final Manager m;
|
||||||
|
@ -36,211 +29,193 @@ public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
|
public void handleMessage(MessageEnvelope envelope, Throwable exception) {
|
||||||
try {
|
try {
|
||||||
sendDbusMessages(envelope, content);
|
sendDbusMessages(envelope);
|
||||||
} catch (DBusException e) {
|
} catch (DBusException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendDbusMessages(
|
private void sendDbusMessages(MessageEnvelope envelope) throws DBusException {
|
||||||
final SignalServiceEnvelope envelope, final SignalServiceContent content
|
final var senderString = envelope.sourceAddress().map(RecipientAddress::getLegacyIdentifier).orElse("");
|
||||||
) throws DBusException {
|
if (envelope.receipt().isPresent()) {
|
||||||
if (envelope.isReceipt()) {
|
final var receiptMessage = envelope.receipt().get();
|
||||||
conn.sendMessage(new Signal.ReceiptReceived(objectPath, envelope.getTimestamp(),
|
final var type = switch (receiptMessage.type()) {
|
||||||
// A receipt envelope always has a source address
|
|
||||||
getLegacyIdentifier(envelope.getSourceAddress())));
|
|
||||||
conn.sendMessage(new Signal.ReceiptReceivedV2(objectPath, envelope.getTimestamp(),
|
|
||||||
// A receipt envelope always has a source address
|
|
||||||
getLegacyIdentifier(envelope.getSourceAddress()), "delivery", Map.of()));
|
|
||||||
} else if (content != null) {
|
|
||||||
final var sender = !envelope.isUnidentifiedSender() && envelope.hasSourceUuid()
|
|
||||||
? envelope.getSourceAddress()
|
|
||||||
: content.getSender();
|
|
||||||
final var senderString = getLegacyIdentifier(sender);
|
|
||||||
if (content.getReceiptMessage().isPresent()) {
|
|
||||||
final var receiptMessage = content.getReceiptMessage().get();
|
|
||||||
final var type = switch (receiptMessage.getType()) {
|
|
||||||
case READ -> "read";
|
case READ -> "read";
|
||||||
case VIEWED -> "viewed";
|
case VIEWED -> "viewed";
|
||||||
case DELIVERY -> "delivery";
|
case DELIVERY -> "delivery";
|
||||||
case UNKNOWN -> "unknown";
|
case UNKNOWN -> "unknown";
|
||||||
};
|
};
|
||||||
for (long timestamp : receiptMessage.getTimestamps()) {
|
for (long timestamp : receiptMessage.timestamps()) {
|
||||||
conn.sendMessage(new Signal.ReceiptReceived(objectPath, timestamp, senderString));
|
conn.sendMessage(new Signal.ReceiptReceived(objectPath, timestamp, senderString));
|
||||||
conn.sendMessage(new Signal.ReceiptReceivedV2(objectPath,
|
conn.sendMessage(new Signal.ReceiptReceivedV2(objectPath, timestamp, senderString, type, Map.of()));
|
||||||
envelope.getTimestamp(),
|
|
||||||
senderString,
|
|
||||||
type,
|
|
||||||
Map.of()));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (envelope.data().isPresent()) {
|
||||||
|
var message = envelope.data().get();
|
||||||
|
|
||||||
} else if (content.getDataMessage().isPresent()) {
|
var groupId = message.groupContext()
|
||||||
var message = content.getDataMessage().get();
|
.map(MessageEnvelope.Data.GroupContext::groupId)
|
||||||
|
.map(GroupId::serialize)
|
||||||
var groupId = getGroupId(message);
|
.orElseGet(() -> new byte[0]);
|
||||||
if (!message.isEndSession() && (
|
var isGroupUpdate = message.groupContext()
|
||||||
groupId == null
|
.map(MessageEnvelope.Data.GroupContext::isGroupUpdate)
|
||||||
|| message.getGroupContext().get().getGroupV1Type() == null
|
.orElse(false);
|
||||||
|| message.getGroupContext().get().getGroupV1Type() == SignalServiceGroup.Type.DELIVER
|
if (!message.isEndSession() && !isGroupUpdate) {
|
||||||
)) {
|
|
||||||
conn.sendMessage(new Signal.MessageReceived(objectPath,
|
conn.sendMessage(new Signal.MessageReceived(objectPath,
|
||||||
message.getTimestamp(),
|
message.timestamp(),
|
||||||
senderString,
|
senderString,
|
||||||
groupId != null ? groupId : new byte[0],
|
groupId,
|
||||||
message.getBody().or(""),
|
message.body().orElse(""),
|
||||||
getAttachments(message)));
|
getAttachments(message)));
|
||||||
conn.sendMessage(new Signal.MessageReceivedV2(objectPath,
|
conn.sendMessage(new Signal.MessageReceivedV2(objectPath,
|
||||||
message.getTimestamp(),
|
message.timestamp(),
|
||||||
senderString,
|
senderString,
|
||||||
groupId != null ? groupId : new byte[0],
|
groupId,
|
||||||
message.getBody().or(""),
|
message.body().orElse(""),
|
||||||
getMessageExtras(message)));
|
getMessageExtras(message)));
|
||||||
}
|
}
|
||||||
} else if (content.getSyncMessage().isPresent()) {
|
}
|
||||||
var sync_message = content.getSyncMessage().get();
|
if (envelope.sync().isPresent()) {
|
||||||
if (sync_message.getSent().isPresent()) {
|
var syncMessage = envelope.sync().get();
|
||||||
var transcript = sync_message.getSent().get();
|
if (syncMessage.sent().isPresent()) {
|
||||||
|
var transcript = syncMessage.sent().get();
|
||||||
|
|
||||||
if (transcript.getDestination().isPresent() || transcript.getMessage()
|
if (transcript.destination().isPresent() || transcript.message().groupContext().isPresent()) {
|
||||||
.getGroupContext()
|
var message = transcript.message();
|
||||||
.isPresent()) {
|
var groupId = message.groupContext()
|
||||||
var message = transcript.getMessage();
|
.map(MessageEnvelope.Data.GroupContext::groupId)
|
||||||
var groupId = getGroupId(message);
|
.map(GroupId::serialize)
|
||||||
|
.orElseGet(() -> new byte[0]);
|
||||||
|
|
||||||
conn.sendMessage(new Signal.SyncMessageReceived(objectPath,
|
conn.sendMessage(new Signal.SyncMessageReceived(objectPath,
|
||||||
transcript.getTimestamp(),
|
transcript.message().timestamp(),
|
||||||
senderString,
|
senderString,
|
||||||
transcript.getDestination().transform(Util::getLegacyIdentifier).or(""),
|
transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""),
|
||||||
groupId != null ? groupId : new byte[0],
|
groupId,
|
||||||
message.getBody().or(""),
|
message.body().orElse(""),
|
||||||
getAttachments(message)));
|
getAttachments(message)));
|
||||||
conn.sendMessage(new Signal.SyncMessageReceivedV2(objectPath,
|
conn.sendMessage(new Signal.SyncMessageReceivedV2(objectPath,
|
||||||
transcript.getTimestamp(),
|
transcript.message().timestamp(),
|
||||||
senderString,
|
senderString,
|
||||||
transcript.getDestination().transform(Util::getLegacyIdentifier).or(""),
|
transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""),
|
||||||
groupId != null ? groupId : new byte[0],
|
groupId,
|
||||||
message.getBody().or(""),
|
message.body().orElse(""),
|
||||||
getMessageExtras(message)));
|
getMessageExtras(message)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] getGroupId(final SignalServiceDataMessage message) {
|
private List<String> getAttachments(MessageEnvelope.Data message) {
|
||||||
return message.getGroupContext().isPresent() ? GroupUtils.getGroupId(message.getGroupContext().get())
|
|
||||||
.serialize() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> getAttachments(SignalServiceDataMessage message) {
|
|
||||||
var attachments = new ArrayList<String>();
|
var attachments = new ArrayList<String>();
|
||||||
if (message.getAttachments().isPresent()) {
|
if (message.attachments().size() > 0) {
|
||||||
for (var attachment : message.getAttachments().get()) {
|
for (var attachment : message.attachments()) {
|
||||||
if (attachment.isPointer()) {
|
if (attachment.id().isPresent()) {
|
||||||
attachments.add(m.getAttachmentFile(attachment.asPointer().getRemoteId()).getAbsolutePath());
|
attachments.add(m.getAttachmentFile(attachment.id().get()).getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return attachments;
|
return attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, Variant<?>> getMessageExtras(SignalServiceDataMessage message) {
|
private HashMap<String, Variant<?>> getMessageExtras(MessageEnvelope.Data message) {
|
||||||
var extras = new HashMap<String, Variant<?>>();
|
var extras = new HashMap<String, Variant<?>>();
|
||||||
if (message.getAttachments().isPresent()) {
|
if (message.attachments().size() > 0) {
|
||||||
var attachments = message.getAttachments()
|
var attachments = message.attachments()
|
||||||
.get()
|
|
||||||
.stream()
|
.stream()
|
||||||
.filter(SignalServiceAttachment::isPointer)
|
.filter(a -> a.id().isPresent())
|
||||||
.map(a -> getAttachmentMap(m, a))
|
.map(a -> getAttachmentMap(m, a))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
extras.put("attachments", new Variant<>(attachments, "aa{sv}"));
|
extras.put("attachments", new Variant<>(attachments, "aa{sv}"));
|
||||||
}
|
}
|
||||||
if (message.getMentions().isPresent()) {
|
if (message.mentions().size() > 0) {
|
||||||
var mentions = message.getMentions()
|
var mentions = message.mentions().stream().map(this::getMentionMap).collect(Collectors.toList());
|
||||||
.get()
|
|
||||||
.stream()
|
|
||||||
.map(mention -> getMentionMap(m, mention))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
extras.put("mentions", new Variant<>(mentions, "aa{sv}"));
|
extras.put("mentions", new Variant<>(mentions, "aa{sv}"));
|
||||||
}
|
}
|
||||||
extras.put("expiresInSeconds", new Variant<>(message.getExpiresInSeconds()));
|
extras.put("expiresInSeconds", new Variant<>(message.expiresInSeconds()));
|
||||||
if (message.getQuote().isPresent()) {
|
if (message.quote().isPresent()) {
|
||||||
extras.put("quote", new Variant<>(getQuoteMap(message.getQuote().get()), "a{sv}"));
|
extras.put("quote", new Variant<>(getQuoteMap(message.quote().get()), "a{sv}"));
|
||||||
}
|
}
|
||||||
if (message.getReaction().isPresent()) {
|
if (message.reaction().isPresent()) {
|
||||||
final var reaction = message.getReaction().get();
|
final var reaction = message.reaction().get();
|
||||||
extras.put("reaction", new Variant<>(getReactionMap(reaction), "a{sv}"));
|
extras.put("reaction", new Variant<>(getReactionMap(reaction), "a{sv}"));
|
||||||
}
|
}
|
||||||
if (message.getRemoteDelete().isPresent()) {
|
if (message.remoteDeleteId().isPresent()) {
|
||||||
extras.put("remoteDelete",
|
extras.put("remoteDelete",
|
||||||
new Variant<>(Map.of("timestamp", new Variant<>(message.getRemoteDelete())), "a{sv}"));
|
new Variant<>(Map.of("timestamp", new Variant<>(message.remoteDeleteId())), "a{sv}"));
|
||||||
}
|
}
|
||||||
if (message.getSticker().isPresent()) {
|
if (message.sticker().isPresent()) {
|
||||||
final var sticker = message.getSticker().get();
|
final var sticker = message.sticker().get();
|
||||||
extras.put("sticker", new Variant<>(getStickerMap(sticker), "a{sv}"));
|
extras.put("sticker", new Variant<>(getStickerMap(sticker), "a{sv}"));
|
||||||
}
|
}
|
||||||
extras.put("isViewOnce", new Variant<>(message.isViewOnce()));
|
extras.put("isViewOnce", new Variant<>(message.isViewOnce()));
|
||||||
return extras;
|
return extras;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Variant<?>> getQuoteMap(final SignalServiceDataMessage.Quote quote) {
|
private Map<String, Variant<?>> getQuoteMap(final MessageEnvelope.Data.Quote quote) {
|
||||||
return Map.of("id",
|
return Map.of("id",
|
||||||
new Variant<>(quote.getId()),
|
new Variant<>(quote.id()),
|
||||||
"author",
|
"author",
|
||||||
new Variant<>(getLegacyIdentifier(m.resolveSignalServiceAddress(quote.getAuthor()))),
|
new Variant<>(quote.author().getLegacyIdentifier()),
|
||||||
"text",
|
"text",
|
||||||
new Variant<>(quote.getText()));
|
new Variant<>(quote.text()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Variant<? extends Serializable>> getStickerMap(final SignalServiceDataMessage.Sticker sticker) {
|
private Map<String, Variant<? extends Serializable>> getStickerMap(final MessageEnvelope.Data.Sticker sticker) {
|
||||||
return Map.of("packId", new Variant<>(sticker.getPackId()), "stickerId", new Variant<>(sticker.getStickerId()));
|
return Map.of("packId", new Variant<>(sticker.packId()), "stickerId", new Variant<>(sticker.stickerId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Variant<?>> getReactionMap(final SignalServiceDataMessage.Reaction reaction) {
|
private Map<String, Variant<?>> getReactionMap(final MessageEnvelope.Data.Reaction reaction) {
|
||||||
return Map.of("emoji",
|
return Map.of("emoji",
|
||||||
new Variant<>(reaction.getEmoji()),
|
new Variant<>(reaction.emoji()),
|
||||||
"targetAuthor",
|
"targetAuthor",
|
||||||
new Variant<>(getLegacyIdentifier(m.resolveSignalServiceAddress(reaction.getTargetAuthor()))),
|
new Variant<>(reaction.targetAuthor().getLegacyIdentifier()),
|
||||||
"targetSentTimestamp",
|
"targetSentTimestamp",
|
||||||
new Variant<>(reaction.getTargetSentTimestamp()),
|
new Variant<>(reaction.targetSentTimestamp()),
|
||||||
"isRemove",
|
"isRemove",
|
||||||
new Variant<>(reaction.isRemove()));
|
new Variant<>(reaction.isRemove()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Variant<?>> getAttachmentMap(final Manager m, final SignalServiceAttachment attachment) {
|
private Map<String, Variant<?>> getAttachmentMap(
|
||||||
final var a = attachment.asPointer();
|
final Manager m, final MessageEnvelope.Data.Attachment a
|
||||||
|
) {
|
||||||
final var map = new HashMap<String, Variant<?>>();
|
final var map = new HashMap<String, Variant<?>>();
|
||||||
map.put("file", new Variant<>(m.getAttachmentFile(a.getRemoteId()).getAbsolutePath()));
|
if (a.id().isPresent()) {
|
||||||
map.put("remoteId", new Variant<>(a.getRemoteId().toString()));
|
map.put("file", new Variant<>(m.getAttachmentFile(a.id().get()).getAbsolutePath()));
|
||||||
map.put("isVoiceNote", new Variant<>(a.getVoiceNote()));
|
map.put("remoteId", new Variant<>(a.id().get()));
|
||||||
|
}
|
||||||
|
map.put("isVoiceNote", new Variant<>(a.isVoiceNote()));
|
||||||
map.put("isBorderless", new Variant<>(a.isBorderless()));
|
map.put("isBorderless", new Variant<>(a.isBorderless()));
|
||||||
map.put("isGif", new Variant<>(a.isGif()));
|
map.put("isGif", new Variant<>(a.isGif()));
|
||||||
if (a.getCaption().isPresent()) {
|
if (a.caption().isPresent()) {
|
||||||
map.put("caption", new Variant<>(a.getCaption().get()));
|
map.put("caption", new Variant<>(a.caption().get()));
|
||||||
}
|
}
|
||||||
if (a.getFileName().isPresent()) {
|
if (a.fileName().isPresent()) {
|
||||||
map.put("fileName", new Variant<>(a.getFileName().get()));
|
map.put("fileName", new Variant<>(a.fileName().get()));
|
||||||
}
|
}
|
||||||
if (a.getSize().isPresent()) {
|
if (a.size().isPresent()) {
|
||||||
map.put("size", new Variant<>(a.getSize().get()));
|
map.put("size", new Variant<>(a.size().get()));
|
||||||
}
|
}
|
||||||
if (a.getWidth() > 0 || a.getHeight() > 0) {
|
if (a.width().isPresent()) {
|
||||||
map.put("height", new Variant<>(a.getHeight()));
|
map.put("width", new Variant<>(a.width().get()));
|
||||||
map.put("width", new Variant<>(a.getWidth()));
|
}
|
||||||
|
if (a.height().isPresent()) {
|
||||||
|
map.put("height", new Variant<>(a.height().get()));
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Variant<?>> getMentionMap(
|
private Map<String, Variant<?>> getMentionMap(
|
||||||
final Manager m, final SignalServiceDataMessage.Mention mention
|
final MessageEnvelope.Data.Mention mention
|
||||||
) {
|
) {
|
||||||
return Map.of("recipient",
|
return Map.of("recipient",
|
||||||
new Variant<>(getLegacyIdentifier(m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid())))),
|
new Variant<>(mention.recipient().getLegacyIdentifier()),
|
||||||
"start",
|
"start",
|
||||||
new Variant<>(mention.getStart()),
|
new Variant<>(mention.start()),
|
||||||
"length",
|
"length",
|
||||||
new Variant<>(mention.getLength()));
|
new Variant<>(mention.length()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,9 @@ package org.asamk.signal;
|
||||||
import org.asamk.signal.json.JsonError;
|
import org.asamk.signal.json.JsonError;
|
||||||
import org.asamk.signal.json.JsonMessageEnvelope;
|
import org.asamk.signal.json.JsonMessageEnvelope;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@ -23,14 +22,14 @@ public class JsonReceiveMessageHandler implements Manager.ReceiveMessageHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
|
public void handleMessage(MessageEnvelope envelope, Throwable exception) {
|
||||||
final var object = new HashMap<String, Object>();
|
final var object = new HashMap<String, Object>();
|
||||||
if (exception != null) {
|
if (exception != null) {
|
||||||
object.put("error", JsonError.from(exception));
|
object.put("error", JsonError.from(exception));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (envelope != null) {
|
if (envelope != null) {
|
||||||
object.put("envelope", JsonMessageEnvelope.from(envelope, content, exception, m));
|
object.put("envelope", JsonMessageEnvelope.from(envelope, exception, m));
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonWriter.write(object);
|
jsonWriter.write(object);
|
||||||
|
|
|
@ -2,30 +2,17 @@ package org.asamk.signal;
|
||||||
|
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.asamk.signal.manager.UntrustedIdentityException;
|
import org.asamk.signal.manager.UntrustedIdentityException;
|
||||||
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||||
import org.asamk.signal.manager.groups.GroupId;
|
import org.asamk.signal.manager.groups.GroupId;
|
||||||
import org.asamk.signal.manager.groups.GroupUtils;
|
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||||
import org.asamk.signal.util.DateUtils;
|
import org.asamk.signal.util.DateUtils;
|
||||||
import org.slf4j.helpers.MessageFormatter;
|
import org.slf4j.helpers.MessageFormatter;
|
||||||
import org.whispersystems.libsignal.protocol.DecryptionErrorMessage;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroupContext;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
|
|
||||||
import org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage;
|
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
|
||||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
|
||||||
|
|
||||||
public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
|
|
||||||
final Manager m;
|
final Manager m;
|
||||||
|
@ -37,26 +24,24 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
|
public void handleMessage(MessageEnvelope envelope, Throwable exception) {
|
||||||
if (envelope.hasSourceUuid()) {
|
var source = envelope.sourceAddress();
|
||||||
var source = envelope.getSourceAddress();
|
writer.println("Envelope from: {} (device: {})",
|
||||||
writer.println("Envelope from: {} (device: {})", formatContact(source), envelope.getSourceDevice());
|
source.map(this::formatContact).orElse("unknown source"),
|
||||||
} else {
|
envelope.sourceDevice());
|
||||||
writer.println("Envelope from: unknown source");
|
writer.println("Timestamp: {}", DateUtils.formatTimestamp(envelope.timestamp()));
|
||||||
}
|
writer.println("Server timestamps: received: {} delivered: {}",
|
||||||
writer.println("Timestamp: {}", DateUtils.formatTimestamp(envelope.getTimestamp()));
|
DateUtils.formatTimestamp(envelope.serverReceivedTimestamp()),
|
||||||
|
DateUtils.formatTimestamp(envelope.serverDeliveredTimestamp()));
|
||||||
if (envelope.isUnidentifiedSender()) {
|
if (envelope.isUnidentifiedSender()) {
|
||||||
writer.println("Sent by unidentified/sealed sender");
|
writer.println("Sent by unidentified/sealed sender");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (envelope.isReceipt()) {
|
|
||||||
writer.println("Got receipt.");
|
|
||||||
} else if (envelope.isSignalMessage() || envelope.isPreKeySignalMessage() || envelope.isUnidentifiedSender()) {
|
|
||||||
if (exception != null) {
|
if (exception != null) {
|
||||||
if (exception instanceof UntrustedIdentityException e) {
|
if (exception instanceof UntrustedIdentityException e) {
|
||||||
writer.println(
|
writer.println(
|
||||||
"The user’s key is untrusted, either the user has reinstalled Signal or a third party sent this message.");
|
"The user’s key is untrusted, either the user has reinstalled Signal or a third party sent this message.");
|
||||||
final var recipientName = getLegacyIdentifier(m.resolveSignalServiceAddress(e.getSender()));
|
final var recipientName = e.getSender().getLegacyIdentifier();
|
||||||
writer.println(
|
writer.println(
|
||||||
"Use 'signal-cli -u {} listIdentities -n {}', verify the key and run 'signal-cli -u {} trust -v \"FINGER_PRINT\" {}' to mark it as trusted",
|
"Use 'signal-cli -u {} listIdentities -n {}', verify the key and run 'signal-cli -u {} trust -v \"FINGER_PRINT\" {}' to mark it as trusted",
|
||||||
m.getSelfNumber(),
|
m.getSelfNumber(),
|
||||||
|
@ -71,98 +56,72 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
writer.println("Exception: {} ({})", exception.getMessage(), exception.getClass().getSimpleName());
|
writer.println("Exception: {} ({})", exception.getMessage(), exception.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (content == null) {
|
|
||||||
writer.println("No message content");
|
|
||||||
} else {
|
|
||||||
writer.println("Sender: {} (device: {})",
|
|
||||||
formatContact(content.getSender()),
|
|
||||||
content.getSenderDevice());
|
|
||||||
writer.println("Server timestamps: received: {} delivered: {}",
|
|
||||||
DateUtils.formatTimestamp(content.getServerReceivedTimestamp()),
|
|
||||||
DateUtils.formatTimestamp(content.getServerDeliveredTimestamp()));
|
|
||||||
|
|
||||||
if (content.getSenderKeyDistributionMessage().isPresent()) {
|
if (envelope.data().isPresent()) {
|
||||||
final var message = content.getSenderKeyDistributionMessage().get();
|
var message = envelope.data().get();
|
||||||
writer.println("Received a sender key distribution message for distributionId {}",
|
|
||||||
message.getDistributionId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (content.getDataMessage().isPresent()) {
|
|
||||||
var message = content.getDataMessage().get();
|
|
||||||
printDataMessage(writer, message);
|
printDataMessage(writer, message);
|
||||||
}
|
}
|
||||||
if (content.getSyncMessage().isPresent()) {
|
if (envelope.sync().isPresent()) {
|
||||||
writer.println("Received a sync message");
|
writer.println("Received a sync message");
|
||||||
var syncMessage = content.getSyncMessage().get();
|
var syncMessage = envelope.sync().get();
|
||||||
printSyncMessage(writer, syncMessage);
|
printSyncMessage(writer, syncMessage);
|
||||||
}
|
}
|
||||||
|
if (envelope.call().isPresent()) {
|
||||||
if (content.getCallMessage().isPresent()) {
|
|
||||||
writer.println("Received a call message");
|
writer.println("Received a call message");
|
||||||
var callMessage = content.getCallMessage().get();
|
var callMessage = envelope.call().get();
|
||||||
printCallMessage(writer.indentedWriter(), callMessage);
|
printCallMessage(writer.indentedWriter(), callMessage);
|
||||||
}
|
}
|
||||||
if (content.getReceiptMessage().isPresent()) {
|
if (envelope.receipt().isPresent()) {
|
||||||
writer.println("Received a receipt message");
|
writer.println("Received a receipt message");
|
||||||
var receiptMessage = content.getReceiptMessage().get();
|
var receiptMessage = envelope.receipt().get();
|
||||||
printReceiptMessage(writer.indentedWriter(), receiptMessage);
|
printReceiptMessage(writer.indentedWriter(), receiptMessage);
|
||||||
}
|
}
|
||||||
if (content.getTypingMessage().isPresent()) {
|
if (envelope.typing().isPresent()) {
|
||||||
writer.println("Received a typing message");
|
writer.println("Received a typing message");
|
||||||
var typingMessage = content.getTypingMessage().get();
|
var typingMessage = envelope.typing().get();
|
||||||
printTypingMessage(writer.indentedWriter(), typingMessage);
|
printTypingMessage(writer.indentedWriter(), typingMessage);
|
||||||
}
|
}
|
||||||
if (content.getDecryptionErrorMessage().isPresent()) {
|
|
||||||
writer.println("Received a decryption error message (resend request)");
|
|
||||||
var decryptionErrorMessage = content.getDecryptionErrorMessage().get();
|
|
||||||
printDecryptionErrorMessage(writer.indentedWriter(), decryptionErrorMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
writer.println("Unknown message received.");
|
|
||||||
}
|
|
||||||
writer.println();
|
writer.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printDataMessage(
|
private void printDataMessage(
|
||||||
PlainTextWriter writer, SignalServiceDataMessage message
|
PlainTextWriter writer, MessageEnvelope.Data message
|
||||||
) {
|
) {
|
||||||
writer.println("Message timestamp: {}", DateUtils.formatTimestamp(message.getTimestamp()));
|
writer.println("Message timestamp: {}", DateUtils.formatTimestamp(message.timestamp()));
|
||||||
if (message.isViewOnce()) {
|
if (message.isViewOnce()) {
|
||||||
writer.println("=VIEW ONCE=");
|
writer.println("=VIEW ONCE=");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.getBody().isPresent()) {
|
if (message.body().isPresent()) {
|
||||||
writer.println("Body: {}", message.getBody().get());
|
writer.println("Body: {}", message.body().get());
|
||||||
}
|
}
|
||||||
if (message.getGroupContext().isPresent()) {
|
if (message.groupContext().isPresent()) {
|
||||||
writer.println("Group info:");
|
writer.println("Group info:");
|
||||||
final var groupContext = message.getGroupContext().get();
|
final var groupContext = message.groupContext().get();
|
||||||
printGroupContext(writer.indentedWriter(), groupContext);
|
printGroupContext(writer.indentedWriter(), groupContext);
|
||||||
}
|
}
|
||||||
if (message.getGroupCallUpdate().isPresent()) {
|
if (message.groupCallUpdate().isPresent()) {
|
||||||
writer.println("Group call update:");
|
writer.println("Group call update:");
|
||||||
final var groupCallUpdate = message.getGroupCallUpdate().get();
|
final var groupCallUpdate = message.groupCallUpdate().get();
|
||||||
writer.indentedWriter().println("Era id: {}", groupCallUpdate.getEraId());
|
writer.indentedWriter().println("Era id: {}", groupCallUpdate.eraId());
|
||||||
}
|
}
|
||||||
if (message.getPreviews().isPresent()) {
|
if (message.previews().size() > 0) {
|
||||||
writer.println("Previews:");
|
writer.println("Previews:");
|
||||||
final var previews = message.getPreviews().get();
|
final var previews = message.previews();
|
||||||
for (var preview : previews) {
|
for (var preview : previews) {
|
||||||
writer.println("- Preview");
|
writer.println("- Preview");
|
||||||
printPreview(writer.indentedWriter(), preview);
|
printPreview(writer.indentedWriter(), preview);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (message.getSharedContacts().isPresent()) {
|
if (message.sharedContacts().size() > 0) {
|
||||||
final var sharedContacts = message.getSharedContacts().get();
|
|
||||||
writer.println("Contacts:");
|
writer.println("Contacts:");
|
||||||
for (var contact : sharedContacts) {
|
for (var contact : message.sharedContacts()) {
|
||||||
writer.println("- Contact:");
|
writer.println("- Contact:");
|
||||||
printSharedContact(writer.indentedWriter(), contact);
|
printSharedContact(writer.indentedWriter(), contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (message.getSticker().isPresent()) {
|
if (message.sticker().isPresent()) {
|
||||||
final var sticker = message.getSticker().get();
|
final var sticker = message.sticker().get();
|
||||||
writer.println("Sticker:");
|
writer.println("Sticker:");
|
||||||
printSticker(writer.indentedWriter(), sticker);
|
printSticker(writer.indentedWriter(), sticker);
|
||||||
}
|
}
|
||||||
|
@ -170,37 +129,37 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
writer.println("Is end session");
|
writer.println("Is end session");
|
||||||
}
|
}
|
||||||
if (message.isExpirationUpdate()) {
|
if (message.isExpirationUpdate()) {
|
||||||
writer.println("Is Expiration update: {}", message.isExpirationUpdate());
|
writer.println("Is Expiration update: true");
|
||||||
}
|
}
|
||||||
if (message.getExpiresInSeconds() > 0) {
|
if (message.expiresInSeconds() > 0) {
|
||||||
writer.println("Expires in: {} seconds", message.getExpiresInSeconds());
|
writer.println("Expires in: {} seconds", message.expiresInSeconds());
|
||||||
}
|
}
|
||||||
if (message.getProfileKey().isPresent()) {
|
if (message.hasProfileKey()) {
|
||||||
writer.println("Profile key update, key length: {}", message.getProfileKey().get().length);
|
writer.println("Profile key update");
|
||||||
}
|
}
|
||||||
if (message.getReaction().isPresent()) {
|
if (message.reaction().isPresent()) {
|
||||||
writer.println("Reaction:");
|
writer.println("Reaction:");
|
||||||
final var reaction = message.getReaction().get();
|
final var reaction = message.reaction().get();
|
||||||
printReaction(writer.indentedWriter(), reaction);
|
printReaction(writer.indentedWriter(), reaction);
|
||||||
}
|
}
|
||||||
if (message.getQuote().isPresent()) {
|
if (message.quote().isPresent()) {
|
||||||
writer.println("Quote:");
|
writer.println("Quote:");
|
||||||
var quote = message.getQuote().get();
|
var quote = message.quote().get();
|
||||||
printQuote(writer.indentedWriter(), quote);
|
printQuote(writer.indentedWriter(), quote);
|
||||||
}
|
}
|
||||||
if (message.getRemoteDelete().isPresent()) {
|
if (message.remoteDeleteId().isPresent()) {
|
||||||
final var remoteDelete = message.getRemoteDelete().get();
|
final var remoteDelete = message.remoteDeleteId().get();
|
||||||
writer.println("Remote delete message: timestamp = {}", remoteDelete.getTargetSentTimestamp());
|
writer.println("Remote delete message: timestamp = {}", remoteDelete);
|
||||||
}
|
}
|
||||||
if (message.getMentions().isPresent()) {
|
if (message.mentions().size() > 0) {
|
||||||
writer.println("Mentions:");
|
writer.println("Mentions:");
|
||||||
for (var mention : message.getMentions().get()) {
|
for (var mention : message.mentions()) {
|
||||||
printMention(writer, mention);
|
printMention(writer, mention);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (message.getAttachments().isPresent()) {
|
if (message.attachments().size() > 0) {
|
||||||
writer.println("Attachments:");
|
writer.println("Attachments:");
|
||||||
for (var attachment : message.getAttachments().get()) {
|
for (var attachment : message.attachments()) {
|
||||||
writer.println("- Attachment:");
|
writer.println("- Attachment:");
|
||||||
printAttachment(writer.indentedWriter(), attachment);
|
printAttachment(writer.indentedWriter(), attachment);
|
||||||
}
|
}
|
||||||
|
@ -208,144 +167,116 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printTypingMessage(
|
private void printTypingMessage(
|
||||||
final PlainTextWriter writer, final SignalServiceTypingMessage typingMessage
|
final PlainTextWriter writer, final MessageEnvelope.Typing typingMessage
|
||||||
) {
|
) {
|
||||||
writer.println("Action: {}", typingMessage.getAction());
|
writer.println("Action: {}", typingMessage.type());
|
||||||
writer.println("Timestamp: {}", DateUtils.formatTimestamp(typingMessage.getTimestamp()));
|
writer.println("Timestamp: {}", DateUtils.formatTimestamp(typingMessage.timestamp()));
|
||||||
if (typingMessage.getGroupId().isPresent()) {
|
if (typingMessage.groupId().isPresent()) {
|
||||||
writer.println("Group Info:");
|
writer.println("Group Info:");
|
||||||
final var groupId = GroupId.unknownVersion(typingMessage.getGroupId().get());
|
final var groupId = typingMessage.groupId().get();
|
||||||
printGroupInfo(writer.indentedWriter(), groupId);
|
printGroupInfo(writer.indentedWriter(), groupId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printDecryptionErrorMessage(
|
|
||||||
final PlainTextWriter writer, final DecryptionErrorMessage decryptionErrorMessage
|
|
||||||
) {
|
|
||||||
writer.println("Device id: {}", decryptionErrorMessage.getDeviceId());
|
|
||||||
writer.println("Timestamp: {}", DateUtils.formatTimestamp(decryptionErrorMessage.getTimestamp()));
|
|
||||||
writer.println("Ratchet key: {}",
|
|
||||||
decryptionErrorMessage.getRatchetKey().isPresent() ? "is present" : "not present");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printReceiptMessage(
|
private void printReceiptMessage(
|
||||||
final PlainTextWriter writer, final SignalServiceReceiptMessage receiptMessage
|
final PlainTextWriter writer, final MessageEnvelope.Receipt receiptMessage
|
||||||
) {
|
) {
|
||||||
writer.println("When: {}", DateUtils.formatTimestamp(receiptMessage.getWhen()));
|
writer.println("When: {}", DateUtils.formatTimestamp(receiptMessage.when()));
|
||||||
if (receiptMessage.isDeliveryReceipt()) {
|
if (receiptMessage.type() == MessageEnvelope.Receipt.Type.DELIVERY) {
|
||||||
writer.println("Is delivery receipt");
|
writer.println("Is delivery receipt");
|
||||||
}
|
}
|
||||||
if (receiptMessage.isReadReceipt()) {
|
if (receiptMessage.type() == MessageEnvelope.Receipt.Type.READ) {
|
||||||
writer.println("Is read receipt");
|
writer.println("Is read receipt");
|
||||||
}
|
}
|
||||||
if (receiptMessage.isViewedReceipt()) {
|
if (receiptMessage.type() == MessageEnvelope.Receipt.Type.VIEWED) {
|
||||||
writer.println("Is viewed receipt");
|
writer.println("Is viewed receipt");
|
||||||
}
|
}
|
||||||
writer.println("Timestamps:");
|
writer.println("Timestamps:");
|
||||||
for (long timestamp : receiptMessage.getTimestamps()) {
|
for (long timestamp : receiptMessage.timestamps()) {
|
||||||
writer.println("- {}", DateUtils.formatTimestamp(timestamp));
|
writer.println("- {}", DateUtils.formatTimestamp(timestamp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printCallMessage(
|
private void printCallMessage(
|
||||||
final PlainTextWriter writer, final SignalServiceCallMessage callMessage
|
final PlainTextWriter writer, final MessageEnvelope.Call callMessage
|
||||||
) {
|
) {
|
||||||
if (callMessage.getDestinationDeviceId().isPresent()) {
|
if (callMessage.destinationDeviceId().isPresent()) {
|
||||||
final var deviceId = callMessage.getDestinationDeviceId().get();
|
final var deviceId = callMessage.destinationDeviceId().get();
|
||||||
writer.println("Destination device id: {}", deviceId);
|
writer.println("Destination device id: {}", deviceId);
|
||||||
}
|
}
|
||||||
if (callMessage.getGroupId().isPresent()) {
|
if (callMessage.groupId().isPresent()) {
|
||||||
final var groupId = GroupId.unknownVersion(callMessage.getGroupId().get());
|
final var groupId = callMessage.groupId().get();
|
||||||
writer.println("Destination group id: {}", groupId);
|
writer.println("Destination group id: {}", groupId);
|
||||||
}
|
}
|
||||||
if (callMessage.getTimestamp().isPresent()) {
|
if (callMessage.timestamp().isPresent()) {
|
||||||
writer.println("Timestamp: {}", DateUtils.formatTimestamp(callMessage.getTimestamp().get()));
|
writer.println("Timestamp: {}", DateUtils.formatTimestamp(callMessage.timestamp().get()));
|
||||||
}
|
}
|
||||||
if (callMessage.getAnswerMessage().isPresent()) {
|
if (callMessage.answer().isPresent()) {
|
||||||
var answerMessage = callMessage.getAnswerMessage().get();
|
var answerMessage = callMessage.answer().get();
|
||||||
writer.println("Answer message: {}, sdp: {})", answerMessage.getId(), answerMessage.getSdp());
|
writer.println("Answer message: {}, sdp: {})", answerMessage.id(), answerMessage.sdp());
|
||||||
}
|
}
|
||||||
if (callMessage.getBusyMessage().isPresent()) {
|
if (callMessage.busy().isPresent()) {
|
||||||
var busyMessage = callMessage.getBusyMessage().get();
|
var busyMessage = callMessage.busy().get();
|
||||||
writer.println("Busy message: {}", busyMessage.getId());
|
writer.println("Busy message: {}", busyMessage.id());
|
||||||
}
|
}
|
||||||
if (callMessage.getHangupMessage().isPresent()) {
|
if (callMessage.hangup().isPresent()) {
|
||||||
var hangupMessage = callMessage.getHangupMessage().get();
|
var hangupMessage = callMessage.hangup().get();
|
||||||
writer.println("Hangup message: {}", hangupMessage.getId());
|
writer.println("Hangup message: {}", hangupMessage.id());
|
||||||
}
|
}
|
||||||
if (callMessage.getIceUpdateMessages().isPresent()) {
|
if (callMessage.iceUpdate().size() > 0) {
|
||||||
writer.println("Ice update messages:");
|
writer.println("Ice update messages:");
|
||||||
var iceUpdateMessages = callMessage.getIceUpdateMessages().get();
|
var iceUpdateMessages = callMessage.iceUpdate();
|
||||||
for (var iceUpdateMessage : iceUpdateMessages) {
|
for (var iceUpdateMessage : iceUpdateMessages) {
|
||||||
writer.println("- {}, sdp: {}", iceUpdateMessage.getId(), iceUpdateMessage.getSdp());
|
writer.println("- {}, sdp: {}", iceUpdateMessage.id(), iceUpdateMessage.sdp());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (callMessage.getOfferMessage().isPresent()) {
|
if (callMessage.offer().isPresent()) {
|
||||||
var offerMessage = callMessage.getOfferMessage().get();
|
var offerMessage = callMessage.offer().get();
|
||||||
writer.println("Offer message: {}, sdp: {}", offerMessage.getId(), offerMessage.getSdp());
|
writer.println("Offer message: {}, sdp: {}", offerMessage.id(), offerMessage.sdp());
|
||||||
}
|
}
|
||||||
if (callMessage.getOpaqueMessage().isPresent()) {
|
if (callMessage.opaque().isPresent()) {
|
||||||
final var opaqueMessage = callMessage.getOpaqueMessage().get();
|
final var opaqueMessage = callMessage.opaque().get();
|
||||||
writer.println("Opaque message: size {}, urgency: {}",
|
writer.println("Opaque message: size {}, urgency: {}",
|
||||||
opaqueMessage.getOpaque().length,
|
opaqueMessage.opaque().length,
|
||||||
opaqueMessage.getUrgency().name());
|
opaqueMessage.urgency().name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printSyncMessage(
|
private void printSyncMessage(
|
||||||
final PlainTextWriter writer, final SignalServiceSyncMessage syncMessage
|
final PlainTextWriter writer, final MessageEnvelope.Sync syncMessage
|
||||||
) {
|
) {
|
||||||
if (syncMessage.getContacts().isPresent()) {
|
if (syncMessage.contacts().isPresent()) {
|
||||||
final var contactsMessage = syncMessage.getContacts().get();
|
final var contactsMessage = syncMessage.contacts().get();
|
||||||
var type = contactsMessage.isComplete() ? "complete" : "partial";
|
var type = contactsMessage.isComplete() ? "complete" : "partial";
|
||||||
writer.println("Received {} sync contacts:", type);
|
writer.println("Received {} sync contacts:", type);
|
||||||
printAttachment(writer.indentedWriter(), contactsMessage.getContactsStream());
|
|
||||||
}
|
}
|
||||||
if (syncMessage.getGroups().isPresent()) {
|
if (syncMessage.groups().isPresent()) {
|
||||||
writer.println("Received sync groups:");
|
writer.println("Received sync groups.");
|
||||||
printAttachment(writer.indentedWriter(), syncMessage.getGroups().get());
|
|
||||||
}
|
}
|
||||||
if (syncMessage.getRead().isPresent()) {
|
if (syncMessage.read().size() > 0) {
|
||||||
writer.println("Received sync read messages list");
|
writer.println("Received sync read messages list");
|
||||||
for (var rm : syncMessage.getRead().get()) {
|
for (var rm : syncMessage.read()) {
|
||||||
writer.println("- From: {} Message timestamp: {}",
|
writer.println("- From: {} Message timestamp: {}",
|
||||||
formatContact(rm.getSender()),
|
formatContact(rm.sender()),
|
||||||
DateUtils.formatTimestamp(rm.getTimestamp()));
|
DateUtils.formatTimestamp(rm.timestamp()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (syncMessage.getViewed().isPresent()) {
|
if (syncMessage.viewed().size() > 0) {
|
||||||
writer.println("Received sync viewed messages list");
|
writer.println("Received sync viewed messages list");
|
||||||
for (var vm : syncMessage.getViewed().get()) {
|
for (var vm : syncMessage.viewed()) {
|
||||||
writer.println("- From: {} Message timestamp: {}",
|
writer.println("- From: {} Message timestamp: {}",
|
||||||
formatContact(vm.getSender()),
|
formatContact(vm.sender()),
|
||||||
DateUtils.formatTimestamp(vm.getTimestamp()));
|
DateUtils.formatTimestamp(vm.timestamp()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (syncMessage.getRequest().isPresent()) {
|
if (syncMessage.sent().isPresent()) {
|
||||||
String type;
|
|
||||||
if (syncMessage.getRequest().get().isContactsRequest()) {
|
|
||||||
type = "contacts";
|
|
||||||
} else if (syncMessage.getRequest().get().isGroupsRequest()) {
|
|
||||||
type = "groups";
|
|
||||||
} else if (syncMessage.getRequest().get().isBlockedListRequest()) {
|
|
||||||
type = "blocked list";
|
|
||||||
} else if (syncMessage.getRequest().get().isConfigurationRequest()) {
|
|
||||||
type = "configuration";
|
|
||||||
} else if (syncMessage.getRequest().get().isKeysRequest()) {
|
|
||||||
type = "keys";
|
|
||||||
} else {
|
|
||||||
type = "<unknown>";
|
|
||||||
}
|
|
||||||
writer.println("Received sync request for: {}", type);
|
|
||||||
}
|
|
||||||
if (syncMessage.getSent().isPresent()) {
|
|
||||||
writer.println("Received sync sent message");
|
writer.println("Received sync sent message");
|
||||||
final var sentTranscriptMessage = syncMessage.getSent().get();
|
final var sentTranscriptMessage = syncMessage.sent().get();
|
||||||
String to;
|
String to;
|
||||||
if (sentTranscriptMessage.getDestination().isPresent()) {
|
if (sentTranscriptMessage.destination().isPresent()) {
|
||||||
to = formatContact(sentTranscriptMessage.getDestination().get());
|
to = formatContact(sentTranscriptMessage.destination().get());
|
||||||
} else if (sentTranscriptMessage.getRecipients().size() > 0) {
|
} else if (sentTranscriptMessage.recipients().size() > 0) {
|
||||||
to = sentTranscriptMessage.getRecipients()
|
to = sentTranscriptMessage.recipients()
|
||||||
.stream()
|
.stream()
|
||||||
.map(this::formatContact)
|
.map(this::formatContact)
|
||||||
.collect(Collectors.joining(", "));
|
.collect(Collectors.joining(", "));
|
||||||
|
@ -354,257 +285,195 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
}
|
}
|
||||||
writer.indentedWriter().println("To: {}", to);
|
writer.indentedWriter().println("To: {}", to);
|
||||||
writer.indentedWriter()
|
writer.indentedWriter()
|
||||||
.println("Timestamp: {}", DateUtils.formatTimestamp(sentTranscriptMessage.getTimestamp()));
|
.println("Timestamp: {}", DateUtils.formatTimestamp(sentTranscriptMessage.timestamp()));
|
||||||
if (sentTranscriptMessage.getExpirationStartTimestamp() > 0) {
|
if (sentTranscriptMessage.expirationStartTimestamp() > 0) {
|
||||||
writer.indentedWriter()
|
writer.indentedWriter()
|
||||||
.println("Expiration started at: {}",
|
.println("Expiration started at: {}",
|
||||||
DateUtils.formatTimestamp(sentTranscriptMessage.getExpirationStartTimestamp()));
|
DateUtils.formatTimestamp(sentTranscriptMessage.expirationStartTimestamp()));
|
||||||
}
|
}
|
||||||
var message = sentTranscriptMessage.getMessage();
|
var message = sentTranscriptMessage.message();
|
||||||
printDataMessage(writer.indentedWriter(), message);
|
printDataMessage(writer.indentedWriter(), message);
|
||||||
}
|
}
|
||||||
if (syncMessage.getBlockedList().isPresent()) {
|
if (syncMessage.blocked().isPresent()) {
|
||||||
writer.println("Received sync message with block list");
|
writer.println("Received sync message with block list");
|
||||||
writer.println("Blocked numbers:");
|
writer.println("Blocked:");
|
||||||
final var blockedList = syncMessage.getBlockedList().get();
|
final var blockedList = syncMessage.blocked().get();
|
||||||
for (var address : blockedList.getAddresses()) {
|
for (var address : blockedList.recipients()) {
|
||||||
writer.println("- {}", getLegacyIdentifier(address));
|
writer.println("- {}", address.getLegacyIdentifier());
|
||||||
|
}
|
||||||
|
for (var groupId : blockedList.groupIds()) {
|
||||||
|
writer.println("- {}", groupId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (syncMessage.getVerified().isPresent()) {
|
if (syncMessage.viewOnceOpen().isPresent()) {
|
||||||
writer.println("Received sync message with verified identities:");
|
final var viewOnceOpenMessage = syncMessage.viewOnceOpen().get();
|
||||||
final var verifiedMessage = syncMessage.getVerified().get();
|
|
||||||
writer.println("- {}: {}", formatContact(verifiedMessage.getDestination()), verifiedMessage.getVerified());
|
|
||||||
}
|
|
||||||
if (syncMessage.getConfiguration().isPresent()) {
|
|
||||||
writer.println("Received sync message with configuration:");
|
|
||||||
final var configurationMessage = syncMessage.getConfiguration().get();
|
|
||||||
if (configurationMessage.getReadReceipts().isPresent()) {
|
|
||||||
writer.println("- Read receipts: {}",
|
|
||||||
configurationMessage.getReadReceipts().get() ? "enabled" : "disabled");
|
|
||||||
}
|
|
||||||
if (configurationMessage.getLinkPreviews().isPresent()) {
|
|
||||||
writer.println("- Link previews: {}",
|
|
||||||
configurationMessage.getLinkPreviews().get() ? "enabled" : "disabled");
|
|
||||||
}
|
|
||||||
if (configurationMessage.getTypingIndicators().isPresent()) {
|
|
||||||
writer.println("- Typing indicators: {}",
|
|
||||||
configurationMessage.getTypingIndicators().get() ? "enabled" : "disabled");
|
|
||||||
}
|
|
||||||
if (configurationMessage.getUnidentifiedDeliveryIndicators().isPresent()) {
|
|
||||||
writer.println("- Unidentified Delivery Indicators: {}",
|
|
||||||
configurationMessage.getUnidentifiedDeliveryIndicators().get() ? "enabled" : "disabled");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (syncMessage.getFetchType().isPresent()) {
|
|
||||||
final var fetchType = syncMessage.getFetchType().get();
|
|
||||||
writer.println("Received sync message with fetch type: {}", fetchType);
|
|
||||||
}
|
|
||||||
if (syncMessage.getViewOnceOpen().isPresent()) {
|
|
||||||
final var viewOnceOpenMessage = syncMessage.getViewOnceOpen().get();
|
|
||||||
writer.println("Received sync message with view once open message:");
|
writer.println("Received sync message with view once open message:");
|
||||||
writer.indentedWriter().println("Sender: {}", formatContact(viewOnceOpenMessage.getSender()));
|
writer.indentedWriter().println("Sender: {}", formatContact(viewOnceOpenMessage.sender()));
|
||||||
writer.indentedWriter()
|
writer.indentedWriter()
|
||||||
.println("Timestamp: {}", DateUtils.formatTimestamp(viewOnceOpenMessage.getTimestamp()));
|
.println("Timestamp: {}", DateUtils.formatTimestamp(viewOnceOpenMessage.timestamp()));
|
||||||
}
|
}
|
||||||
if (syncMessage.getStickerPackOperations().isPresent()) {
|
if (syncMessage.messageRequestResponse().isPresent()) {
|
||||||
final var stickerPackOperationMessages = syncMessage.getStickerPackOperations().get();
|
final var requestResponseMessage = syncMessage.messageRequestResponse().get();
|
||||||
writer.println("Received sync message with sticker pack operations:");
|
|
||||||
for (var m : stickerPackOperationMessages) {
|
|
||||||
writer.println("- {}", m.getType().isPresent() ? m.getType().get() : "<unknown>");
|
|
||||||
if (m.getPackId().isPresent()) {
|
|
||||||
writer.indentedWriter()
|
|
||||||
.println("packId: {}", Base64.getEncoder().encodeToString(m.getPackId().get()));
|
|
||||||
}
|
|
||||||
if (m.getPackKey().isPresent()) {
|
|
||||||
writer.indentedWriter()
|
|
||||||
.println("packKey: {}", Base64.getEncoder().encodeToString(m.getPackKey().get()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (syncMessage.getMessageRequestResponse().isPresent()) {
|
|
||||||
final var requestResponseMessage = syncMessage.getMessageRequestResponse().get();
|
|
||||||
writer.println("Received message request response:");
|
writer.println("Received message request response:");
|
||||||
writer.indentedWriter().println("Type: {}", requestResponseMessage.getType());
|
writer.indentedWriter().println("Type: {}", requestResponseMessage.type());
|
||||||
if (requestResponseMessage.getGroupId().isPresent()) {
|
if (requestResponseMessage.groupId().isPresent()) {
|
||||||
writer.println("For group:");
|
writer.println("For group:");
|
||||||
printGroupInfo(writer.indentedWriter(),
|
printGroupInfo(writer.indentedWriter(), requestResponseMessage.groupId().get());
|
||||||
GroupId.unknownVersion(requestResponseMessage.getGroupId().get()));
|
|
||||||
}
|
}
|
||||||
if (requestResponseMessage.getPerson().isPresent()) {
|
if (requestResponseMessage.person().isPresent()) {
|
||||||
writer.indentedWriter()
|
writer.indentedWriter().println("For Person: {}", formatContact(requestResponseMessage.person().get()));
|
||||||
.println("For Person: {}", formatContact(requestResponseMessage.getPerson().get()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (syncMessage.getKeys().isPresent()) {
|
|
||||||
final var keysMessage = syncMessage.getKeys().get();
|
|
||||||
writer.println("Received sync message with keys:");
|
|
||||||
if (keysMessage.getStorageService().isPresent()) {
|
|
||||||
writer.println("- storage key: length: {}", keysMessage.getStorageService().get().serialize().length);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printPreview(
|
private void printPreview(
|
||||||
final PlainTextWriter writer, final SignalServiceDataMessage.Preview preview
|
final PlainTextWriter writer, final MessageEnvelope.Data.Preview preview
|
||||||
) {
|
) {
|
||||||
writer.println("Title: {}", preview.getTitle());
|
writer.println("Title: {}", preview.title());
|
||||||
writer.println("Description: {}", preview.getDescription());
|
writer.println("Description: {}", preview.description());
|
||||||
writer.println("Date: {}", DateUtils.formatTimestamp(preview.getDate()));
|
writer.println("Date: {}", DateUtils.formatTimestamp(preview.date()));
|
||||||
writer.println("Url: {}", preview.getUrl());
|
writer.println("Url: {}", preview.url());
|
||||||
if (preview.getImage().isPresent()) {
|
if (preview.image().isPresent()) {
|
||||||
writer.println("Image:");
|
writer.println("Image:");
|
||||||
printAttachment(writer.indentedWriter(), preview.getImage().get());
|
printAttachment(writer.indentedWriter(), preview.image().get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printSticker(
|
private void printSticker(
|
||||||
final PlainTextWriter writer, final SignalServiceDataMessage.Sticker sticker
|
final PlainTextWriter writer, final MessageEnvelope.Data.Sticker sticker
|
||||||
) {
|
) {
|
||||||
writer.println("Pack id: {}", Base64.getEncoder().encodeToString(sticker.getPackId()));
|
writer.println("Pack id: {}", Base64.getEncoder().encodeToString(sticker.packId()));
|
||||||
writer.println("Pack key: {}", Base64.getEncoder().encodeToString(sticker.getPackKey()));
|
writer.println("Pack key: {}", Base64.getEncoder().encodeToString(sticker.packKey()));
|
||||||
writer.println("Sticker id: {}", sticker.getStickerId());
|
writer.println("Sticker id: {}", sticker.stickerId());
|
||||||
writer.println("Image:");
|
|
||||||
printAttachment(writer.indentedWriter(), sticker.getAttachment());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printReaction(
|
private void printReaction(
|
||||||
final PlainTextWriter writer, final SignalServiceDataMessage.Reaction reaction
|
final PlainTextWriter writer, final MessageEnvelope.Data.Reaction reaction
|
||||||
) {
|
) {
|
||||||
writer.println("Emoji: {}", reaction.getEmoji());
|
writer.println("Emoji: {}", reaction.emoji());
|
||||||
writer.println("Target author: {}", formatContact(reaction.getTargetAuthor()));
|
writer.println("Target author: {}", formatContact(reaction.targetAuthor()));
|
||||||
writer.println("Target timestamp: {}", DateUtils.formatTimestamp(reaction.getTargetSentTimestamp()));
|
writer.println("Target timestamp: {}", DateUtils.formatTimestamp(reaction.targetSentTimestamp()));
|
||||||
writer.println("Is remove: {}", reaction.isRemove());
|
writer.println("Is remove: {}", reaction.isRemove());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printQuote(
|
private void printQuote(
|
||||||
final PlainTextWriter writer, final SignalServiceDataMessage.Quote quote
|
final PlainTextWriter writer, final MessageEnvelope.Data.Quote quote
|
||||||
) {
|
) {
|
||||||
writer.println("Id: {}", quote.getId());
|
writer.println("Id: {}", quote.id());
|
||||||
writer.println("Author: {}", formatContact(quote.getAuthor()));
|
writer.println("Author: {}", formatContact(quote.author()));
|
||||||
writer.println("Text: {}", quote.getText());
|
writer.println("Text: {}", quote.text());
|
||||||
if (quote.getMentions() != null && quote.getMentions().size() > 0) {
|
if (quote.mentions() != null && quote.mentions().size() > 0) {
|
||||||
writer.println("Mentions:");
|
writer.println("Mentions:");
|
||||||
for (var mention : quote.getMentions()) {
|
for (var mention : quote.mentions()) {
|
||||||
printMention(writer, mention);
|
printMention(writer, mention);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (quote.getAttachments().size() > 0) {
|
if (quote.attachments().size() > 0) {
|
||||||
writer.println("Attachments:");
|
writer.println("Attachments:");
|
||||||
for (var attachment : quote.getAttachments()) {
|
for (var attachment : quote.attachments()) {
|
||||||
writer.println("- Filename: {}", attachment.getFileName());
|
writer.println("- Filename: {}", attachment.fileName());
|
||||||
writer.indent(w -> {
|
writer.indent(w -> {
|
||||||
w.println("Type: {}", attachment.getContentType());
|
w.println("Type: {}", attachment.contentType());
|
||||||
w.println("Thumbnail:");
|
w.println("Thumbnail:");
|
||||||
if (attachment.getThumbnail() != null) {
|
if (attachment.thumbnail().isPresent()) {
|
||||||
printAttachment(w, attachment.getThumbnail());
|
printAttachment(w, attachment.thumbnail().get());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printSharedContact(final PlainTextWriter writer, final SharedContact contact) {
|
private void printSharedContact(final PlainTextWriter writer, final MessageEnvelope.Data.SharedContact contact) {
|
||||||
writer.println("Name:");
|
writer.println("Name:");
|
||||||
var name = contact.getName();
|
var name = contact.name();
|
||||||
writer.indent(w -> {
|
writer.indent(w -> {
|
||||||
if (name.getDisplay().isPresent() && !name.getDisplay().get().isBlank()) {
|
if (name.display().isPresent() && !name.display().get().isBlank()) {
|
||||||
w.println("Display name: {}", name.getDisplay().get());
|
w.println("Display name: {}", name.display().get());
|
||||||
}
|
}
|
||||||
if (name.getGiven().isPresent() && !name.getGiven().get().isBlank()) {
|
if (name.given().isPresent() && !name.given().get().isBlank()) {
|
||||||
w.println("First name: {}", name.getGiven().get());
|
w.println("First name: {}", name.given().get());
|
||||||
}
|
}
|
||||||
if (name.getMiddle().isPresent() && !name.getMiddle().get().isBlank()) {
|
if (name.middle().isPresent() && !name.middle().get().isBlank()) {
|
||||||
w.println("Middle name: {}", name.getMiddle().get());
|
w.println("Middle name: {}", name.middle().get());
|
||||||
}
|
}
|
||||||
if (name.getFamily().isPresent() && !name.getFamily().get().isBlank()) {
|
if (name.family().isPresent() && !name.family().get().isBlank()) {
|
||||||
w.println("Family name: {}", name.getFamily().get());
|
w.println("Family name: {}", name.family().get());
|
||||||
}
|
}
|
||||||
if (name.getPrefix().isPresent() && !name.getPrefix().get().isBlank()) {
|
if (name.prefix().isPresent() && !name.prefix().get().isBlank()) {
|
||||||
w.println("Prefix name: {}", name.getPrefix().get());
|
w.println("Prefix name: {}", name.prefix().get());
|
||||||
}
|
}
|
||||||
if (name.getSuffix().isPresent() && !name.getSuffix().get().isBlank()) {
|
if (name.suffix().isPresent() && !name.suffix().get().isBlank()) {
|
||||||
w.println("Suffix name: {}", name.getSuffix().get());
|
w.println("Suffix name: {}", name.suffix().get());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (contact.getAvatar().isPresent()) {
|
if (contact.avatar().isPresent()) {
|
||||||
var avatar = contact.getAvatar().get();
|
var avatar = contact.avatar().get();
|
||||||
writer.println("Avatar: (profile: {})", avatar.isProfile());
|
writer.println("Avatar: (profile: {})", avatar.isProfile());
|
||||||
printAttachment(writer.indentedWriter(), avatar.getAttachment());
|
printAttachment(writer.indentedWriter(), avatar.attachment());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contact.getOrganization().isPresent()) {
|
if (contact.organization().isPresent()) {
|
||||||
writer.println("Organisation: {}", contact.getOrganization().get());
|
writer.println("Organisation: {}", contact.organization().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contact.getPhone().isPresent()) {
|
if (contact.phone().size() > 0) {
|
||||||
writer.println("Phone details:");
|
writer.println("Phone details:");
|
||||||
for (var phone : contact.getPhone().get()) {
|
for (var phone : contact.phone()) {
|
||||||
writer.println("- Phone:");
|
writer.println("- Phone:");
|
||||||
writer.indent(w -> {
|
writer.indent(w -> {
|
||||||
if (phone.getValue() != null) {
|
w.println("Number: {}", phone.value());
|
||||||
w.println("Number: {}", phone.getValue());
|
w.println("Type: {}", phone.type());
|
||||||
}
|
if (phone.label().isPresent() && !phone.label().get().isBlank()) {
|
||||||
if (phone.getType() != null) {
|
w.println("Label: {}", phone.label().get());
|
||||||
w.println("Type: {}", phone.getType());
|
|
||||||
}
|
|
||||||
if (phone.getLabel().isPresent() && !phone.getLabel().get().isBlank()) {
|
|
||||||
w.println("Label: {}", phone.getLabel().get());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contact.getEmail().isPresent()) {
|
if (contact.email().size() > 0) {
|
||||||
writer.println("Email details:");
|
writer.println("Email details:");
|
||||||
for (var email : contact.getEmail().get()) {
|
for (var email : contact.email()) {
|
||||||
writer.println("- Email:");
|
writer.println("- Email:");
|
||||||
writer.indent(w -> {
|
writer.indent(w -> {
|
||||||
if (email.getValue() != null) {
|
w.println("Address: {}", email.value());
|
||||||
w.println("Address: {}", email.getValue());
|
w.println("Type: {}", email.type());
|
||||||
}
|
if (email.label().isPresent() && !email.label().get().isBlank()) {
|
||||||
if (email.getType() != null) {
|
w.println("Label: {}", email.label().get());
|
||||||
w.println("Type: {}", email.getType());
|
|
||||||
}
|
|
||||||
if (email.getLabel().isPresent() && !email.getLabel().get().isBlank()) {
|
|
||||||
w.println("Label: {}", email.getLabel().get());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contact.getAddress().isPresent()) {
|
if (contact.address().size() > 0) {
|
||||||
writer.println("Address details:");
|
writer.println("Address details:");
|
||||||
for (var address : contact.getAddress().get()) {
|
for (var address : contact.address()) {
|
||||||
writer.println("- Address:");
|
writer.println("- Address:");
|
||||||
writer.indent(w -> {
|
writer.indent(w -> {
|
||||||
if (address.getType() != null) {
|
w.println("Type: {}", address.type());
|
||||||
w.println("Type: {}", address.getType());
|
if (address.label().isPresent() && !address.label().get().isBlank()) {
|
||||||
|
w.println("Label: {}", address.label().get());
|
||||||
}
|
}
|
||||||
if (address.getLabel().isPresent() && !address.getLabel().get().isBlank()) {
|
if (address.street().isPresent() && !address.street().get().isBlank()) {
|
||||||
w.println("Label: {}", address.getLabel().get());
|
w.println("Street: {}", address.street().get());
|
||||||
}
|
}
|
||||||
if (address.getStreet().isPresent() && !address.getStreet().get().isBlank()) {
|
if (address.pobox().isPresent() && !address.pobox().get().isBlank()) {
|
||||||
w.println("Street: {}", address.getStreet().get());
|
w.println("Pobox: {}", address.pobox().get());
|
||||||
}
|
}
|
||||||
if (address.getPobox().isPresent() && !address.getPobox().get().isBlank()) {
|
if (address.neighborhood().isPresent() && !address.neighborhood().get().isBlank()) {
|
||||||
w.println("Pobox: {}", address.getPobox().get());
|
w.println("Neighbourhood: {}", address.neighborhood().get());
|
||||||
}
|
}
|
||||||
if (address.getNeighborhood().isPresent() && !address.getNeighborhood().get().isBlank()) {
|
if (address.city().isPresent() && !address.city().get().isBlank()) {
|
||||||
w.println("Neighbourhood: {}", address.getNeighborhood().get());
|
w.println("City: {}", address.city().get());
|
||||||
}
|
}
|
||||||
if (address.getCity().isPresent() && !address.getCity().get().isBlank()) {
|
if (address.region().isPresent() && !address.region().get().isBlank()) {
|
||||||
w.println("City: {}", address.getCity().get());
|
w.println("Region: {}", address.region().get());
|
||||||
}
|
}
|
||||||
if (address.getRegion().isPresent() && !address.getRegion().get().isBlank()) {
|
if (address.postcode().isPresent() && !address.postcode().get().isBlank()) {
|
||||||
w.println("Region: {}", address.getRegion().get());
|
w.println("Postcode: {}", address.postcode().get());
|
||||||
}
|
}
|
||||||
if (address.getPostcode().isPresent() && !address.getPostcode().get().isBlank()) {
|
if (address.country().isPresent() && !address.country().get().isBlank()) {
|
||||||
w.println("Postcode: {}", address.getPostcode().get());
|
w.println("Country: {}", address.country().get());
|
||||||
}
|
|
||||||
if (address.getCountry().isPresent() && !address.getCountry().get().isBlank()) {
|
|
||||||
w.println("Country: {}", address.getCountry().get());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -612,30 +481,11 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printGroupContext(
|
private void printGroupContext(
|
||||||
final PlainTextWriter writer, final SignalServiceGroupContext groupContext
|
final PlainTextWriter writer, final MessageEnvelope.Data.GroupContext groupContext
|
||||||
) {
|
) {
|
||||||
final var groupId = GroupUtils.getGroupId(groupContext);
|
printGroupInfo(writer, groupContext.groupId());
|
||||||
if (groupContext.getGroupV1().isPresent()) {
|
writer.println("Revision: {}", groupContext.revision());
|
||||||
var groupInfo = groupContext.getGroupV1().get();
|
writer.println("Type: {}", groupContext.isGroupUpdate() ? "UPDATE" : "DELIVER");
|
||||||
printGroupInfo(writer, groupId);
|
|
||||||
writer.println("Type: {}", groupInfo.getType());
|
|
||||||
if (groupInfo.getMembers().isPresent()) {
|
|
||||||
writer.println("Members:");
|
|
||||||
for (var member : groupInfo.getMembers().get()) {
|
|
||||||
writer.println("- {}", formatContact(member));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (groupInfo.getAvatar().isPresent()) {
|
|
||||||
writer.println("Avatar:");
|
|
||||||
printAttachment(writer.indentedWriter(), groupInfo.getAvatar().get());
|
|
||||||
}
|
|
||||||
} else if (groupContext.getGroupV2().isPresent()) {
|
|
||||||
final var groupInfo = groupContext.getGroupV2().get();
|
|
||||||
printGroupInfo(writer, groupId);
|
|
||||||
writer.println("Revision: {}", groupInfo.getRevision());
|
|
||||||
writer.println("Master key length: {}", groupInfo.getMasterKey().serialize().length);
|
|
||||||
writer.println("Has signed group change: {}", groupInfo.hasSignedGroupChange());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printGroupInfo(final PlainTextWriter writer, final GroupId groupId) {
|
private void printGroupInfo(final PlainTextWriter writer, final GroupId groupId) {
|
||||||
|
@ -650,58 +500,59 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printMention(
|
private void printMention(
|
||||||
PlainTextWriter writer, SignalServiceDataMessage.Mention mention
|
PlainTextWriter writer, MessageEnvelope.Data.Mention mention
|
||||||
) {
|
) {
|
||||||
final var address = m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid()));
|
writer.println("- {}: {} (length: {})", formatContact(mention.recipient()), mention.start(), mention.length());
|
||||||
writer.println("- {}: {} (length: {})", formatContact(address), mention.getStart(), mention.getLength());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printAttachment(PlainTextWriter writer, SignalServiceAttachment attachment) {
|
private void printAttachment(PlainTextWriter writer, MessageEnvelope.Data.Attachment attachment) {
|
||||||
writer.println("Content-Type: {}", attachment.getContentType());
|
writer.println("Content-Type: {}", attachment.contentType());
|
||||||
writer.println("Type: {}", attachment.isPointer() ? "Pointer" : attachment.isStream() ? "Stream" : "<unknown>");
|
writer.println("Type: {}", attachment.id().isPresent() ? "Pointer" : "Stream");
|
||||||
if (attachment.isPointer()) {
|
if (attachment.id().isPresent()) {
|
||||||
final var pointer = attachment.asPointer();
|
writer.println("Id: {}", attachment.id().get());
|
||||||
writer.println("Id: {} Key length: {}", pointer.getRemoteId(), pointer.getKey().length);
|
|
||||||
if (pointer.getUploadTimestamp() > 0) {
|
|
||||||
writer.println("Upload timestamp: {}", DateUtils.formatTimestamp(pointer.getUploadTimestamp()));
|
|
||||||
}
|
}
|
||||||
if (pointer.getCaption().isPresent()) {
|
if (attachment.uploadTimestamp().isPresent()) {
|
||||||
writer.println("Caption: {}", pointer.getCaption().get());
|
writer.println("Upload timestamp: {}", DateUtils.formatTimestamp(attachment.uploadTimestamp().get()));
|
||||||
}
|
}
|
||||||
if (pointer.getFileName().isPresent()) {
|
if (attachment.caption().isPresent()) {
|
||||||
writer.println("Filename: {}", pointer.getFileName().get());
|
writer.println("Caption: {}", attachment.caption().get());
|
||||||
}
|
}
|
||||||
|
if (attachment.fileName().isPresent()) {
|
||||||
|
writer.println("Filename: {}", attachment.fileName().get());
|
||||||
|
}
|
||||||
|
if (attachment.size().isPresent() || attachment.preview().isPresent()) {
|
||||||
writer.println("Size: {}{}",
|
writer.println("Size: {}{}",
|
||||||
pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "<unavailable>",
|
attachment.size().isPresent() ? attachment.size().get() + " bytes" : "<unavailable>",
|
||||||
pointer.getPreview().isPresent() ? " (Preview is available: "
|
attachment.preview().isPresent() ? " (Preview is available: "
|
||||||
+ pointer.getPreview().get().length
|
+ attachment.preview().get().length
|
||||||
+ " bytes)" : "");
|
+ " bytes)" : "");
|
||||||
|
}
|
||||||
final var flags = new ArrayList<String>();
|
final var flags = new ArrayList<String>();
|
||||||
if (pointer.getVoiceNote()) {
|
if (attachment.isVoiceNote()) {
|
||||||
flags.add("voice note");
|
flags.add("voice note");
|
||||||
}
|
}
|
||||||
if (pointer.isBorderless()) {
|
if (attachment.isBorderless()) {
|
||||||
flags.add("borderless");
|
flags.add("borderless");
|
||||||
}
|
}
|
||||||
if (pointer.isGif()) {
|
if (attachment.isGif()) {
|
||||||
flags.add("video gif");
|
flags.add("video gif");
|
||||||
}
|
}
|
||||||
if (flags.size() > 0) {
|
if (flags.size() > 0) {
|
||||||
writer.println("Flags: {}", String.join(", ", flags));
|
writer.println("Flags: {}", String.join(", ", flags));
|
||||||
}
|
}
|
||||||
if (pointer.getWidth() > 0 || pointer.getHeight() > 0) {
|
if (attachment.width().isPresent() || attachment.height().isPresent()) {
|
||||||
writer.println("Dimensions: {}x{}", pointer.getWidth(), pointer.getHeight());
|
writer.println("Dimensions: {}x{}", attachment.width().orElse(0), attachment.height().orElse(0));
|
||||||
}
|
}
|
||||||
var file = m.getAttachmentFile(pointer.getRemoteId());
|
if (attachment.id().isPresent()) {
|
||||||
|
var file = m.getAttachmentFile(attachment.id().get());
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
writer.println("Stored plaintext in: {}", file);
|
writer.println("Stored plaintext in: {}", file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatContact(SignalServiceAddress address) {
|
private String formatContact(RecipientAddress address) {
|
||||||
address = m.resolveSignalServiceAddress(address);
|
final var number = address.getLegacyIdentifier();
|
||||||
final var number = getLegacyIdentifier(address);
|
|
||||||
final var name = m.getContactOrProfileName(RecipientIdentifier.Single.fromAddress(address));
|
final var name = m.getContactOrProfileName(RecipientIdentifier.Single.fromAddress(address));
|
||||||
if (name == null || name.isEmpty()) {
|
if (name == null || name.isEmpty()) {
|
||||||
return number;
|
return number;
|
||||||
|
|
|
@ -14,7 +14,6 @@ import org.asamk.signal.util.Hex;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
|
||||||
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -29,15 +28,13 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
|
||||||
return "listIdentities";
|
return "listIdentities";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void printIdentityFingerprint(PlainTextWriter writer, Manager m, Identity theirId) {
|
private static void printIdentityFingerprint(PlainTextWriter writer, Identity theirId) {
|
||||||
final SignalServiceAddress address = theirId.recipient().toSignalServiceAddress();
|
|
||||||
var digits = Util.formatSafetyNumber(theirId.safetyNumber());
|
|
||||||
writer.println("{}: {} Added: {} Fingerprint: {} Safety Number: {}",
|
writer.println("{}: {} Added: {} Fingerprint: {} Safety Number: {}",
|
||||||
address.getNumber().orNull(),
|
theirId.recipient().getNumber().orElse(null),
|
||||||
theirId.trustLevel(),
|
theirId.trustLevel(),
|
||||||
theirId.dateAdded(),
|
theirId.dateAdded(),
|
||||||
Hex.toString(theirId.getFingerprint()),
|
Hex.toString(theirId.getFingerprint()),
|
||||||
digits);
|
Util.formatSafetyNumber(theirId.safetyNumber()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -61,7 +58,7 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
|
||||||
|
|
||||||
if (outputWriter instanceof PlainTextWriter writer) {
|
if (outputWriter instanceof PlainTextWriter writer) {
|
||||||
for (var id : identities) {
|
for (var id : identities) {
|
||||||
printIdentityFingerprint(writer, m, id);
|
printIdentityFingerprint(writer, id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final var writer = (JsonWriter) outputWriter;
|
final var writer = (JsonWriter) outputWriter;
|
||||||
|
|
|
@ -33,8 +33,6 @@ import org.freedesktop.dbus.DBusPath;
|
||||||
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
||||||
import org.freedesktop.dbus.exceptions.DBusException;
|
import org.freedesktop.dbus.exceptions.DBusException;
|
||||||
import org.freedesktop.dbus.interfaces.DBusInterface;
|
import org.freedesktop.dbus.interfaces.DBusInterface;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId;
|
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
||||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||||
|
|
||||||
|
@ -459,7 +457,7 @@ public class DbusManagerImpl implements Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getAttachmentFile(final SignalServiceAttachmentRemoteId attachmentId) {
|
public File getAttachmentFile(final String attachmentId) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,11 +549,6 @@ public class DbusManagerImpl implements Manager {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SignalServiceAddress resolveSignalServiceAddress(final SignalServiceAddress address) {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,14 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
|
|
||||||
record JsonAttachment(String contentType, String filename, String id, Long size) {
|
record JsonAttachment(String contentType, String filename, String id, Long size) {
|
||||||
|
|
||||||
static JsonAttachment from(SignalServiceAttachment attachment) {
|
static JsonAttachment from(MessageEnvelope.Data.Attachment attachment) {
|
||||||
if (attachment.isPointer()) {
|
final var id = attachment.id().orElse(null);
|
||||||
final var pointer = attachment.asPointer();
|
final var filename = attachment.fileName().orElse(null);
|
||||||
final var id = pointer.getRemoteId().toString();
|
final var size = attachment.size().orElse(null);
|
||||||
final var filename = pointer.getFileName().orNull();
|
return new JsonAttachment(attachment.contentType(), filename, id, size);
|
||||||
final var size = pointer.getSize().transform(Integer::longValue).orNull();
|
|
||||||
return new JsonAttachment(attachment.getContentType(), filename, id, size);
|
|
||||||
} else {
|
|
||||||
final var stream = attachment.asStream();
|
|
||||||
final var filename = stream.getFileName().orNull();
|
|
||||||
final var size = stream.getLength();
|
|
||||||
return new JsonAttachment(attachment.getContentType(), filename, null, size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static JsonAttachment from(String filename) {
|
static JsonAttachment from(String filename) {
|
||||||
|
|
|
@ -2,28 +2,65 @@ package org.asamk.signal.json;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.messages.calls.AnswerMessage;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.whispersystems.signalservice.api.messages.calls.BusyMessage;
|
|
||||||
import org.whispersystems.signalservice.api.messages.calls.HangupMessage;
|
|
||||||
import org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage;
|
|
||||||
import org.whispersystems.signalservice.api.messages.calls.OfferMessage;
|
|
||||||
import org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage;
|
|
||||||
|
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
record JsonCallMessage(
|
record JsonCallMessage(
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL) OfferMessage offerMessage,
|
@JsonInclude(JsonInclude.Include.NON_NULL) Offer offerMessage,
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL) AnswerMessage answerMessage,
|
@JsonInclude(JsonInclude.Include.NON_NULL) Answer answerMessage,
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL) BusyMessage busyMessage,
|
@JsonInclude(JsonInclude.Include.NON_NULL) Busy busyMessage,
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL) HangupMessage hangupMessage,
|
@JsonInclude(JsonInclude.Include.NON_NULL) Hangup hangupMessage,
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<IceUpdateMessage> iceUpdateMessages
|
@JsonInclude(JsonInclude.Include.NON_EMPTY) List<IceUpdate> iceUpdateMessages
|
||||||
) {
|
) {
|
||||||
|
|
||||||
static JsonCallMessage from(SignalServiceCallMessage callMessage) {
|
static JsonCallMessage from(MessageEnvelope.Call callMessage) {
|
||||||
return new JsonCallMessage(callMessage.getOfferMessage().orNull(),
|
return new JsonCallMessage(callMessage.offer().map(Offer::from).orElse(null),
|
||||||
callMessage.getAnswerMessage().orNull(),
|
callMessage.answer().map(Answer::from).orElse(null),
|
||||||
callMessage.getBusyMessage().orNull(),
|
callMessage.busy().map(Busy::from).orElse(null),
|
||||||
callMessage.getHangupMessage().orNull(),
|
callMessage.hangup().map(Hangup::from).orElse(null),
|
||||||
callMessage.getIceUpdateMessages().orNull());
|
callMessage.iceUpdate().stream().map(IceUpdate::from).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
record Offer(long id, String sdp, String type, String opaque) {
|
||||||
|
|
||||||
|
public static Offer from(final MessageEnvelope.Call.Offer offer) {
|
||||||
|
return new Offer(offer.id(),
|
||||||
|
offer.sdp(),
|
||||||
|
offer.type().name(),
|
||||||
|
Base64.getEncoder().encodeToString(offer.opaque()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Answer(long id, String sdp, String opaque) {
|
||||||
|
|
||||||
|
public static Answer from(final MessageEnvelope.Call.Answer answer) {
|
||||||
|
return new Answer(answer.id(), answer.sdp(), Base64.getEncoder().encodeToString(answer.opaque()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Busy(long id) {
|
||||||
|
|
||||||
|
public static Busy from(final MessageEnvelope.Call.Busy busy) {
|
||||||
|
return new Busy(busy.id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Hangup(long id, String type, int deviceId, boolean isLegacy) {
|
||||||
|
|
||||||
|
public static Hangup from(final MessageEnvelope.Call.Hangup hangup) {
|
||||||
|
return new Hangup(hangup.id(), hangup.type().name(), hangup.deviceId(), hangup.isLegacy());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record IceUpdate(long id, String sdp, String opaque) {
|
||||||
|
|
||||||
|
public static IceUpdate from(final MessageEnvelope.Call.IceUpdate iceUpdate) {
|
||||||
|
return new IceUpdate(iceUpdate.id(),
|
||||||
|
iceUpdate.sdp(),
|
||||||
|
Base64.getEncoder().encodeToString(iceUpdate.opaque()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
|
||||||
|
|
||||||
public record JsonContactAddress(
|
public record JsonContactAddress(
|
||||||
SharedContact.PostalAddress.Type type,
|
String type,
|
||||||
String label,
|
String label,
|
||||||
String street,
|
String street,
|
||||||
String pobox,
|
String pobox,
|
||||||
|
@ -15,15 +15,15 @@ public record JsonContactAddress(
|
||||||
String country
|
String country
|
||||||
) {
|
) {
|
||||||
|
|
||||||
static JsonContactAddress from(SharedContact.PostalAddress address) {
|
static JsonContactAddress from(MessageEnvelope.Data.SharedContact.Address address) {
|
||||||
return new JsonContactAddress(address.getType(),
|
return new JsonContactAddress(address.type().name(),
|
||||||
Util.getStringIfNotBlank(address.getLabel()),
|
Util.getStringIfNotBlank(address.label()),
|
||||||
Util.getStringIfNotBlank(address.getStreet()),
|
Util.getStringIfNotBlank(address.street()),
|
||||||
Util.getStringIfNotBlank(address.getPobox()),
|
Util.getStringIfNotBlank(address.pobox()),
|
||||||
Util.getStringIfNotBlank(address.getNeighborhood()),
|
Util.getStringIfNotBlank(address.neighborhood()),
|
||||||
Util.getStringIfNotBlank(address.getCity()),
|
Util.getStringIfNotBlank(address.city()),
|
||||||
Util.getStringIfNotBlank(address.getRegion()),
|
Util.getStringIfNotBlank(address.region()),
|
||||||
Util.getStringIfNotBlank(address.getPostcode()),
|
Util.getStringIfNotBlank(address.postcode()),
|
||||||
Util.getStringIfNotBlank(address.getCountry()));
|
Util.getStringIfNotBlank(address.country()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
|
|
||||||
public record JsonContactAvatar(JsonAttachment attachment, boolean isProfile) {
|
public record JsonContactAvatar(JsonAttachment attachment, boolean isProfile) {
|
||||||
|
|
||||||
static JsonContactAvatar from(SharedContact.Avatar avatar) {
|
static JsonContactAvatar from(MessageEnvelope.Data.SharedContact.Avatar avatar) {
|
||||||
return new JsonContactAvatar(JsonAttachment.from(avatar.getAttachment()), avatar.isProfile());
|
return new JsonContactAvatar(JsonAttachment.from(avatar.attachment()), avatar.isProfile());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
|
||||||
|
|
||||||
public record JsonContactEmail(String value, SharedContact.Email.Type type, String label) {
|
public record JsonContactEmail(String value, String type, String label) {
|
||||||
|
|
||||||
static JsonContactEmail from(SharedContact.Email email) {
|
static JsonContactEmail from(MessageEnvelope.Data.SharedContact.Email email) {
|
||||||
return new JsonContactEmail(email.getValue(), email.getType(), Util.getStringIfNotBlank(email.getLabel()));
|
return new JsonContactEmail(email.value(), email.type().name(), Util.getStringIfNotBlank(email.label()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
|
||||||
|
|
||||||
public record JsonContactName(
|
public record JsonContactName(
|
||||||
String display, String given, String family, String prefix, String suffix, String middle
|
String display, String given, String family, String prefix, String suffix, String middle
|
||||||
) {
|
) {
|
||||||
|
|
||||||
static JsonContactName from(SharedContact.Name name) {
|
static JsonContactName from(MessageEnvelope.Data.SharedContact.Name name) {
|
||||||
return new JsonContactName(Util.getStringIfNotBlank(name.getDisplay()),
|
return new JsonContactName(Util.getStringIfNotBlank(name.display()),
|
||||||
Util.getStringIfNotBlank(name.getGiven()),
|
Util.getStringIfNotBlank(name.given()),
|
||||||
Util.getStringIfNotBlank(name.getFamily()),
|
Util.getStringIfNotBlank(name.family()),
|
||||||
Util.getStringIfNotBlank(name.getPrefix()),
|
Util.getStringIfNotBlank(name.prefix()),
|
||||||
Util.getStringIfNotBlank(name.getSuffix()),
|
Util.getStringIfNotBlank(name.suffix()),
|
||||||
Util.getStringIfNotBlank(name.getMiddle()));
|
Util.getStringIfNotBlank(name.middle()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
|
||||||
|
|
||||||
public record JsonContactPhone(String value, SharedContact.Phone.Type type, String label) {
|
public record JsonContactPhone(String value, String type, String label) {
|
||||||
|
|
||||||
static JsonContactPhone from(SharedContact.Phone phone) {
|
static JsonContactPhone from(MessageEnvelope.Data.SharedContact.Phone phone) {
|
||||||
return new JsonContactPhone(phone.getValue(), phone.getType(), Util.getStringIfNotBlank(phone.getLabel()));
|
return new JsonContactPhone(phone.value(), phone.type().name(), Util.getStringIfNotBlank(phone.label()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@ package org.asamk.signal.json;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -24,66 +23,32 @@ record JsonDataMessage(
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL) JsonGroupInfo groupInfo
|
@JsonInclude(JsonInclude.Include.NON_NULL) JsonGroupInfo groupInfo
|
||||||
) {
|
) {
|
||||||
|
|
||||||
static JsonDataMessage from(SignalServiceDataMessage dataMessage, Manager m) {
|
static JsonDataMessage from(MessageEnvelope.Data dataMessage) {
|
||||||
final var timestamp = dataMessage.getTimestamp();
|
final var timestamp = dataMessage.timestamp();
|
||||||
final JsonGroupInfo groupInfo;
|
final var groupInfo = dataMessage.groupContext().isPresent() ? JsonGroupInfo.from(dataMessage.groupContext()
|
||||||
if (dataMessage.getGroupContext().isPresent()) {
|
.get()) : null;
|
||||||
final var groupContext = dataMessage.getGroupContext().get();
|
final var message = dataMessage.body().orElse(null);
|
||||||
if (groupContext.getGroupV1().isPresent()) {
|
final var expiresInSeconds = dataMessage.expiresInSeconds();
|
||||||
var group = groupContext.getGroupV1().get();
|
|
||||||
groupInfo = JsonGroupInfo.from(group);
|
|
||||||
} else if (groupContext.getGroupV2().isPresent()) {
|
|
||||||
var group = groupContext.getGroupV2().get();
|
|
||||||
groupInfo = JsonGroupInfo.from(group);
|
|
||||||
} else {
|
|
||||||
groupInfo = null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
groupInfo = null;
|
|
||||||
}
|
|
||||||
final var message = dataMessage.getBody().orNull();
|
|
||||||
final var expiresInSeconds = dataMessage.getExpiresInSeconds();
|
|
||||||
final var viewOnce = dataMessage.isViewOnce();
|
final var viewOnce = dataMessage.isViewOnce();
|
||||||
final var reaction = dataMessage.getReaction().isPresent() ? JsonReaction.from(dataMessage.getReaction().get(),
|
final var reaction = dataMessage.reaction().map(JsonReaction::from).orElse(null);
|
||||||
m) : null;
|
final var quote = dataMessage.quote().isPresent() ? JsonQuote.from(dataMessage.quote().get()) : null;
|
||||||
final var quote = dataMessage.getQuote().isPresent() ? JsonQuote.from(dataMessage.getQuote().get(), m) : null;
|
final var mentions = dataMessage.mentions().size() > 0 ? dataMessage.mentions()
|
||||||
final List<JsonMention> mentions;
|
|
||||||
if (dataMessage.getMentions().isPresent()) {
|
|
||||||
mentions = dataMessage.getMentions()
|
|
||||||
.get()
|
|
||||||
.stream()
|
.stream()
|
||||||
.map(mention -> JsonMention.from(mention, m))
|
.map(JsonMention::from)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList()) : null;
|
||||||
} else {
|
final var remoteDelete = dataMessage.remoteDeleteId().isPresent()
|
||||||
mentions = List.of();
|
? new JsonRemoteDelete(dataMessage.remoteDeleteId().get())
|
||||||
}
|
|
||||||
final var remoteDelete = dataMessage.getRemoteDelete().isPresent()
|
|
||||||
? JsonRemoteDelete.from(dataMessage.getRemoteDelete().get())
|
|
||||||
: null;
|
: null;
|
||||||
final List<JsonAttachment> attachments;
|
final var attachments = dataMessage.attachments().size() > 0 ? dataMessage.attachments()
|
||||||
if (dataMessage.getAttachments().isPresent()) {
|
|
||||||
attachments = dataMessage.getAttachments()
|
|
||||||
.get()
|
|
||||||
.stream()
|
.stream()
|
||||||
.map(JsonAttachment::from)
|
.map(JsonAttachment::from)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList()) : null;
|
||||||
} else {
|
final var sticker = dataMessage.sticker().isPresent() ? JsonSticker.from(dataMessage.sticker().get()) : null;
|
||||||
attachments = List.of();
|
|
||||||
}
|
|
||||||
final var sticker = dataMessage.getSticker().isPresent()
|
|
||||||
? JsonSticker.from(dataMessage.getSticker().get())
|
|
||||||
: null;
|
|
||||||
|
|
||||||
final List<JsonSharedContact> contacts;
|
final var contacts = dataMessage.sharedContacts().size() > 0 ? dataMessage.sharedContacts()
|
||||||
if (dataMessage.getSharedContacts().isPresent()) {
|
|
||||||
contacts = dataMessage.getSharedContacts()
|
|
||||||
.get()
|
|
||||||
.stream()
|
.stream()
|
||||||
.map(JsonSharedContact::from)
|
.map(JsonSharedContact::from)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList()) : null;
|
||||||
} else {
|
|
||||||
contacts = List.of();
|
|
||||||
}
|
|
||||||
return new JsonDataMessage(timestamp,
|
return new JsonDataMessage(timestamp,
|
||||||
message,
|
message,
|
||||||
expiresInSeconds,
|
expiresInSeconds,
|
||||||
|
|
|
@ -1,42 +1,17 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
|
|
||||||
import org.asamk.signal.manager.groups.GroupUtils;
|
|
||||||
import org.asamk.signal.util.Util;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
|
|
||||||
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
record JsonGroupInfo(
|
record JsonGroupInfo(String groupId, String type) {
|
||||||
String groupId,
|
|
||||||
String type,
|
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL) String name,
|
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<String> members
|
|
||||||
) {
|
|
||||||
|
|
||||||
static JsonGroupInfo from(SignalServiceGroup groupInfo) {
|
static JsonGroupInfo from(MessageEnvelope.Data.GroupContext groupContext) {
|
||||||
return new JsonGroupInfo(Base64.getEncoder().encodeToString(groupInfo.getGroupId()),
|
return new JsonGroupInfo(groupContext.groupId().toBase64(),
|
||||||
groupInfo.getType().toString(),
|
groupContext.isGroupUpdate() ? "UPDATE" : "DELIVER");
|
||||||
groupInfo.getName().orNull(),
|
|
||||||
groupInfo.getMembers().isPresent() ? groupInfo.getMembers()
|
|
||||||
.get()
|
|
||||||
.stream()
|
|
||||||
.map(Util::getLegacyIdentifier)
|
|
||||||
.collect(Collectors.toList()) : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
static JsonGroupInfo from(SignalServiceGroupV2 groupInfo) {
|
|
||||||
return new JsonGroupInfo(GroupUtils.getGroupIdV2(groupInfo.getMasterKey()).toBase64(),
|
|
||||||
groupInfo.hasSignedGroupChange() ? "UPDATE" : "DELIVER",
|
|
||||||
null,
|
|
||||||
null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static JsonGroupInfo from(byte[] groupId) {
|
static JsonGroupInfo from(byte[] groupId) {
|
||||||
return new JsonGroupInfo(Base64.getEncoder().encodeToString(groupId), "DELIVER", null, null);
|
return new JsonGroupInfo(Base64.getEncoder().encodeToString(groupId), "DELIVER");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,17 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
|
||||||
|
|
||||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
import java.util.UUID;
|
||||||
|
|
||||||
public record JsonMention(@Deprecated String name, String number, String uuid, int start, int length) {
|
public record JsonMention(@Deprecated String name, String number, String uuid, int start, int length) {
|
||||||
|
|
||||||
static JsonMention from(SignalServiceDataMessage.Mention mention, Manager m) {
|
static JsonMention from(MessageEnvelope.Data.Mention mention) {
|
||||||
final var address = m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid()));
|
final var address = mention.recipient();
|
||||||
return new JsonMention(getLegacyIdentifier(address),
|
return new JsonMention(address.getLegacyIdentifier(),
|
||||||
address.getNumber().orNull(),
|
address.getNumber().orElse(null),
|
||||||
address.getUuid().toString(),
|
address.getUuid().map(UUID::toString).orElse(null),
|
||||||
mention.getStart(),
|
mention.start(),
|
||||||
mention.getLength());
|
mention.length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,12 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.asamk.signal.manager.UntrustedIdentityException;
|
import org.asamk.signal.manager.UntrustedIdentityException;
|
||||||
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
|
||||||
|
|
||||||
public record JsonMessageEnvelope(
|
public record JsonMessageEnvelope(
|
||||||
@Deprecated String source,
|
@Deprecated String source,
|
||||||
|
@ -29,29 +27,23 @@ public record JsonMessageEnvelope(
|
||||||
) {
|
) {
|
||||||
|
|
||||||
public static JsonMessageEnvelope from(
|
public static JsonMessageEnvelope from(
|
||||||
SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception, Manager m
|
MessageEnvelope envelope, Throwable exception, Manager m
|
||||||
) {
|
) {
|
||||||
final String source;
|
final String source;
|
||||||
final String sourceNumber;
|
final String sourceNumber;
|
||||||
final String sourceUuid;
|
final String sourceUuid;
|
||||||
final Integer sourceDevice;
|
final Integer sourceDevice;
|
||||||
if (!envelope.isUnidentifiedSender() && envelope.hasSourceUuid()) {
|
if (envelope.sourceAddress().isPresent()) {
|
||||||
final var sourceAddress = m.resolveSignalServiceAddress(envelope.getSourceAddress());
|
final var sourceAddress = envelope.sourceAddress().get();
|
||||||
source = getLegacyIdentifier(sourceAddress);
|
source = sourceAddress.getLegacyIdentifier();
|
||||||
sourceNumber = sourceAddress.getNumber().orNull();
|
sourceNumber = sourceAddress.getNumber().orElse(null);
|
||||||
sourceUuid = sourceAddress.getUuid().toString();
|
sourceUuid = sourceAddress.getUuid().map(UUID::toString).orElse(null);
|
||||||
sourceDevice = envelope.getSourceDevice();
|
sourceDevice = envelope.sourceDevice();
|
||||||
} else if (envelope.isUnidentifiedSender() && content != null) {
|
|
||||||
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) {
|
} else if (exception instanceof UntrustedIdentityException e) {
|
||||||
final var sender = m.resolveSignalServiceAddress(e.getSender());
|
final var sender = e.getSender();
|
||||||
source = getLegacyIdentifier(sender);
|
source = sender.getLegacyIdentifier();
|
||||||
sourceNumber = sender.getNumber().orNull();
|
sourceNumber = sender.getNumber().orElse(null);
|
||||||
sourceUuid = sender.getUuid().toString();
|
sourceUuid = sender.getUuid().map(UUID::toString).orElse(null);
|
||||||
sourceDevice = e.getSenderDevice();
|
sourceDevice = e.getSenderDevice();
|
||||||
} else {
|
} else {
|
||||||
source = null;
|
source = null;
|
||||||
|
@ -66,27 +58,13 @@ public record JsonMessageEnvelope(
|
||||||
name = null;
|
name = null;
|
||||||
}
|
}
|
||||||
final var sourceName = name;
|
final var sourceName = name;
|
||||||
final var timestamp = envelope.getTimestamp();
|
final var timestamp = envelope.timestamp();
|
||||||
final JsonReceiptMessage receiptMessage;
|
final var receiptMessage = envelope.receipt().map(JsonReceiptMessage::from).orElse(null);
|
||||||
if (envelope.isReceipt()) {
|
final var typingMessage = envelope.typing().map(JsonTypingMessage::from).orElse(null);
|
||||||
receiptMessage = JsonReceiptMessage.deliveryReceipt(timestamp, List.of(timestamp));
|
|
||||||
} else if (content != null && content.getReceiptMessage().isPresent()) {
|
|
||||||
receiptMessage = JsonReceiptMessage.from(content.getReceiptMessage().get());
|
|
||||||
} else {
|
|
||||||
receiptMessage = null;
|
|
||||||
}
|
|
||||||
final var typingMessage = content != null && content.getTypingMessage().isPresent() ? JsonTypingMessage.from(
|
|
||||||
content.getTypingMessage().get()) : null;
|
|
||||||
|
|
||||||
final var dataMessage = content != null && content.getDataMessage().isPresent()
|
final var dataMessage = envelope.data().map(JsonDataMessage::from).orElse(null);
|
||||||
? JsonDataMessage.from(content.getDataMessage().get(), m)
|
final var syncMessage = envelope.sync().map(JsonSyncMessage::from).orElse(null);
|
||||||
: null;
|
final var callMessage = envelope.call().map(JsonCallMessage::from).orElse(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;
|
|
||||||
|
|
||||||
return new JsonMessageEnvelope(source,
|
return new JsonMessageEnvelope(source,
|
||||||
sourceNumber,
|
sourceNumber,
|
||||||
|
|
|
@ -2,15 +2,13 @@ package org.asamk.signal.json;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
|
||||||
|
|
||||||
public record JsonQuote(
|
public record JsonQuote(
|
||||||
long id,
|
long id,
|
||||||
@Deprecated String author,
|
@Deprecated String author,
|
||||||
|
@ -21,30 +19,23 @@ public record JsonQuote(
|
||||||
List<JsonQuotedAttachment> attachments
|
List<JsonQuotedAttachment> attachments
|
||||||
) {
|
) {
|
||||||
|
|
||||||
static JsonQuote from(SignalServiceDataMessage.Quote quote, Manager m) {
|
static JsonQuote from(MessageEnvelope.Data.Quote quote) {
|
||||||
final var id = quote.getId();
|
final var id = quote.id();
|
||||||
final var address = m.resolveSignalServiceAddress(quote.getAuthor());
|
final var address = quote.author();
|
||||||
final var author = getLegacyIdentifier(address);
|
final var author = address.getLegacyIdentifier();
|
||||||
final var authorNumber = address.getNumber().orNull();
|
final var authorNumber = address.getNumber().orElse(null);
|
||||||
final var authorUuid = address.getUuid().toString();
|
final var authorUuid = address.getUuid().map(UUID::toString).orElse(null);
|
||||||
final var text = quote.getText();
|
final var text = quote.text().orElse(null);
|
||||||
|
|
||||||
final List<JsonMention> mentions;
|
final var mentions = quote.mentions().size() > 0 ? quote.mentions()
|
||||||
if (quote.getMentions() != null && quote.getMentions().size() > 0) {
|
|
||||||
mentions = quote.getMentions()
|
|
||||||
.stream()
|
.stream()
|
||||||
.map(quotedMention -> JsonMention.from(quotedMention, m))
|
.map(JsonMention::from)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList()) : null;
|
||||||
} else {
|
|
||||||
mentions = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<JsonQuotedAttachment> attachments;
|
final var attachments = quote.attachments().size() > 0 ? quote.attachments()
|
||||||
if (quote.getAttachments().size() > 0) {
|
.stream()
|
||||||
attachments = quote.getAttachments().stream().map(JsonQuotedAttachment::from).collect(Collectors.toList());
|
.map(JsonQuotedAttachment::from)
|
||||||
} else {
|
.collect(Collectors.toList()) : new ArrayList<JsonQuotedAttachment>();
|
||||||
attachments = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new JsonQuote(id, author, authorNumber, authorUuid, text, mentions, attachments);
|
return new JsonQuote(id, author, authorNumber, authorUuid, text, mentions, attachments);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,21 +2,18 @@ package org.asamk.signal.json;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
|
|
||||||
public record JsonQuotedAttachment(
|
public record JsonQuotedAttachment(
|
||||||
String contentType, String filename, @JsonInclude(JsonInclude.Include.NON_NULL) JsonAttachment thumbnail
|
String contentType, String filename, @JsonInclude(JsonInclude.Include.NON_NULL) JsonAttachment thumbnail
|
||||||
) {
|
) {
|
||||||
|
|
||||||
static JsonQuotedAttachment from(SignalServiceDataMessage.Quote.QuotedAttachment quotedAttachment) {
|
static JsonQuotedAttachment from(MessageEnvelope.Data.Attachment quotedAttachment) {
|
||||||
final var contentType = quotedAttachment.getContentType();
|
final var contentType = quotedAttachment.contentType();
|
||||||
final var filename = quotedAttachment.getFileName();
|
final var filename = quotedAttachment.fileName().orElse(null);
|
||||||
final JsonAttachment thumbnail;
|
final var thumbnail = quotedAttachment.thumbnail().isPresent()
|
||||||
if (quotedAttachment.getThumbnail() != null) {
|
? JsonAttachment.from(quotedAttachment.thumbnail().get())
|
||||||
thumbnail = JsonAttachment.from(quotedAttachment.getThumbnail());
|
: null;
|
||||||
} else {
|
|
||||||
thumbnail = null;
|
|
||||||
}
|
|
||||||
return new JsonQuotedAttachment(contentType, filename, thumbnail);
|
return new JsonQuotedAttachment(contentType, filename, thumbnail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Reaction;
|
|
||||||
|
|
||||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
import java.util.UUID;
|
||||||
|
|
||||||
public record JsonReaction(
|
public record JsonReaction(
|
||||||
String emoji,
|
String emoji,
|
||||||
|
@ -14,13 +13,13 @@ public record JsonReaction(
|
||||||
boolean isRemove
|
boolean isRemove
|
||||||
) {
|
) {
|
||||||
|
|
||||||
static JsonReaction from(Reaction reaction, Manager m) {
|
static JsonReaction from(MessageEnvelope.Data.Reaction reaction) {
|
||||||
final var emoji = reaction.getEmoji();
|
final var emoji = reaction.emoji();
|
||||||
final var address = m.resolveSignalServiceAddress(reaction.getTargetAuthor());
|
final var address = reaction.targetAuthor();
|
||||||
final var targetAuthor = getLegacyIdentifier(address);
|
final var targetAuthor = address.getLegacyIdentifier();
|
||||||
final var targetAuthorNumber = address.getNumber().orNull();
|
final var targetAuthorNumber = address.getNumber().orElse(null);
|
||||||
final var targetAuthorUuid = address.getUuid().toString();
|
final var targetAuthorUuid = address.getUuid().map(UUID::toString).orElse(null);
|
||||||
final var targetSentTimestamp = reaction.getTargetSentTimestamp();
|
final var targetSentTimestamp = reaction.targetSentTimestamp();
|
||||||
final var isRemove = reaction.isRemove();
|
final var isRemove = reaction.isRemove();
|
||||||
return new JsonReaction(emoji,
|
return new JsonReaction(emoji,
|
||||||
targetAuthor,
|
targetAuthor,
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
record JsonReceiptMessage(long when, boolean isDelivery, boolean isRead, boolean isViewed, List<Long> timestamps) {
|
record JsonReceiptMessage(long when, boolean isDelivery, boolean isRead, boolean isViewed, List<Long> timestamps) {
|
||||||
|
|
||||||
static JsonReceiptMessage from(SignalServiceReceiptMessage receiptMessage) {
|
static JsonReceiptMessage from(MessageEnvelope.Receipt receiptMessage) {
|
||||||
final var when = receiptMessage.getWhen();
|
final var when = receiptMessage.when();
|
||||||
final var isDelivery = receiptMessage.isDeliveryReceipt();
|
final var isDelivery = receiptMessage.type() == MessageEnvelope.Receipt.Type.DELIVERY;
|
||||||
final var isRead = receiptMessage.isReadReceipt();
|
final var isRead = receiptMessage.type() == MessageEnvelope.Receipt.Type.READ;
|
||||||
final var isViewed = receiptMessage.isViewedReceipt();
|
final var isViewed = receiptMessage.type() == MessageEnvelope.Receipt.Type.VIEWED;
|
||||||
final var timestamps = receiptMessage.getTimestamps();
|
final var timestamps = receiptMessage.timestamps();
|
||||||
return new JsonReceiptMessage(when, isDelivery, isRead, isViewed, timestamps);
|
return new JsonReceiptMessage(when, isDelivery, isRead, isViewed, timestamps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,3 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
record JsonRemoteDelete(long timestamp) {}
|
||||||
|
|
||||||
record JsonRemoteDelete(long timestamp) {
|
|
||||||
|
|
||||||
static JsonRemoteDelete from(SignalServiceDataMessage.RemoteDelete remoteDelete) {
|
|
||||||
return new JsonRemoteDelete(remoteDelete.getTargetSentTimestamp());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,43 +2,40 @@ package org.asamk.signal.json;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public record JsonSharedContact(
|
public record JsonSharedContact(
|
||||||
JsonContactName name,
|
JsonContactName name,
|
||||||
JsonContactAvatar avatar,
|
@JsonInclude(JsonInclude.Include.NON_NULL) JsonContactAvatar avatar,
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonContactPhone> phone,
|
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonContactPhone> phone,
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonContactEmail> email,
|
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonContactEmail> email,
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonContactAddress> address,
|
@JsonInclude(JsonInclude.Include.NON_NULL) List<JsonContactAddress> address,
|
||||||
String organization
|
String organization
|
||||||
) {
|
) {
|
||||||
|
|
||||||
static JsonSharedContact from(SharedContact contact) {
|
static JsonSharedContact from(MessageEnvelope.Data.SharedContact contact) {
|
||||||
final var name = JsonContactName.from(contact.getName());
|
final var name = JsonContactName.from(contact.name());
|
||||||
final var avatar = contact.getAvatar().isPresent() ? JsonContactAvatar.from(contact.getAvatar().get()) : null;
|
final var avatar = contact.avatar().isPresent() ? JsonContactAvatar.from(contact.avatar().get()) : null;
|
||||||
|
|
||||||
final var phone = contact.getPhone().isPresent() ? contact.getPhone()
|
final var phone = contact.phone().size() > 0 ? contact.phone()
|
||||||
.get()
|
|
||||||
.stream()
|
.stream()
|
||||||
.map(JsonContactPhone::from)
|
.map(JsonContactPhone::from)
|
||||||
.collect(Collectors.toList()) : null;
|
.collect(Collectors.toList()) : null;
|
||||||
|
|
||||||
final var email = contact.getEmail().isPresent() ? contact.getEmail()
|
final var email = contact.email().size() > 0 ? contact.email()
|
||||||
.get()
|
|
||||||
.stream()
|
.stream()
|
||||||
.map(JsonContactEmail::from)
|
.map(JsonContactEmail::from)
|
||||||
.collect(Collectors.toList()) : null;
|
.collect(Collectors.toList()) : null;
|
||||||
|
|
||||||
final var address = contact.getAddress().isPresent() ? contact.getAddress()
|
final var address = contact.address().size() > 0 ? contact.address()
|
||||||
.get()
|
|
||||||
.stream()
|
.stream()
|
||||||
.map(JsonContactAddress::from)
|
.map(JsonContactAddress::from)
|
||||||
.collect(Collectors.toList()) : null;
|
.collect(Collectors.toList()) : null;
|
||||||
|
|
||||||
final var organization = contact.getOrganization().orNull();
|
final var organization = contact.organization().orElse(null);
|
||||||
|
|
||||||
return new JsonSharedContact(name, avatar, phone, email, address, organization);
|
return new JsonSharedContact(name, avatar, phone, email, address, organization);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|
||||||
public record JsonSticker(String packId, String packKey, int stickerId) {
|
public record JsonSticker(String packId, String packKey, int stickerId) {
|
||||||
|
|
||||||
static JsonSticker from(SignalServiceDataMessage.Sticker sticker) {
|
static JsonSticker from(MessageEnvelope.Data.Sticker sticker) {
|
||||||
final var packId = Base64.getEncoder().encodeToString(sticker.getPackId());
|
final var encoder = Base64.getEncoder();
|
||||||
final var packKey = Base64.getEncoder().encodeToString(sticker.getPackKey());
|
final var packId = encoder.encodeToString(sticker.packId());
|
||||||
final var stickerId = sticker.getStickerId();
|
final var packKey = encoder.encodeToString(sticker.packKey());
|
||||||
|
final var stickerId = sticker.stickerId();
|
||||||
return new JsonSticker(packId, packKey, stickerId);
|
return new JsonSticker(packId, packKey, stickerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,9 @@ package org.asamk.signal.json;
|
||||||
import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
|
|
||||||
|
|
||||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
import java.util.UUID;
|
||||||
|
|
||||||
record JsonSyncDataMessage(
|
record JsonSyncDataMessage(
|
||||||
@Deprecated String destination,
|
@Deprecated String destination,
|
||||||
|
@ -15,16 +14,16 @@ record JsonSyncDataMessage(
|
||||||
@JsonUnwrapped JsonDataMessage dataMessage
|
@JsonUnwrapped JsonDataMessage dataMessage
|
||||||
) {
|
) {
|
||||||
|
|
||||||
static JsonSyncDataMessage from(SentTranscriptMessage transcriptMessage, Manager m) {
|
static JsonSyncDataMessage from(MessageEnvelope.Sync.Sent transcriptMessage) {
|
||||||
if (transcriptMessage.getDestination().isPresent()) {
|
if (transcriptMessage.destination().isPresent()) {
|
||||||
final var address = transcriptMessage.getDestination().get();
|
final var address = transcriptMessage.destination().get();
|
||||||
return new JsonSyncDataMessage(getLegacyIdentifier(address),
|
return new JsonSyncDataMessage(address.getLegacyIdentifier(),
|
||||||
address.getNumber().orNull(),
|
address.getNumber().orElse(null),
|
||||||
address.getUuid().toString(),
|
address.getUuid().map(UUID::toString).orElse(null),
|
||||||
JsonDataMessage.from(transcriptMessage.getMessage(), m));
|
JsonDataMessage.from(transcriptMessage.message()));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return new JsonSyncDataMessage(null, null, null, JsonDataMessage.from(transcriptMessage.getMessage(), m));
|
return new JsonSyncDataMessage(null, null, null, JsonDataMessage.from(transcriptMessage.message()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,10 @@ package org.asamk.signal.json;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.manager.groups.GroupId;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||||
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -39,43 +38,40 @@ record JsonSyncMessage(
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JsonSyncMessage from(SignalServiceSyncMessage syncMessage, Manager m) {
|
static JsonSyncMessage from(MessageEnvelope.Sync syncMessage) {
|
||||||
final var sentMessage = syncMessage.getSent().isPresent() ? JsonSyncDataMessage.from(syncMessage.getSent()
|
final var sentMessage = syncMessage.sent().isPresent()
|
||||||
.get(), m) : null;
|
? JsonSyncDataMessage.from(syncMessage.sent().get())
|
||||||
|
: null;
|
||||||
final List<String> blockedNumbers;
|
final List<String> blockedNumbers;
|
||||||
final List<String> blockedGroupIds;
|
final List<String> blockedGroupIds;
|
||||||
if (syncMessage.getBlockedList().isPresent()) {
|
if (syncMessage.blocked().isPresent()) {
|
||||||
final var base64 = Base64.getEncoder();
|
blockedNumbers = syncMessage.blocked()
|
||||||
blockedNumbers = syncMessage.getBlockedList()
|
|
||||||
.get()
|
.get()
|
||||||
.getAddresses()
|
.recipients()
|
||||||
.stream()
|
.stream()
|
||||||
.map(Util::getLegacyIdentifier)
|
.map(RecipientAddress::getLegacyIdentifier)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
blockedGroupIds = syncMessage.getBlockedList()
|
blockedGroupIds = syncMessage.blocked()
|
||||||
.get()
|
.get()
|
||||||
.getGroupIds()
|
.groupIds()
|
||||||
.stream()
|
.stream()
|
||||||
.map(base64::encodeToString)
|
.map(GroupId::toBase64)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} else {
|
} else {
|
||||||
blockedNumbers = null;
|
blockedNumbers = null;
|
||||||
blockedGroupIds = null;
|
blockedGroupIds = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final var readMessages = syncMessage.getRead().isPresent() ? syncMessage.getRead()
|
final var readMessages = syncMessage.read().size() > 0 ? syncMessage.read()
|
||||||
.get()
|
|
||||||
.stream()
|
.stream()
|
||||||
.map(JsonSyncReadMessage::from)
|
.map(JsonSyncReadMessage::from)
|
||||||
.collect(Collectors.toList()) : null;
|
.collect(Collectors.toList()) : null;
|
||||||
|
|
||||||
final JsonSyncMessageType type;
|
final JsonSyncMessageType type;
|
||||||
if (syncMessage.getContacts().isPresent()) {
|
if (syncMessage.contacts().isPresent()) {
|
||||||
type = JsonSyncMessageType.CONTACTS_SYNC;
|
type = JsonSyncMessageType.CONTACTS_SYNC;
|
||||||
} else if (syncMessage.getGroups().isPresent()) {
|
} else if (syncMessage.groups().isPresent()) {
|
||||||
type = JsonSyncMessageType.GROUPS_SYNC;
|
type = JsonSyncMessageType.GROUPS_SYNC;
|
||||||
} else if (syncMessage.getRequest().isPresent()) {
|
|
||||||
type = JsonSyncMessageType.REQUEST_SYNC;
|
|
||||||
} else {
|
} else {
|
||||||
type = null;
|
type = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
|
|
||||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
import java.util.UUID;
|
||||||
|
|
||||||
record JsonSyncReadMessage(
|
record JsonSyncReadMessage(
|
||||||
@Deprecated String sender, String senderNumber, String senderUuid, long timestamp
|
@Deprecated String sender, String senderNumber, String senderUuid, long timestamp
|
||||||
) {
|
) {
|
||||||
|
|
||||||
static JsonSyncReadMessage from(final ReadMessage readMessage) {
|
static JsonSyncReadMessage from(MessageEnvelope.Sync.Read readMessage) {
|
||||||
final var senderAddress = readMessage.getSender();
|
final var senderAddress = readMessage.sender();
|
||||||
final var sender = getLegacyIdentifier(senderAddress);
|
final var sender = senderAddress.getLegacyIdentifier();
|
||||||
final var senderNumber = senderAddress.getNumber().orNull();
|
final var senderNumber = senderAddress.getNumber().orElse(null);
|
||||||
final var senderUuid = senderAddress.getUuid().toString();
|
final var senderUuid = senderAddress.getUuid().map(UUID::toString).orElse(null);
|
||||||
final var timestamp = readMessage.getTimestamp();
|
final var timestamp = readMessage.timestamp();
|
||||||
return new JsonSyncReadMessage(sender, senderNumber, senderUuid, timestamp);
|
return new JsonSyncReadMessage(sender, senderNumber, senderUuid, timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,25 +2,17 @@ package org.asamk.signal.json;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||||
|
import org.asamk.signal.manager.groups.GroupId;
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
record JsonTypingMessage(
|
record JsonTypingMessage(
|
||||||
String action, long timestamp, @JsonInclude(JsonInclude.Include.NON_NULL) String groupId
|
String action, long timestamp, @JsonInclude(JsonInclude.Include.NON_NULL) String groupId
|
||||||
) {
|
) {
|
||||||
|
|
||||||
JsonTypingMessage(final String action, final long timestamp, final String groupId) {
|
static JsonTypingMessage from(MessageEnvelope.Typing typingMessage) {
|
||||||
this.action = action;
|
final var action = typingMessage.type().name();
|
||||||
this.timestamp = timestamp;
|
final var timestamp = typingMessage.timestamp();
|
||||||
this.groupId = groupId;
|
final var groupId = typingMessage.groupId().map(GroupId::toBase64).orElse(null);
|
||||||
}
|
|
||||||
|
|
||||||
static JsonTypingMessage from(SignalServiceTypingMessage typingMessage) {
|
|
||||||
final var action = typingMessage.getAction().name();
|
|
||||||
final var timestamp = typingMessage.getTimestamp();
|
|
||||||
final var encoder = Base64.getEncoder();
|
|
||||||
final var groupId = typingMessage.getGroupId().transform(encoder::encodeToString).orNull();
|
|
||||||
return new JsonTypingMessage(action, timestamp, groupId);
|
return new JsonTypingMessage(action, timestamp, groupId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Util {
|
public class Util {
|
||||||
|
@ -17,8 +18,8 @@ public class Util {
|
||||||
private Util() {
|
private Util() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getStringIfNotBlank(org.whispersystems.libsignal.util.guava.Optional<String> value) {
|
public static String getStringIfNotBlank(Optional<String> value) {
|
||||||
var string = value.orNull();
|
var string = value.orElse(null);
|
||||||
if (string == null || string.isBlank()) {
|
if (string == null || string.isBlank()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue