Fix behavior for recipients with only UUIDs

Fixes #359
This commit is contained in:
AsamK 2020-10-11 10:41:56 +02:00
parent ae39d6a085
commit a54fc92c05
7 changed files with 30 additions and 27 deletions

View file

@ -12,6 +12,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.ArrayList;
import java.util.List;
@ -34,22 +35,23 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
conn.sendMessage(new Signal.ReceiptReceived(
objectPath,
envelope.getTimestamp(),
!envelope.isUnidentifiedSender() && envelope.hasSource() ? envelope.getSourceE164().get() : content.getSender().getNumber().get()
// A receipt envelope always has a source address
envelope.getSourceAddress().getLegacyIdentifier()
));
} catch (DBusException e) {
e.printStackTrace();
}
} else if (content != null) {
final SignalServiceAddress sender = !envelope.isUnidentifiedSender() && envelope.hasSource() ? envelope.getSourceAddress() : content.getSender();
if (content.getReceiptMessage().isPresent()) {
final SignalServiceReceiptMessage receiptMessage = content.getReceiptMessage().get();
if (receiptMessage.isDeliveryReceipt()) {
final String sender = !envelope.isUnidentifiedSender() && envelope.hasSource() ? envelope.getSourceE164().get() : content.getSender().getNumber().get();
for (long timestamp : receiptMessage.getTimestamps()) {
try {
conn.sendMessage(new Signal.ReceiptReceived(
objectPath,
timestamp,
sender
sender.getLegacyIdentifier()
));
} catch (DBusException e) {
e.printStackTrace();
@ -66,7 +68,7 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
conn.sendMessage(new Signal.MessageReceived(
objectPath,
message.getTimestamp(),
envelope.isUnidentifiedSender() || !envelope.hasSource() ? content.getSender().getNumber().get() : envelope.getSourceE164().get(),
sender.getLegacyIdentifier(),
message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()
? message.getGroupContext().get().getGroupV1().get().getGroupId() : new byte[0],
message.getBody().isPresent() ? message.getBody().get() : "",
@ -80,15 +82,15 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
if (sync_message.getSent().isPresent()) {
SentTranscriptMessage transcript = sync_message.getSent().get();
if (!envelope.isUnidentifiedSender() && envelope.hasSource() && (transcript.getDestination().isPresent() || transcript.getMessage().getGroupContext().isPresent())) {
if (transcript.getDestination().isPresent() || transcript.getMessage().getGroupContext().isPresent()) {
SignalServiceDataMessage message = transcript.getMessage();
try {
conn.sendMessage(new Signal.SyncMessageReceived(
objectPath,
transcript.getTimestamp(),
envelope.getSourceAddress().getNumber().get(),
transcript.getDestination().isPresent() ? transcript.getDestination().get().getNumber().get() : "",
sender.getLegacyIdentifier(),
transcript.getDestination().isPresent() ? transcript.getDestination().get().getLegacyIdentifier() : "",
message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()
? message.getGroupContext().get().getGroupV1().get().getGroupId() : new byte[0],
message.getBody().isPresent() ? message.getBody().get() : "",

View file

@ -47,8 +47,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
SignalServiceAddress source = envelope.getSourceAddress();
ContactInfo sourceContact = m.getContact(source.getNumber().get());
System.out.println(String.format("Envelope from: %s (device: %d)", (sourceContact == null ? "" : "" + sourceContact.name + "") + source.getNumber().get(), envelope.getSourceDevice()));
ContactInfo sourceContact = m.getContact(source.getLegacyIdentifier());
System.out.println(String.format("Envelope from: %s (device: %d)", (sourceContact == null ? "" : "" + sourceContact.name + "") + source.getLegacyIdentifier(), envelope.getSourceDevice()));
if (source.getRelay().isPresent()) {
System.out.println("Relayed by: " + source.getRelay().get());
}
@ -76,8 +76,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (content == null) {
System.out.println("Failed to decrypt message.");
} else {
ContactInfo sourceContact = m.getContact(content.getSender().getNumber().get());
System.out.println(String.format("Sender: %s (device: %d)", (sourceContact == null ? "" : "" + sourceContact.name + "") + content.getSender().getNumber().get(), content.getSenderDevice()));
ContactInfo sourceContact = m.getContact(content.getSender().getLegacyIdentifier());
System.out.println(String.format("Sender: %s (device: %d)", (sourceContact == null ? "" : "" + sourceContact.name + "") + content.getSender().getLegacyIdentifier(), content.getSenderDevice()));
if (content.getDataMessage().isPresent()) {
SignalServiceDataMessage message = content.getDataMessage().get();
handleSignalServiceDataMessage(message);
@ -102,8 +102,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (syncMessage.getRead().isPresent()) {
System.out.println("Received sync read messages list");
for (ReadMessage rm : syncMessage.getRead().get()) {
ContactInfo fromContact = m.getContact(rm.getSender().getNumber().get());
System.out.println("From: " + (fromContact == null ? "" : "" + fromContact.name + "") + rm.getSender().getNumber().get() + " Message timestamp: " + DateUtils.formatTimestamp(rm.getTimestamp()));
ContactInfo fromContact = m.getContact(rm.getSender().getLegacyIdentifier());
System.out.println("From: " + (fromContact == null ? "" : "" + fromContact.name + "") + rm.getSender().getLegacyIdentifier() + " Message timestamp: " + DateUtils.formatTimestamp(rm.getTimestamp()));
}
}
if (syncMessage.getRequest().isPresent()) {
@ -129,14 +129,14 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
final SentTranscriptMessage sentTranscriptMessage = syncMessage.getSent().get();
String to;
if (sentTranscriptMessage.getDestination().isPresent()) {
String dest = sentTranscriptMessage.getDestination().get().getNumber().get();
String dest = sentTranscriptMessage.getDestination().get().getLegacyIdentifier();
ContactInfo destContact = m.getContact(dest);
to = (destContact == null ? "" : "" + destContact.name + "") + dest;
} else if (sentTranscriptMessage.getRecipients().size() > 0) {
StringBuilder toBuilder = new StringBuilder();
for (SignalServiceAddress dest : sentTranscriptMessage.getRecipients()) {
ContactInfo destContact = m.getContact(dest.getNumber().get());
toBuilder.append(destContact == null ? "" : "" + destContact.name + "").append(dest.getNumber().get()).append(" ");
ContactInfo destContact = m.getContact(dest.getLegacyIdentifier());
toBuilder.append(destContact == null ? "" : "" + destContact.name + "").append(dest.getLegacyIdentifier()).append(" ");
}
to = toBuilder.toString();
} else {
@ -154,7 +154,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
System.out.println("Blocked numbers:");
final BlockedListMessage blockedList = syncMessage.getBlockedList().get();
for (SignalServiceAddress address : blockedList.getAddresses()) {
System.out.println(" - " + address.getNumber().get());
System.out.println(" - " + address.getLegacyIdentifier());
}
}
if (syncMessage.getVerified().isPresent()) {
@ -178,7 +178,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (syncMessage.getViewOnceOpen().isPresent()) {
final ViewOnceOpenMessage viewOnceOpenMessage = syncMessage.getViewOnceOpen().get();
System.out.println("Received sync message with view once open message:");
System.out.println(" - Sender:" + viewOnceOpenMessage.getSender().getNumber().get());
System.out.println(" - Sender:" + viewOnceOpenMessage.getSender().getLegacyIdentifier());
System.out.println(" - Timestamp:" + viewOnceOpenMessage.getTimestamp());
}
if (syncMessage.getStickerPackOperations().isPresent()) {
@ -280,7 +280,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
System.out.println(" Type: " + groupInfo.getType());
if (groupInfo.getMembers().isPresent()) {
for (SignalServiceAddress member : groupInfo.getMembers().get()) {
System.out.println(" Member: " + member.getNumber().get());
System.out.println(" Member: " + member.getLegacyIdentifier());
}
}
if (groupInfo.getAvatar().isPresent()) {
@ -332,7 +332,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
final SignalServiceDataMessage.Reaction reaction = message.getReaction().get();
System.out.println("Reaction:");
System.out.println(" - Emoji: " + reaction.getEmoji());
System.out.println(" - Target author: " + reaction.getTargetAuthor().getNumber().get());
System.out.println(" - Target author: " + reaction.getTargetAuthor().getLegacyIdentifier());
System.out.println(" - Target timestamp: " + reaction.getTargetSentTimestamp());
System.out.println(" - Is remove: " + reaction.isRemove());
}
@ -340,7 +340,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (message.getQuote().isPresent()) {
SignalServiceDataMessage.Quote quote = message.getQuote().get();
System.out.println("Quote: (" + quote.getId() + ")");
System.out.println(" Author: " + quote.getAuthor().getNumber().get());
System.out.println(" Author: " + quote.getAuthor().getLegacyIdentifier());
System.out.println(" Text: " + quote.getText());
if (quote.getAttachments().size() > 0) {
System.out.println(" Attachments: ");

View file

@ -19,7 +19,7 @@ class JsonGroupInfo {
if (groupInfo.getMembers().isPresent()) {
this.members = new ArrayList<>(groupInfo.getMembers().get().size());
for (SignalServiceAddress address : groupInfo.getMembers().get()) {
this.members.add(address.getNumber().get());
this.members.add(address.getLegacyIdentifier());
}
}
if (groupInfo.getName().isPresent()) {

View file

@ -20,7 +20,7 @@ public class JsonMessageEnvelope {
public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content) {
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
SignalServiceAddress source = envelope.getSourceAddress();
this.source = source.getNumber().get();
this.source = source.getLegacyIdentifier();
this.relay = source.getRelay().isPresent() ? source.getRelay().get() : null;
}
this.sourceDevice = envelope.getSourceDevice();
@ -28,7 +28,7 @@ public class JsonMessageEnvelope {
this.isReceipt = envelope.isReceipt();
if (content != null) {
if (envelope.isUnidentifiedSender()) {
this.source = content.getSender().getNumber().get();
this.source = content.getSender().getLegacyIdentifier();
this.sourceDevice = content.getSenderDevice();
}
if (content.getDataMessage().isPresent()) {

View file

@ -10,7 +10,7 @@ class JsonSyncDataMessage extends JsonDataMessage {
JsonSyncDataMessage(SentTranscriptMessage transcriptMessage) {
super(transcriptMessage.getMessage());
if (transcriptMessage.getDestination().isPresent()) {
this.destination = transcriptMessage.getDestination().get().getNumber().get();
this.destination = transcriptMessage.getDestination().get().getLegacyIdentifier();
}
}

View file

@ -28,7 +28,7 @@ class JsonSyncMessage {
if (syncMessage.getBlockedList().isPresent()) {
this.blockedNumbers = new ArrayList<>(syncMessage.getBlockedList().get().getAddresses().size());
for (SignalServiceAddress address : syncMessage.getBlockedList().get().getAddresses()) {
this.blockedNumbers.add(address.getNumber().get());
this.blockedNumbers.add(address.getLegacyIdentifier());
}
}
if (syncMessage.getRead().isPresent()) {

View file

@ -1510,7 +1510,8 @@ public class Manager implements Closeable {
if (!(exception instanceof org.whispersystems.libsignal.UntrustedIdentityException)) {
File cacheFile = null;
try {
cacheFile = getMessageCacheFile(envelope.getSourceE164().get(), now, envelope.getTimestamp());
String source = envelope.getSourceE164().isPresent() ? envelope.getSourceE164().get() : "";
cacheFile = getMessageCacheFile(source, now, envelope.getTimestamp());
Files.delete(cacheFile.toPath());
// Try to delete directory if empty
new File(getMessageCachePath()).delete();