mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +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
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
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;
|
||||
|
||||
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());
|
||||
|
|
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;
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue