Add typing message to json output

Fixes #423
This commit is contained in:
AsamK 2021-01-17 11:43:39 +01:00
parent 5a2c4b8dfd
commit 3b29add396
2 changed files with 38 additions and 0 deletions

View file

@ -41,6 +41,10 @@ public class JsonMessageEnvelope {
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
final JsonReceiptMessage receiptMessage; final JsonReceiptMessage receiptMessage;
@JsonProperty
@JsonInclude(JsonInclude.Include.NON_NULL)
final JsonTypingMessage typingMessage;
public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content, Manager m) { 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();
@ -64,6 +68,9 @@ public class JsonMessageEnvelope {
} else { } else {
this.receiptMessage = null; this.receiptMessage = null;
} }
this.typingMessage = content != null && content.getTypingMessage().isPresent()
? new JsonTypingMessage(content.getTypingMessage().get())
: null;
this.dataMessage = content != null && content.getDataMessage().isPresent() this.dataMessage = content != null && content.getDataMessage().isPresent()
? new JsonDataMessage(content.getDataMessage().get(), m) ? new JsonDataMessage(content.getDataMessage().get(), m)
@ -85,6 +92,7 @@ public class JsonMessageEnvelope {
dataMessage = new JsonDataMessage(messageReceived); dataMessage = new JsonDataMessage(messageReceived);
syncMessage = null; syncMessage = null;
callMessage = null; callMessage = null;
typingMessage = null;
} }
public JsonMessageEnvelope(Signal.ReceiptReceived receiptReceived) { public JsonMessageEnvelope(Signal.ReceiptReceived receiptReceived) {
@ -96,6 +104,7 @@ public class JsonMessageEnvelope {
dataMessage = null; dataMessage = null;
syncMessage = null; syncMessage = null;
callMessage = null; callMessage = null;
typingMessage = null;
} }
public JsonMessageEnvelope(Signal.SyncMessageReceived messageReceived) { public JsonMessageEnvelope(Signal.SyncMessageReceived messageReceived) {
@ -107,5 +116,6 @@ public class JsonMessageEnvelope {
dataMessage = null; dataMessage = null;
syncMessage = new JsonSyncMessage(messageReceived); syncMessage = new JsonSyncMessage(messageReceived);
callMessage = null; callMessage = null;
typingMessage = null;
} }
} }

View file

@ -0,0 +1,28 @@
package org.asamk.signal.json;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
import java.util.Base64;
class JsonTypingMessage {
@JsonProperty
final String action;
@JsonProperty
final long timestamp;
@JsonProperty
@JsonInclude(JsonInclude.Include.NON_NULL)
final String groupId;
JsonTypingMessage(SignalServiceTypingMessage typingMessage) {
this.action = typingMessage.getAction().name();
this.timestamp = typingMessage.getTimestamp();
final Base64.Encoder encoder = Base64.getEncoder();
this.groupId = typingMessage.getGroupId().transform(encoder::encodeToString).orNull();
}
}