mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Improve receiving unidentified messages
This commit is contained in:
parent
90b752b912
commit
8ad9c9b0ff
2 changed files with 8 additions and 13 deletions
|
@ -20,14 +20,14 @@ class JsonMessageEnvelope {
|
|||
SignalServiceAddress source = envelope.getSourceAddress();
|
||||
this.source = source.getNumber();
|
||||
this.sourceDevice = envelope.getSourceDevice();
|
||||
if (this.source.equals("")) {
|
||||
this.source = content.getSender();
|
||||
this.sourceDevice = content.getSenderDevice();
|
||||
}
|
||||
this.relay = source.getRelay().isPresent() ? source.getRelay().get() : null;
|
||||
this.timestamp = envelope.getTimestamp();
|
||||
this.isReceipt = envelope.isReceipt();
|
||||
if (content != null) {
|
||||
if (envelope.isUnidentifiedSender()) {
|
||||
this.source = content.getSender();
|
||||
this.sourceDevice = content.getSenderDevice();
|
||||
}
|
||||
if (content.getDataMessage().isPresent()) {
|
||||
this.dataMessage = new JsonDataMessage(content.getDataMessage().get());
|
||||
}
|
||||
|
|
|
@ -43,14 +43,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
@Override
|
||||
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
|
||||
SignalServiceAddress source = envelope.getSourceAddress();
|
||||
String sender = source.getNumber();
|
||||
int senderDeviceId = envelope.getSourceDevice();
|
||||
if (sender.equals("")) {
|
||||
sender = content.getSender();
|
||||
senderDeviceId = content.getSenderDevice();
|
||||
}
|
||||
ContactInfo sourceContact = m.getContact(sender);
|
||||
System.out.println(String.format("Envelope from: %s (device: %d)", (sourceContact == null ? "" : "“" + sourceContact.name + "” ") + sender, senderDeviceId));
|
||||
ContactInfo sourceContact = m.getContact(source.getNumber());
|
||||
System.out.println(String.format("Envelope from: %s (device: %d)", (sourceContact == null ? "" : "“" + sourceContact.name + "” ") + source.getNumber(), envelope.getSourceDevice()));
|
||||
if (source.getRelay().isPresent()) {
|
||||
System.out.println("Relayed by: " + source.getRelay().get());
|
||||
}
|
||||
|
@ -61,7 +55,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
|
||||
if (envelope.isReceipt()) {
|
||||
System.out.println("Got receipt.");
|
||||
} else if (envelope.isSignalMessage() | envelope.isPreKeySignalMessage()) {
|
||||
} else if (envelope.isSignalMessage() || envelope.isPreKeySignalMessage() || envelope.isUnidentifiedSender()) {
|
||||
if (exception != null) {
|
||||
if (exception instanceof org.whispersystems.libsignal.UntrustedIdentityException) {
|
||||
org.whispersystems.libsignal.UntrustedIdentityException e = (org.whispersystems.libsignal.UntrustedIdentityException) exception;
|
||||
|
@ -75,6 +69,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
if (content == null) {
|
||||
System.out.println("Failed to decrypt message.");
|
||||
} else {
|
||||
System.out.println(String.format("Sender: %s (device: %d)", content.getSender(), content.getSenderDevice()));
|
||||
if (content.getDataMessage().isPresent()) {
|
||||
SignalServiceDataMessage message = content.getDataMessage().get();
|
||||
handleSignalServiceDataMessage(message);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue