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.SignalServiceReceiptMessage;
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage; import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage; import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -34,22 +35,23 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
conn.sendMessage(new Signal.ReceiptReceived( conn.sendMessage(new Signal.ReceiptReceived(
objectPath, objectPath,
envelope.getTimestamp(), 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) { } catch (DBusException e) {
e.printStackTrace(); e.printStackTrace();
} }
} else if (content != null) { } else if (content != null) {
final SignalServiceAddress sender = !envelope.isUnidentifiedSender() && envelope.hasSource() ? envelope.getSourceAddress() : content.getSender();
if (content.getReceiptMessage().isPresent()) { if (content.getReceiptMessage().isPresent()) {
final SignalServiceReceiptMessage receiptMessage = content.getReceiptMessage().get(); final SignalServiceReceiptMessage receiptMessage = content.getReceiptMessage().get();
if (receiptMessage.isDeliveryReceipt()) { if (receiptMessage.isDeliveryReceipt()) {
final String sender = !envelope.isUnidentifiedSender() && envelope.hasSource() ? envelope.getSourceE164().get() : content.getSender().getNumber().get();
for (long timestamp : receiptMessage.getTimestamps()) { for (long timestamp : receiptMessage.getTimestamps()) {
try { try {
conn.sendMessage(new Signal.ReceiptReceived( conn.sendMessage(new Signal.ReceiptReceived(
objectPath, objectPath,
timestamp, timestamp,
sender sender.getLegacyIdentifier()
)); ));
} catch (DBusException e) { } catch (DBusException e) {
e.printStackTrace(); e.printStackTrace();
@ -66,7 +68,7 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
conn.sendMessage(new Signal.MessageReceived( conn.sendMessage(new Signal.MessageReceived(
objectPath, objectPath,
message.getTimestamp(), 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().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()
? message.getGroupContext().get().getGroupV1().get().getGroupId() : new byte[0], ? message.getGroupContext().get().getGroupV1().get().getGroupId() : new byte[0],
message.getBody().isPresent() ? message.getBody().get() : "", message.getBody().isPresent() ? message.getBody().get() : "",
@ -80,15 +82,15 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
if (sync_message.getSent().isPresent()) { if (sync_message.getSent().isPresent()) {
SentTranscriptMessage transcript = sync_message.getSent().get(); 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(); SignalServiceDataMessage message = transcript.getMessage();
try { try {
conn.sendMessage(new Signal.SyncMessageReceived( conn.sendMessage(new Signal.SyncMessageReceived(
objectPath, objectPath,
transcript.getTimestamp(), transcript.getTimestamp(),
envelope.getSourceAddress().getNumber().get(), sender.getLegacyIdentifier(),
transcript.getDestination().isPresent() ? transcript.getDestination().get().getNumber().get() : "", transcript.getDestination().isPresent() ? transcript.getDestination().get().getLegacyIdentifier() : "",
message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent() message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()
? message.getGroupContext().get().getGroupV1().get().getGroupId() : new byte[0], ? message.getGroupContext().get().getGroupV1().get().getGroupId() : new byte[0],
message.getBody().isPresent() ? message.getBody().get() : "", 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) { public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) { if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
SignalServiceAddress source = envelope.getSourceAddress(); SignalServiceAddress source = envelope.getSourceAddress();
ContactInfo sourceContact = m.getContact(source.getNumber().get()); ContactInfo sourceContact = m.getContact(source.getLegacyIdentifier());
System.out.println(String.format("Envelope from: %s (device: %d)", (sourceContact == null ? "" : "" + sourceContact.name + "") + source.getNumber().get(), envelope.getSourceDevice())); System.out.println(String.format("Envelope from: %s (device: %d)", (sourceContact == null ? "" : "" + sourceContact.name + "") + source.getLegacyIdentifier(), envelope.getSourceDevice()));
if (source.getRelay().isPresent()) { if (source.getRelay().isPresent()) {
System.out.println("Relayed by: " + source.getRelay().get()); System.out.println("Relayed by: " + source.getRelay().get());
} }
@ -76,8 +76,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (content == null) { if (content == null) {
System.out.println("Failed to decrypt message."); System.out.println("Failed to decrypt message.");
} else { } else {
ContactInfo sourceContact = m.getContact(content.getSender().getNumber().get()); ContactInfo sourceContact = m.getContact(content.getSender().getLegacyIdentifier());
System.out.println(String.format("Sender: %s (device: %d)", (sourceContact == null ? "" : "" + sourceContact.name + "") + content.getSender().getNumber().get(), content.getSenderDevice())); System.out.println(String.format("Sender: %s (device: %d)", (sourceContact == null ? "" : "" + sourceContact.name + "") + content.getSender().getLegacyIdentifier(), content.getSenderDevice()));
if (content.getDataMessage().isPresent()) { if (content.getDataMessage().isPresent()) {
SignalServiceDataMessage message = content.getDataMessage().get(); SignalServiceDataMessage message = content.getDataMessage().get();
handleSignalServiceDataMessage(message); handleSignalServiceDataMessage(message);
@ -102,8 +102,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (syncMessage.getRead().isPresent()) { if (syncMessage.getRead().isPresent()) {
System.out.println("Received sync read messages list"); System.out.println("Received sync read messages list");
for (ReadMessage rm : syncMessage.getRead().get()) { for (ReadMessage rm : syncMessage.getRead().get()) {
ContactInfo fromContact = m.getContact(rm.getSender().getNumber().get()); ContactInfo fromContact = m.getContact(rm.getSender().getLegacyIdentifier());
System.out.println("From: " + (fromContact == null ? "" : "" + fromContact.name + "") + rm.getSender().getNumber().get() + " Message timestamp: " + DateUtils.formatTimestamp(rm.getTimestamp())); System.out.println("From: " + (fromContact == null ? "" : "" + fromContact.name + "") + rm.getSender().getLegacyIdentifier() + " Message timestamp: " + DateUtils.formatTimestamp(rm.getTimestamp()));
} }
} }
if (syncMessage.getRequest().isPresent()) { if (syncMessage.getRequest().isPresent()) {
@ -129,14 +129,14 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
final SentTranscriptMessage sentTranscriptMessage = syncMessage.getSent().get(); final SentTranscriptMessage sentTranscriptMessage = syncMessage.getSent().get();
String to; String to;
if (sentTranscriptMessage.getDestination().isPresent()) { if (sentTranscriptMessage.getDestination().isPresent()) {
String dest = sentTranscriptMessage.getDestination().get().getNumber().get(); String dest = sentTranscriptMessage.getDestination().get().getLegacyIdentifier();
ContactInfo destContact = m.getContact(dest); ContactInfo destContact = m.getContact(dest);
to = (destContact == null ? "" : "" + destContact.name + "") + dest; to = (destContact == null ? "" : "" + destContact.name + "") + dest;
} else if (sentTranscriptMessage.getRecipients().size() > 0) { } else if (sentTranscriptMessage.getRecipients().size() > 0) {
StringBuilder toBuilder = new StringBuilder(); StringBuilder toBuilder = new StringBuilder();
for (SignalServiceAddress dest : sentTranscriptMessage.getRecipients()) { for (SignalServiceAddress dest : sentTranscriptMessage.getRecipients()) {
ContactInfo destContact = m.getContact(dest.getNumber().get()); ContactInfo destContact = m.getContact(dest.getLegacyIdentifier());
toBuilder.append(destContact == null ? "" : "" + destContact.name + "").append(dest.getNumber().get()).append(" "); toBuilder.append(destContact == null ? "" : "" + destContact.name + "").append(dest.getLegacyIdentifier()).append(" ");
} }
to = toBuilder.toString(); to = toBuilder.toString();
} else { } else {
@ -154,7 +154,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
System.out.println("Blocked numbers:"); System.out.println("Blocked numbers:");
final BlockedListMessage blockedList = syncMessage.getBlockedList().get(); final BlockedListMessage blockedList = syncMessage.getBlockedList().get();
for (SignalServiceAddress address : blockedList.getAddresses()) { for (SignalServiceAddress address : blockedList.getAddresses()) {
System.out.println(" - " + address.getNumber().get()); System.out.println(" - " + address.getLegacyIdentifier());
} }
} }
if (syncMessage.getVerified().isPresent()) { if (syncMessage.getVerified().isPresent()) {
@ -178,7 +178,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (syncMessage.getViewOnceOpen().isPresent()) { if (syncMessage.getViewOnceOpen().isPresent()) {
final ViewOnceOpenMessage viewOnceOpenMessage = syncMessage.getViewOnceOpen().get(); final ViewOnceOpenMessage viewOnceOpenMessage = syncMessage.getViewOnceOpen().get();
System.out.println("Received sync message with view once open message:"); 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()); System.out.println(" - Timestamp:" + viewOnceOpenMessage.getTimestamp());
} }
if (syncMessage.getStickerPackOperations().isPresent()) { if (syncMessage.getStickerPackOperations().isPresent()) {
@ -280,7 +280,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
System.out.println(" Type: " + groupInfo.getType()); System.out.println(" Type: " + groupInfo.getType());
if (groupInfo.getMembers().isPresent()) { if (groupInfo.getMembers().isPresent()) {
for (SignalServiceAddress member : groupInfo.getMembers().get()) { for (SignalServiceAddress member : groupInfo.getMembers().get()) {
System.out.println(" Member: " + member.getNumber().get()); System.out.println(" Member: " + member.getLegacyIdentifier());
} }
} }
if (groupInfo.getAvatar().isPresent()) { if (groupInfo.getAvatar().isPresent()) {
@ -332,7 +332,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
final SignalServiceDataMessage.Reaction reaction = message.getReaction().get(); final SignalServiceDataMessage.Reaction reaction = message.getReaction().get();
System.out.println("Reaction:"); System.out.println("Reaction:");
System.out.println(" - Emoji: " + reaction.getEmoji()); 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(" - Target timestamp: " + reaction.getTargetSentTimestamp());
System.out.println(" - Is remove: " + reaction.isRemove()); System.out.println(" - Is remove: " + reaction.isRemove());
} }
@ -340,7 +340,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (message.getQuote().isPresent()) { if (message.getQuote().isPresent()) {
SignalServiceDataMessage.Quote quote = message.getQuote().get(); SignalServiceDataMessage.Quote quote = message.getQuote().get();
System.out.println("Quote: (" + quote.getId() + ")"); 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()); System.out.println(" Text: " + quote.getText());
if (quote.getAttachments().size() > 0) { if (quote.getAttachments().size() > 0) {
System.out.println(" Attachments: "); System.out.println(" Attachments: ");

View file

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

View file

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

View file

@ -10,7 +10,7 @@ class JsonSyncDataMessage extends JsonDataMessage {
JsonSyncDataMessage(SentTranscriptMessage transcriptMessage) { JsonSyncDataMessage(SentTranscriptMessage transcriptMessage) {
super(transcriptMessage.getMessage()); super(transcriptMessage.getMessage());
if (transcriptMessage.getDestination().isPresent()) { 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()) { if (syncMessage.getBlockedList().isPresent()) {
this.blockedNumbers = new ArrayList<>(syncMessage.getBlockedList().get().getAddresses().size()); this.blockedNumbers = new ArrayList<>(syncMessage.getBlockedList().get().getAddresses().size());
for (SignalServiceAddress address : syncMessage.getBlockedList().get().getAddresses()) { for (SignalServiceAddress address : syncMessage.getBlockedList().get().getAddresses()) {
this.blockedNumbers.add(address.getNumber().get()); this.blockedNumbers.add(address.getLegacyIdentifier());
} }
} }
if (syncMessage.getRead().isPresent()) { if (syncMessage.getRead().isPresent()) {

View file

@ -1510,7 +1510,8 @@ public class Manager implements Closeable {
if (!(exception instanceof org.whispersystems.libsignal.UntrustedIdentityException)) { if (!(exception instanceof org.whispersystems.libsignal.UntrustedIdentityException)) {
File cacheFile = null; File cacheFile = null;
try { 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()); Files.delete(cacheFile.toPath());
// Try to delete directory if empty // Try to delete directory if empty
new File(getMessageCachePath()).delete(); new File(getMessageCachePath()).delete();