Include source name in JSON output (#663)

* add sourceName

* avoid sourceName might not have been initialized

* catch NullPointerException instead of checking for null

* Update JsonMessageEnvelope.java

Co-authored-by: AsamK <asamk@gmx.de>
Fixes #663
This commit is contained in:
technillogue 2021-07-23 11:19:09 -04:00 committed by GitHub
parent dedbafb99a
commit 8cc4877627
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@ import org.asamk.Signal;
import org.asamk.signal.manager.Manager; 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.util.InvalidNumberException;
import java.util.List; import java.util.List;
@ -17,6 +18,9 @@ public class JsonMessageEnvelope {
@JsonProperty @JsonProperty
final String source; final String source;
@JsonProperty
final String sourceName;
@JsonProperty @JsonProperty
final Integer sourceDevice; final Integer sourceDevice;
@ -62,6 +66,13 @@ public class JsonMessageEnvelope {
this.sourceDevice = null; this.sourceDevice = null;
this.relay = null; this.relay = null;
} }
String name;
try {
name = m.getContactOrProfileName(this.source);
} catch (InvalidNumberException | NullPointerException e) {
name = null;
}
this.sourceName = name;
this.timestamp = envelope.getTimestamp(); this.timestamp = envelope.getTimestamp();
if (envelope.isReceipt()) { if (envelope.isReceipt()) {
this.receiptMessage = JsonReceiptMessage.deliveryReceipt(timestamp, List.of(timestamp)); this.receiptMessage = JsonReceiptMessage.deliveryReceipt(timestamp, List.of(timestamp));
@ -87,6 +98,7 @@ public class JsonMessageEnvelope {
public JsonMessageEnvelope(Signal.MessageReceived messageReceived) { public JsonMessageEnvelope(Signal.MessageReceived messageReceived) {
source = messageReceived.getSender(); source = messageReceived.getSender();
sourceName = null;
sourceDevice = null; sourceDevice = null;
relay = null; relay = null;
timestamp = messageReceived.getTimestamp(); timestamp = messageReceived.getTimestamp();
@ -99,6 +111,7 @@ public class JsonMessageEnvelope {
public JsonMessageEnvelope(Signal.ReceiptReceived receiptReceived) { public JsonMessageEnvelope(Signal.ReceiptReceived receiptReceived) {
source = receiptReceived.getSender(); source = receiptReceived.getSender();
sourceName = null;
sourceDevice = null; sourceDevice = null;
relay = null; relay = null;
timestamp = receiptReceived.getTimestamp(); timestamp = receiptReceived.getTimestamp();
@ -111,6 +124,7 @@ public class JsonMessageEnvelope {
public JsonMessageEnvelope(Signal.SyncMessageReceived messageReceived) { public JsonMessageEnvelope(Signal.SyncMessageReceived messageReceived) {
source = messageReceived.getSource(); source = messageReceived.getSource();
sourceName = null;
sourceDevice = null; sourceDevice = null;
relay = null; relay = null;
timestamp = messageReceived.getTimestamp(); timestamp = messageReceived.getTimestamp();