mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-02 12:30:39 +00:00
Added support for quotes, mentions and reactions in non-daemon JSON output
This commit is contained in:
parent
83d5d53d8a
commit
1de0bbd4f7
10 changed files with 132 additions and 9 deletions
|
@ -35,7 +35,7 @@ public class JsonReceiveMessageHandler implements Manager.ReceiveMessageHandler
|
||||||
result.putPOJO("error", new JsonError(exception));
|
result.putPOJO("error", new JsonError(exception));
|
||||||
}
|
}
|
||||||
if (envelope != null) {
|
if (envelope != null) {
|
||||||
result.putPOJO("envelope", new JsonMessageEnvelope(envelope, content));
|
result.putPOJO("envelope", new JsonMessageEnvelope(envelope, content, m));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
jsonProcessor.writeValue(System.out, result);
|
jsonProcessor.writeValue(System.out, result);
|
||||||
|
|
|
@ -25,6 +25,20 @@ class JsonAttachment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used for the quoted attachments
|
||||||
|
JsonAttachment(SignalServiceAttachment attachment, String filename) {
|
||||||
|
this.contentType = attachment.getContentType();
|
||||||
|
|
||||||
|
final SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
||||||
|
if (attachment.isPointer()) {
|
||||||
|
this.id = String.valueOf(pointer.getRemoteId());
|
||||||
|
this.filename = filename;
|
||||||
|
if (pointer.getSize().isPresent()) {
|
||||||
|
this.size = pointer.getSize().get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
JsonAttachment(String filename) {
|
JsonAttachment(String filename) {
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
||||||
|
@ -15,10 +16,14 @@ class JsonDataMessage {
|
||||||
long timestamp;
|
long timestamp;
|
||||||
String message;
|
String message;
|
||||||
int expiresInSeconds;
|
int expiresInSeconds;
|
||||||
|
|
||||||
|
JsonReaction reaction;
|
||||||
|
JsonQuote quote;
|
||||||
|
List<JsonMention> mentions;
|
||||||
List<JsonAttachment> attachments;
|
List<JsonAttachment> attachments;
|
||||||
JsonGroupInfo groupInfo;
|
JsonGroupInfo groupInfo;
|
||||||
|
|
||||||
JsonDataMessage(SignalServiceDataMessage dataMessage) {
|
JsonDataMessage(SignalServiceDataMessage dataMessage, final Manager m) {
|
||||||
this.timestamp = dataMessage.getTimestamp();
|
this.timestamp = dataMessage.getTimestamp();
|
||||||
if (dataMessage.getGroupContext().isPresent()) {
|
if (dataMessage.getGroupContext().isPresent()) {
|
||||||
if (dataMessage.getGroupContext().get().getGroupV1().isPresent()) {
|
if (dataMessage.getGroupContext().get().getGroupV1().isPresent()) {
|
||||||
|
@ -33,6 +38,27 @@ class JsonDataMessage {
|
||||||
this.message = dataMessage.getBody().get();
|
this.message = dataMessage.getBody().get();
|
||||||
}
|
}
|
||||||
this.expiresInSeconds = dataMessage.getExpiresInSeconds();
|
this.expiresInSeconds = dataMessage.getExpiresInSeconds();
|
||||||
|
if (dataMessage.getReaction().isPresent()) {
|
||||||
|
if(m == null){
|
||||||
|
System.out.println("ERROR, MANAGER NOT SET");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.reaction = new JsonReaction(dataMessage.getReaction().get(), m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dataMessage.getQuote().isPresent()) {
|
||||||
|
this.quote = new JsonQuote(dataMessage.getQuote().get());
|
||||||
|
} else {
|
||||||
|
this.quote = null;
|
||||||
|
}
|
||||||
|
if (dataMessage.getMentions().isPresent()) {
|
||||||
|
this.mentions = new ArrayList<>(dataMessage.getMentions().get().size());
|
||||||
|
for (SignalServiceDataMessage.Mention mention : dataMessage.getMentions().get()) {
|
||||||
|
this.mentions.add(new JsonMention(mention));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.mentions = new ArrayList<>();
|
||||||
|
}
|
||||||
if (dataMessage.getAttachments().isPresent()) {
|
if (dataMessage.getAttachments().isPresent()) {
|
||||||
this.attachments = new ArrayList<>(dataMessage.getAttachments().get().size());
|
this.attachments = new ArrayList<>(dataMessage.getAttachments().get().size());
|
||||||
for (SignalServiceAttachment attachment : dataMessage.getAttachments().get()) {
|
for (SignalServiceAttachment attachment : dataMessage.getAttachments().get()) {
|
||||||
|
@ -47,6 +73,9 @@ class JsonDataMessage {
|
||||||
timestamp = messageReceived.getTimestamp();
|
timestamp = messageReceived.getTimestamp();
|
||||||
message = messageReceived.getMessage();
|
message = messageReceived.getMessage();
|
||||||
groupInfo = new JsonGroupInfo(messageReceived.getGroupId());
|
groupInfo = new JsonGroupInfo(messageReceived.getGroupId());
|
||||||
|
reaction = null; // TEMP until I understand how to do this
|
||||||
|
quote = null;
|
||||||
|
mentions = null;
|
||||||
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
|
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +83,9 @@ class JsonDataMessage {
|
||||||
timestamp = messageReceived.getTimestamp();
|
timestamp = messageReceived.getTimestamp();
|
||||||
message = messageReceived.getMessage();
|
message = messageReceived.getMessage();
|
||||||
groupInfo = new JsonGroupInfo(messageReceived.getGroupId());
|
groupInfo = new JsonGroupInfo(messageReceived.getGroupId());
|
||||||
|
reaction = null; // TEMP until I understand how to do this
|
||||||
|
quote = null;
|
||||||
|
mentions = null;
|
||||||
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
|
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ class JsonGroupInfo {
|
||||||
|
|
||||||
JsonGroupInfo(SignalServiceGroupV2 groupInfo) {
|
JsonGroupInfo(SignalServiceGroupV2 groupInfo) {
|
||||||
this.groupId = Base64.encodeBytes(GroupUtils.getGroupId(groupInfo.getMasterKey()));
|
this.groupId = Base64.encodeBytes(GroupUtils.getGroupId(groupInfo.getMasterKey()));
|
||||||
|
// TODO populate members and name fields
|
||||||
this.type = groupInfo.hasSignedGroupChange() ? "UPDATE" : "DELIVER";
|
this.type = groupInfo.hasSignedGroupChange() ? "UPDATE" : "DELIVER";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
src/main/java/org/asamk/signal/json/JsonMention.java
Normal file
18
src/main/java/org/asamk/signal/json/JsonMention.java
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||||
|
|
||||||
|
public class JsonMention {
|
||||||
|
|
||||||
|
UUID uuid; // If possible, it would be nice to resolve this into their phone-number/name. Same for plain-text output
|
||||||
|
int start;
|
||||||
|
int length;
|
||||||
|
|
||||||
|
JsonMention(SignalServiceDataMessage.Mention mention){
|
||||||
|
this.uuid = mention.getUuid();
|
||||||
|
this.start = mention.getStart();
|
||||||
|
this.length = mention.getLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
|
@ -18,7 +19,9 @@ public class JsonMessageEnvelope {
|
||||||
JsonCallMessage callMessage;
|
JsonCallMessage callMessage;
|
||||||
JsonReceiptMessage receiptMessage;
|
JsonReceiptMessage receiptMessage;
|
||||||
|
|
||||||
public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content) {
|
public JsonMessageEnvelope(
|
||||||
|
SignalServiceEnvelope envelope, SignalServiceContent content, final Manager m
|
||||||
|
) {
|
||||||
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
|
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
|
||||||
SignalServiceAddress source = envelope.getSourceAddress();
|
SignalServiceAddress source = envelope.getSourceAddress();
|
||||||
this.source = source.getLegacyIdentifier();
|
this.source = source.getLegacyIdentifier();
|
||||||
|
@ -35,10 +38,10 @@ public class JsonMessageEnvelope {
|
||||||
this.sourceDevice = content.getSenderDevice();
|
this.sourceDevice = content.getSenderDevice();
|
||||||
}
|
}
|
||||||
if (content.getDataMessage().isPresent()) {
|
if (content.getDataMessage().isPresent()) {
|
||||||
this.dataMessage = new JsonDataMessage(content.getDataMessage().get());
|
this.dataMessage = new JsonDataMessage(content.getDataMessage().get(), m);
|
||||||
}
|
}
|
||||||
if (content.getSyncMessage().isPresent()) {
|
if (content.getSyncMessage().isPresent()) {
|
||||||
this.syncMessage = new JsonSyncMessage(content.getSyncMessage().get());
|
this.syncMessage = new JsonSyncMessage(content.getSyncMessage().get(), m);
|
||||||
}
|
}
|
||||||
if (content.getCallMessage().isPresent()) {
|
if (content.getCallMessage().isPresent()) {
|
||||||
this.callMessage = new JsonCallMessage(content.getCallMessage().get());
|
this.callMessage = new JsonCallMessage(content.getCallMessage().get());
|
||||||
|
|
34
src/main/java/org/asamk/signal/json/JsonQuote.java
Normal file
34
src/main/java/org/asamk/signal/json/JsonQuote.java
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class JsonQuote {
|
||||||
|
|
||||||
|
long id;
|
||||||
|
String author;
|
||||||
|
String text;
|
||||||
|
List<JsonAttachment> attachments;
|
||||||
|
|
||||||
|
JsonQuote(SignalServiceDataMessage.Quote quote){
|
||||||
|
this.id = quote.getId();
|
||||||
|
this.author = quote.getAuthor().getLegacyIdentifier();
|
||||||
|
this.text = quote.getText();
|
||||||
|
|
||||||
|
if (quote.getAttachments().size() > 0) {
|
||||||
|
this.attachments = new ArrayList<>(quote.getAttachments().size());
|
||||||
|
for (SignalServiceDataMessage.Quote.QuotedAttachment quotedAttachment : quote.getAttachments()) {
|
||||||
|
// We use this constructor to override the filename since the one in the thumbnail is lost
|
||||||
|
this.attachments.add(new JsonAttachment(
|
||||||
|
quotedAttachment.getThumbnail(),
|
||||||
|
quotedAttachment.getFileName()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.attachments = new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
src/main/java/org/asamk/signal/json/JsonReaction.java
Normal file
19
src/main/java/org/asamk/signal/json/JsonReaction.java
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
|
import org.asamk.signal.manager.Manager;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Reaction;
|
||||||
|
|
||||||
|
public class JsonReaction {
|
||||||
|
|
||||||
|
String emoji;
|
||||||
|
String targetAuthor;
|
||||||
|
long targetSentTimestamp;
|
||||||
|
boolean isRemove;
|
||||||
|
|
||||||
|
JsonReaction(Reaction reaction, final Manager m){
|
||||||
|
this.emoji = reaction.getEmoji();
|
||||||
|
this.targetAuthor = m.resolveSignalServiceAddress(reaction.getTargetAuthor()).getLegacyIdentifier();
|
||||||
|
this.targetSentTimestamp = reaction.getTargetSentTimestamp();
|
||||||
|
this.isRemove = reaction.isRemove();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +1,15 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
|
||||||
|
|
||||||
class JsonSyncDataMessage extends JsonDataMessage {
|
class JsonSyncDataMessage extends JsonDataMessage {
|
||||||
|
|
||||||
String destination;
|
String destination;
|
||||||
|
|
||||||
JsonSyncDataMessage(SentTranscriptMessage transcriptMessage) {
|
JsonSyncDataMessage(SentTranscriptMessage transcriptMessage, final Manager m) {
|
||||||
super(transcriptMessage.getMessage());
|
super(transcriptMessage.getMessage(), m);
|
||||||
if (transcriptMessage.getDestination().isPresent()) {
|
if (transcriptMessage.getDestination().isPresent()) {
|
||||||
this.destination = transcriptMessage.getDestination().get().getLegacyIdentifier();
|
this.destination = transcriptMessage.getDestination().get().getLegacyIdentifier();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
|
@ -21,9 +22,9 @@ class JsonSyncMessage {
|
||||||
List<ReadMessage> readMessages;
|
List<ReadMessage> readMessages;
|
||||||
JsonSyncMessageType type;
|
JsonSyncMessageType type;
|
||||||
|
|
||||||
JsonSyncMessage(SignalServiceSyncMessage syncMessage) {
|
JsonSyncMessage(SignalServiceSyncMessage syncMessage, final Manager m) {
|
||||||
if (syncMessage.getSent().isPresent()) {
|
if (syncMessage.getSent().isPresent()) {
|
||||||
this.sentMessage = new JsonSyncDataMessage(syncMessage.getSent().get());
|
this.sentMessage = new JsonSyncDataMessage(syncMessage.getSent().get(), m);
|
||||||
}
|
}
|
||||||
if (syncMessage.getBlockedList().isPresent()) {
|
if (syncMessage.getBlockedList().isPresent()) {
|
||||||
this.blockedNumbers = new ArrayList<>(syncMessage.getBlockedList().get().getAddresses().size());
|
this.blockedNumbers = new ArrayList<>(syncMessage.getBlockedList().get().getAddresses().size());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue