mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
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:
parent
548c313b4c
commit
58db3cbd53
10 changed files with 162 additions and 19 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);
|
||||||
|
|
|
@ -447,8 +447,14 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
if (message.getQuote().isPresent()) {
|
if (message.getQuote().isPresent()) {
|
||||||
SignalServiceDataMessage.Quote quote = message.getQuote().get();
|
SignalServiceDataMessage.Quote quote = message.getQuote().get();
|
||||||
System.out.println("Quote: (" + quote.getId() + ")");
|
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());
|
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) {
|
if (quote.getAttachments().size() > 0) {
|
||||||
System.out.println(" Attachments: ");
|
System.out.println(" Attachments: ");
|
||||||
for (SignalServiceDataMessage.Quote.QuotedAttachment attachment : quote.getAttachments()) {
|
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());
|
System.out.println("Remote delete message: timestamp = " + remoteDelete.getTargetSentTimestamp());
|
||||||
}
|
}
|
||||||
if (message.getMentions().isPresent()) {
|
if (message.getMentions().isPresent()) {
|
||||||
final List<SignalServiceDataMessage.Mention> mentions = message.getMentions().get();
|
|
||||||
System.out.println("Mentions: ");
|
System.out.println("Mentions: ");
|
||||||
for (SignalServiceDataMessage.Mention mention : mentions) {
|
for (SignalServiceDataMessage.Mention mention : message.getMentions().get()) {
|
||||||
System.out.println("- "
|
printMention(mention, m);
|
||||||
+ mention.getUuid()
|
|
||||||
+ ": "
|
|
||||||
+ mention.getStart()
|
|
||||||
+ " (length: "
|
|
||||||
+ mention.getLength()
|
|
||||||
+ ")");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
private void printAttachment(SignalServiceAttachment attachment) {
|
||||||
System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (
|
System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (
|
||||||
attachment.isStream() ? "Stream" : ""
|
attachment.isStream() ? "Stream" : ""
|
||||||
|
|
|
@ -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, 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,20 @@ class JsonDataMessage {
|
||||||
this.message = dataMessage.getBody().get();
|
this.message = dataMessage.getBody().get();
|
||||||
}
|
}
|
||||||
this.expiresInSeconds = dataMessage.getExpiresInSeconds();
|
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()) {
|
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 +66,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; // TODO Replace these 3 with the proper commands
|
||||||
|
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 +76,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; // TODO Replace these 3 with the proper commands
|
||||||
|
quote = null;
|
||||||
|
mentions = null;
|
||||||
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
|
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
22
src/main/java/org/asamk/signal/json/JsonMention.java
Normal file
22
src/main/java/org/asamk/signal/json/JsonMention.java
Normal 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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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,7 @@ public class JsonMessageEnvelope {
|
||||||
JsonCallMessage callMessage;
|
JsonCallMessage callMessage;
|
||||||
JsonReceiptMessage receiptMessage;
|
JsonReceiptMessage receiptMessage;
|
||||||
|
|
||||||
public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content) {
|
public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content, 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 +36,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());
|
||||||
|
|
42
src/main/java/org/asamk/signal/json/JsonQuote.java
Normal file
42
src/main/java/org/asamk/signal/json/JsonQuote.java
Normal 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<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
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, 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, 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, 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