Quotes, Mentions and Reactions in non-daemon JSON mode (#389)

* Added support for quotes, mentions and reactions in non-daemon JSON output
This commit is contained in:
Atomic-Bean 2020-12-23 20:53:40 +10:30 committed by GitHub
parent 548c313b4c
commit 58db3cbd53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 162 additions and 19 deletions

View file

@ -35,7 +35,7 @@ public class JsonReceiveMessageHandler implements Manager.ReceiveMessageHandler
result.putPOJO("error", new JsonError(exception));
}
if (envelope != null) {
result.putPOJO("envelope", new JsonMessageEnvelope(envelope, content));
result.putPOJO("envelope", new JsonMessageEnvelope(envelope, content, m));
}
try {
jsonProcessor.writeValue(System.out, result);

View file

@ -447,8 +447,14 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (message.getQuote().isPresent()) {
SignalServiceDataMessage.Quote quote = message.getQuote().get();
System.out.println("Quote: (" + quote.getId() + ")");
System.out.println(" Author: " + quote.getAuthor().getLegacyIdentifier());
System.out.println(" Author: " + m.resolveSignalServiceAddress(quote.getAuthor()).getLegacyIdentifier());
System.out.println(" Text: " + quote.getText());
if (quote.getMentions().size() > 0) {
System.out.println(" Mentions: ");
for (SignalServiceDataMessage.Mention mention : quote.getMentions()) {
printMention(mention, m);
}
}
if (quote.getAttachments().size() > 0) {
System.out.println(" Attachments: ");
for (SignalServiceDataMessage.Quote.QuotedAttachment attachment : quote.getAttachments()) {
@ -467,16 +473,9 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
System.out.println("Remote delete message: timestamp = " + remoteDelete.getTargetSentTimestamp());
}
if (message.getMentions().isPresent()) {
final List<SignalServiceDataMessage.Mention> mentions = message.getMentions().get();
System.out.println("Mentions: ");
for (SignalServiceDataMessage.Mention mention : mentions) {
System.out.println("- "
+ mention.getUuid()
+ ": "
+ mention.getStart()
+ " (length: "
+ mention.getLength()
+ ")");
for (SignalServiceDataMessage.Mention mention : message.getMentions().get()) {
printMention(mention, m);
}
}
@ -488,6 +487,18 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
}
}
private void printMention(SignalServiceDataMessage.Mention mention, Manager m) {
System.out.println("- "
+ m.resolveSignalServiceAddress(
new SignalServiceAddress(mention.getUuid(), null)
).getLegacyIdentifier()
+ ": "
+ mention.getStart()
+ " (length: "
+ mention.getLength()
+ ")");
}
private void printAttachment(SignalServiceAttachment attachment) {
System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (
attachment.isStream() ? "Stream" : ""

View file

@ -1,6 +1,7 @@
package org.asamk.signal.json;
import org.asamk.Signal;
import org.asamk.signal.manager.Manager;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
@ -15,10 +16,14 @@ class JsonDataMessage {
long timestamp;
String message;
int expiresInSeconds;
JsonReaction reaction;
JsonQuote quote;
List<JsonMention> mentions;
List<JsonAttachment> attachments;
JsonGroupInfo groupInfo;
JsonDataMessage(SignalServiceDataMessage dataMessage) {
JsonDataMessage(SignalServiceDataMessage dataMessage, Manager m) {
this.timestamp = dataMessage.getTimestamp();
if (dataMessage.getGroupContext().isPresent()) {
if (dataMessage.getGroupContext().get().getGroupV1().isPresent()) {
@ -33,6 +38,20 @@ class JsonDataMessage {
this.message = dataMessage.getBody().get();
}
this.expiresInSeconds = dataMessage.getExpiresInSeconds();
if (dataMessage.getReaction().isPresent()) {
this.reaction = new JsonReaction(dataMessage.getReaction().get(), m);
}
if (dataMessage.getQuote().isPresent()) {
this.quote = new JsonQuote(dataMessage.getQuote().get(), m);
}
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, m));
}
} else {
this.mentions = new ArrayList<>();
}
if (dataMessage.getAttachments().isPresent()) {
this.attachments = new ArrayList<>(dataMessage.getAttachments().get().size());
for (SignalServiceAttachment attachment : dataMessage.getAttachments().get()) {
@ -47,6 +66,9 @@ class JsonDataMessage {
timestamp = messageReceived.getTimestamp();
message = messageReceived.getMessage();
groupInfo = new JsonGroupInfo(messageReceived.getGroupId());
reaction = null; // TODO Replace these 3 with the proper commands
quote = null;
mentions = null;
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
}
@ -54,6 +76,9 @@ class JsonDataMessage {
timestamp = messageReceived.getTimestamp();
message = messageReceived.getMessage();
groupInfo = new JsonGroupInfo(messageReceived.getGroupId());
reaction = null; // TODO Replace these 3 with the proper commands
quote = null;
mentions = null;
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
}
}

View file

@ -0,0 +1,22 @@
package org.asamk.signal.json;
import org.asamk.signal.manager.Manager;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
public class JsonMention {
String name;
int start;
int length;
JsonMention(SignalServiceDataMessage.Mention mention, Manager m) {
this.name = m.resolveSignalServiceAddress(
new SignalServiceAddress(mention.getUuid(), null)
).getLegacyIdentifier();
this.start = mention.getStart();
this.length = mention.getLength();
}
}

View file

@ -1,6 +1,7 @@
package org.asamk.signal.json;
import org.asamk.Signal;
import org.asamk.signal.manager.Manager;
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
@ -18,7 +19,7 @@ public class JsonMessageEnvelope {
JsonCallMessage callMessage;
JsonReceiptMessage receiptMessage;
public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content) {
public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content, Manager m) {
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
SignalServiceAddress source = envelope.getSourceAddress();
this.source = source.getLegacyIdentifier();
@ -35,10 +36,10 @@ public class JsonMessageEnvelope {
this.sourceDevice = content.getSenderDevice();
}
if (content.getDataMessage().isPresent()) {
this.dataMessage = new JsonDataMessage(content.getDataMessage().get());
this.dataMessage = new JsonDataMessage(content.getDataMessage().get(), m);
}
if (content.getSyncMessage().isPresent()) {
this.syncMessage = new JsonSyncMessage(content.getSyncMessage().get());
this.syncMessage = new JsonSyncMessage(content.getSyncMessage().get(), m);
}
if (content.getCallMessage().isPresent()) {
this.callMessage = new JsonCallMessage(content.getCallMessage().get());

View file

@ -0,0 +1,42 @@
package org.asamk.signal.json;
import org.asamk.signal.manager.Manager;
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<JsonMention> mentions;
List<JsonQuotedAttachment> attachments;
JsonQuote(SignalServiceDataMessage.Quote quote, Manager m) {
this.id = quote.getId();
this.author = m.resolveSignalServiceAddress(quote.getAuthor()).getLegacyIdentifier();
this.text = quote.getText();
if (quote.getMentions().size() > 0) {
this.mentions = new ArrayList<>(quote.getMentions().size());
for (SignalServiceDataMessage.Mention quotedMention: quote.getMentions()){
this.mentions.add(new JsonMention(quotedMention, m));
}
}
if (quote.getAttachments().size() > 0) {
this.attachments = new ArrayList<>(quote.getAttachments().size());
for (SignalServiceDataMessage.Quote.QuotedAttachment quotedAttachment : quote.getAttachments()) {
this.attachments.add(new JsonQuotedAttachment(quotedAttachment));
}
} else {
this.attachments = new ArrayList<>();
}
}
}

View file

@ -0,0 +1,21 @@
package org.asamk.signal.json;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
public class JsonQuotedAttachment {
String contentType;
String filename;
JsonAttachment thumbnail;
JsonQuotedAttachment(SignalServiceDataMessage.Quote.QuotedAttachment quotedAttachment) {
contentType = quotedAttachment.getContentType();
filename = quotedAttachment.getFileName();
if (quotedAttachment.getThumbnail() != null) {
thumbnail = new JsonAttachment(quotedAttachment.getThumbnail());
}
else {
thumbnail = null;
}
}
}

View 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, Manager m) {
this.emoji = reaction.getEmoji();
this.targetAuthor = m.resolveSignalServiceAddress(reaction.getTargetAuthor()).getLegacyIdentifier();
this.targetSentTimestamp = reaction.getTargetSentTimestamp();
this.isRemove = reaction.isRemove();
}
}

View file

@ -1,14 +1,15 @@
package org.asamk.signal.json;
import org.asamk.Signal;
import org.asamk.signal.manager.Manager;
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
class JsonSyncDataMessage extends JsonDataMessage {
String destination;
JsonSyncDataMessage(SentTranscriptMessage transcriptMessage) {
super(transcriptMessage.getMessage());
JsonSyncDataMessage(SentTranscriptMessage transcriptMessage, Manager m) {
super(transcriptMessage.getMessage(), m);
if (transcriptMessage.getDestination().isPresent()) {
this.destination = transcriptMessage.getDestination().get().getLegacyIdentifier();
}

View file

@ -1,6 +1,7 @@
package org.asamk.signal.json;
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.SignalServiceSyncMessage;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
@ -21,9 +22,9 @@ class JsonSyncMessage {
List<ReadMessage> readMessages;
JsonSyncMessageType type;
JsonSyncMessage(SignalServiceSyncMessage syncMessage) {
JsonSyncMessage(SignalServiceSyncMessage syncMessage, Manager m) {
if (syncMessage.getSent().isPresent()) {
this.sentMessage = new JsonSyncDataMessage(syncMessage.getSent().get());
this.sentMessage = new JsonSyncDataMessage(syncMessage.getSent().get(), m);
}
if (syncMessage.getBlockedList().isPresent()) {
this.blockedNumbers = new ArrayList<>(syncMessage.getBlockedList().get().getAddresses().size());