mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-24 03:35:58 +00:00
Prefer ServiceIds over SignalServiceAddresses.
This commit is contained in:
committed by
Alex Hart
parent
6d4dadea48
commit
3beb730edb
@@ -111,7 +111,7 @@ public class MultiDeviceMessageRequestResponseJob extends BaseJob {
|
||||
if (recipient.isGroup()) {
|
||||
response = MessageRequestResponseMessage.forGroup(recipient.getGroupId().get().getDecodedId(), localToRemoteType(type));
|
||||
} else if (recipient.isMaybeRegistered()) {
|
||||
response = MessageRequestResponseMessage.forIndividual(RecipientUtil.toSignalServiceAddress(context, recipient), localToRemoteType(type));
|
||||
response = MessageRequestResponseMessage.forIndividual(RecipientUtil.getOrFetchServiceId(context, recipient), localToRemoteType(type));
|
||||
} else {
|
||||
response = null;
|
||||
}
|
||||
|
||||
@@ -15,9 +15,11 @@ import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
||||
import org.thoughtcrime.securesms.net.NotPushRegisteredException;
|
||||
import org.thoughtcrime.securesms.payments.proto.PaymentMetaData;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.OutgoingPaymentMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException;
|
||||
@@ -89,9 +91,9 @@ public final class MultiDeviceOutgoingPaymentSyncJob extends BaseJob {
|
||||
|
||||
boolean defrag = payment.isDefrag();
|
||||
|
||||
Optional<SignalServiceAddress> uuid;
|
||||
Optional<ServiceId> uuid;
|
||||
if (!defrag && payment.getPayee().hasRecipientId()) {
|
||||
uuid = Optional.of(new SignalServiceAddress(Recipient.resolved(payment.getPayee().requireRecipientId()).requireServiceId()));
|
||||
uuid = Optional.of(RecipientUtil.getOrFetchServiceId(context, Recipient.resolved(payment.getPayee().requireRecipientId())));
|
||||
} else {
|
||||
uuid = Optional.empty();
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class MultiDeviceReadUpdateJob extends BaseJob {
|
||||
for (SerializableSyncMessageId messageId : messageIds) {
|
||||
Recipient recipient = Recipient.resolved(RecipientId.from(messageId.recipientId));
|
||||
if (!recipient.isGroup() && !recipient.isDistributionList() && recipient.isMaybeRegistered()) {
|
||||
readMessages.add(new ReadMessage(RecipientUtil.toSignalServiceAddress(context, recipient), messageId.timestamp));
|
||||
readMessages.add(new ReadMessage(RecipientUtil.getOrFetchServiceId(context, recipient), messageId.timestamp));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ public class MultiDeviceViewOnceOpenJob extends BaseJob {
|
||||
return;
|
||||
}
|
||||
|
||||
ViewOnceOpenMessage openMessage = new ViewOnceOpenMessage(RecipientUtil.toSignalServiceAddress(context, recipient), messageId.timestamp);
|
||||
ViewOnceOpenMessage openMessage = new ViewOnceOpenMessage(RecipientUtil.getOrFetchServiceId(context, recipient), messageId.timestamp);
|
||||
|
||||
messageSender.sendSyncMessage(SignalServiceSyncMessage.forViewOnceOpen(openMessage), UnidentifiedAccessUtil.getAccessForSync(context));
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class MultiDeviceViewedUpdateJob extends BaseJob {
|
||||
for (SerializableSyncMessageId messageId : messageIds) {
|
||||
Recipient recipient = Recipient.resolved(RecipientId.from(messageId.recipientId));
|
||||
if (!recipient.isGroup() && recipient.isMaybeRegistered()) {
|
||||
viewedMessages.add(new ViewedMessage(RecipientUtil.toSignalServiceAddress(context, recipient), messageId.timestamp));
|
||||
viewedMessages.add(new ViewedMessage(RecipientUtil.getOrFetchServiceId(context, recipient), messageId.timestamp));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -355,8 +355,7 @@ public abstract class PushSendJob extends SendJob {
|
||||
Recipient quoteAuthorRecipient = Recipient.resolved(quoteAuthor);
|
||||
|
||||
if (quoteAuthorRecipient.isMaybeRegistered()) {
|
||||
SignalServiceAddress quoteAddress = RecipientUtil.toSignalServiceAddress(context, quoteAuthorRecipient);
|
||||
return Optional.of(new SignalServiceDataMessage.Quote(quoteId, quoteAddress, quoteBody, quoteAttachments, quoteMentions, quoteType.getDataMessageType()));
|
||||
return Optional.of(new SignalServiceDataMessage.Quote(quoteId, RecipientUtil.getOrFetchServiceId(context, quoteAuthorRecipient), quoteBody, quoteAttachments, quoteMentions, quoteType.getDataMessageType()));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -386,10 +385,10 @@ public abstract class PushSendJob extends SendJob {
|
||||
|
||||
protected Optional<SignalServiceDataMessage.Reaction> getStoryReactionFor(@NonNull OutgoingMediaMessage message, @NonNull SignalServiceDataMessage.StoryContext storyContext) {
|
||||
if (message.isStoryReaction()) {
|
||||
return Optional.of(new SignalServiceDataMessage.Reaction(
|
||||
message.getBody(),
|
||||
false,
|
||||
new SignalServiceAddress(storyContext.getAuthorServiceId()), storyContext.getSentTimestamp()));
|
||||
return Optional.of(new SignalServiceDataMessage.Reaction(message.getBody(),
|
||||
false,
|
||||
storyContext.getAuthorServiceId(),
|
||||
storyContext.getSentTimestamp()));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ public class ReactionSendJob extends BaseJob {
|
||||
{
|
||||
return new SignalServiceDataMessage.Reaction(reaction.getEmoji(),
|
||||
remove,
|
||||
RecipientUtil.toSignalServiceAddress(context, targetAuthor),
|
||||
RecipientUtil.getOrFetchServiceId(context, targetAuthor),
|
||||
targetSentTimestamp);
|
||||
}
|
||||
|
||||
|
||||
@@ -2305,7 +2305,7 @@ public final class MessageContentProcessor {
|
||||
}
|
||||
|
||||
List<org.signal.libsignal.protocol.util.Pair<RecipientId, Boolean>> unidentifiedStatus = Stream.of(members)
|
||||
.map(m -> new org.signal.libsignal.protocol.util.Pair<>(m.getId(), message.isUnidentified(m.requireServiceId().toString())))
|
||||
.map(m -> new org.signal.libsignal.protocol.util.Pair<>(m.getId(), message.isUnidentified(m.requireServiceId())))
|
||||
.toList();
|
||||
receiptDatabase.setUnidentified(unidentifiedStatus, messageId);
|
||||
}
|
||||
@@ -3132,16 +3132,11 @@ public final class MessageContentProcessor {
|
||||
}
|
||||
|
||||
private static boolean isUnidentified(@NonNull SentTranscriptMessage message, @NonNull Recipient recipient) {
|
||||
boolean unidentified = false;
|
||||
|
||||
if (recipient.hasE164()) {
|
||||
unidentified |= message.isUnidentified(recipient.requireE164());
|
||||
}
|
||||
if (recipient.hasServiceId()) {
|
||||
unidentified |= message.isUnidentified(recipient.requireServiceId());
|
||||
return message.isUnidentified(recipient.requireServiceId());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return unidentified;
|
||||
}
|
||||
|
||||
private static void log(@NonNull String message) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage;
|
||||
import org.thoughtcrime.securesms.sms.MessageSender;
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NotFoundException;
|
||||
|
||||
@@ -39,6 +40,16 @@ public class RecipientUtil {
|
||||
|
||||
private static final String TAG = Log.tag(RecipientUtil.class);
|
||||
|
||||
/**
|
||||
* This method will do it's best to get a {@link ServiceId} for the provided recipient. This includes performing
|
||||
* a possible network request if no ServiceId is available. If the request to get a ServiceId fails or the user is
|
||||
* not registered, an IOException is thrown.
|
||||
*/
|
||||
@WorkerThread
|
||||
public static @NonNull ServiceId getOrFetchServiceId(@NonNull Context context, @NonNull Recipient recipient) throws IOException {
|
||||
return toSignalServiceAddress(context, recipient).getServiceId();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will do it's best to craft a fully-populated {@link SignalServiceAddress} based on
|
||||
* the provided recipient. This includes performing a possible network request if no UUID is
|
||||
|
||||
Reference in New Issue
Block a user