mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Improve source serviceId handling
This commit is contained in:
parent
81d2e315e3
commit
fcaecef961
5 changed files with 33 additions and 33 deletions
|
@ -32,6 +32,7 @@ import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptM
|
|||
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -904,8 +905,9 @@ public record MessageEnvelope(
|
|||
final AttachmentFileProvider fileProvider,
|
||||
Exception exception
|
||||
) {
|
||||
final var source = !envelope.isUnidentifiedSender() && envelope.hasSourceServiceId()
|
||||
? recipientResolver.resolveRecipient(envelope.getSourceAddress())
|
||||
final var serviceId = envelope.getSourceServiceId().map(ServiceId::parseOrNull).orElse(null);
|
||||
final var source = !envelope.isUnidentifiedSender() && serviceId != null
|
||||
? recipientResolver.resolveRecipient(serviceId)
|
||||
: envelope.isUnidentifiedSender() && content != null
|
||||
? recipientResolver.resolveRecipient(content.getSender())
|
||||
: exception instanceof ProtocolException e
|
||||
|
|
|
@ -131,15 +131,10 @@ public final class IncomingMessageHandler {
|
|||
final var actions = new ArrayList<HandleAction>();
|
||||
SignalServiceContent content = null;
|
||||
Exception exception = null;
|
||||
try {
|
||||
if (envelope.hasSourceServiceId()) {
|
||||
envelope.getSourceServiceId().map(ServiceId::parseOrNull)
|
||||
// Store uuid if we don't have it already
|
||||
// uuid in envelope is sent by server
|
||||
account.getRecipientTrustedResolver().resolveRecipientTrusted(envelope.getSourceAddress());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
exception = e;
|
||||
}
|
||||
.ifPresent(serviceId -> account.getRecipientResolver().resolveRecipient(serviceId));
|
||||
if (!envelope.isReceipt()) {
|
||||
try {
|
||||
final var cipherResult = dependencies.getCipher()
|
||||
|
@ -488,7 +483,7 @@ public final class IncomingMessageHandler {
|
|||
sender,
|
||||
destination == null
|
||||
? null
|
||||
: new DeviceAddress(context.getRecipientHelper().resolveRecipient(destination),
|
||||
: new DeviceAddress(account.getRecipientResolver().resolveRecipient(destination),
|
||||
destination.getServiceId(),
|
||||
0),
|
||||
ignoreAttachments));
|
||||
|
@ -530,7 +525,7 @@ public final class IncomingMessageHandler {
|
|||
final var blockedListMessage = syncMessage.getBlockedList().get();
|
||||
for (var address : blockedListMessage.getAddresses()) {
|
||||
context.getContactHelper()
|
||||
.setContactBlocked(context.getRecipientHelper().resolveRecipient(address), true);
|
||||
.setContactBlocked(account.getRecipientResolver().resolveRecipient(address), true);
|
||||
}
|
||||
for (var groupId : blockedListMessage.getGroupIds()
|
||||
.stream()
|
||||
|
@ -654,7 +649,7 @@ public final class IncomingMessageHandler {
|
|||
if (source == null) {
|
||||
return false;
|
||||
}
|
||||
final var recipientId = context.getRecipientHelper().resolveRecipient(source);
|
||||
final var recipientId = account.getRecipientResolver().resolveRecipient(source);
|
||||
if (context.getContactHelper().isContactBlocked(recipientId)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -694,7 +689,7 @@ public final class IncomingMessageHandler {
|
|||
|
||||
final var message = content.getDataMessage().orElse(null);
|
||||
|
||||
final var recipientId = context.getRecipientHelper().resolveRecipient(source);
|
||||
final var recipientId = account.getRecipientResolver().resolveRecipient(source);
|
||||
if (!group.isMember(recipientId) && !(
|
||||
group.isPendingMember(recipientId) && message != null && message.isGroupV2Update()
|
||||
)) {
|
||||
|
@ -745,10 +740,11 @@ public final class IncomingMessageHandler {
|
|||
}
|
||||
|
||||
if (groupInfo.getMembers().isPresent()) {
|
||||
final var recipientResolver = account.getRecipientResolver();
|
||||
groupV1.addMembers(groupInfo.getMembers()
|
||||
.get()
|
||||
.stream()
|
||||
.map(context.getRecipientHelper()::resolveRecipient)
|
||||
.map(recipientResolver::resolveRecipient)
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
|
@ -921,8 +917,9 @@ public final class IncomingMessageHandler {
|
|||
}
|
||||
|
||||
private SignalServiceAddress getSenderAddress(SignalServiceEnvelope envelope, SignalServiceContent content) {
|
||||
if (!envelope.isUnidentifiedSender() && envelope.hasSourceServiceId()) {
|
||||
return envelope.getSourceAddress();
|
||||
final var serviceId = envelope.getSourceServiceId().map(ServiceId::parseOrNull).orElse(null);
|
||||
if (!envelope.isUnidentifiedSender() && serviceId != null) {
|
||||
return new SignalServiceAddress(serviceId);
|
||||
} else if (content != null) {
|
||||
return content.getSender();
|
||||
} else {
|
||||
|
@ -931,12 +928,13 @@ public final class IncomingMessageHandler {
|
|||
}
|
||||
|
||||
private DeviceAddress getSender(SignalServiceEnvelope envelope, SignalServiceContent content) {
|
||||
if (!envelope.isUnidentifiedSender() && envelope.hasSourceServiceId()) {
|
||||
return new DeviceAddress(context.getRecipientHelper().resolveRecipient(envelope.getSourceAddress()),
|
||||
envelope.getSourceAddress().getServiceId(),
|
||||
final var serviceId = envelope.getSourceServiceId().map(ServiceId::parseOrNull).orElse(null);
|
||||
if (!envelope.isUnidentifiedSender() && serviceId != null) {
|
||||
return new DeviceAddress(account.getRecipientResolver().resolveRecipient(serviceId),
|
||||
serviceId,
|
||||
envelope.getSourceDevice());
|
||||
} else {
|
||||
return new DeviceAddress(context.getRecipientHelper().resolveRecipient(content.getSender()),
|
||||
return new DeviceAddress(account.getRecipientResolver().resolveRecipient(content.getSender()),
|
||||
content.getSender().getServiceId(),
|
||||
content.getSenderDevice());
|
||||
}
|
||||
|
@ -951,7 +949,7 @@ public final class IncomingMessageHandler {
|
|||
return new DeviceAddress(account.getSelfRecipientId(), account.getAci(), account.getDeviceId());
|
||||
}
|
||||
final var address = addressOptional.get();
|
||||
return new DeviceAddress(context.getRecipientHelper().resolveRecipient(address),
|
||||
return new DeviceAddress(account.getRecipientResolver().resolveRecipient(address),
|
||||
address.getServiceId(),
|
||||
account.getDeviceId());
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.signalservice.api.SignalWebSocket;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
|
||||
import org.whispersystems.signalservice.api.websocket.WebSocketConnectionState;
|
||||
import org.whispersystems.signalservice.api.websocket.WebSocketUnavailableException;
|
||||
|
@ -147,8 +148,10 @@ public class ReceiveHelper {
|
|||
for (final var it : batch) {
|
||||
SignalServiceEnvelope envelope1 = new SignalServiceEnvelope(it.getEnvelope(),
|
||||
it.getServerDeliveredTimestamp());
|
||||
final var recipientId = envelope1.hasSourceServiceId() ? account.getRecipientResolver()
|
||||
.resolveRecipient(envelope1.getSourceAddress()) : null;
|
||||
final var recipientId = envelope1.getSourceServiceId()
|
||||
.map(ServiceId::parseOrNull)
|
||||
.map(s -> account.getRecipientResolver().resolveRecipient(s))
|
||||
.orElse(null);
|
||||
logger.trace("Storing new message from {}", recipientId);
|
||||
// store message on disk, before acknowledging receipt to the server
|
||||
cachedMessage[0] = account.getMessageCache().cacheMessage(envelope1, recipientId);
|
||||
|
@ -230,7 +233,7 @@ public class ReceiveHelper {
|
|||
if (exception instanceof UntrustedIdentityException) {
|
||||
logger.debug("Keeping message with untrusted identity in message cache");
|
||||
final var address = ((UntrustedIdentityException) exception).getSender();
|
||||
if (!envelope.hasSourceServiceId() && address.uuid().isPresent()) {
|
||||
if (envelope.getSourceServiceId().isEmpty() && address.uuid().isPresent()) {
|
||||
final var recipientId = account.getRecipientResolver()
|
||||
.resolveRecipient(ACI.from(address.uuid().get()));
|
||||
try {
|
||||
|
@ -282,7 +285,7 @@ public class ReceiveHelper {
|
|||
cachedMessage.delete();
|
||||
return null;
|
||||
}
|
||||
if (!envelope.hasSourceServiceId()) {
|
||||
if (envelope.getSourceServiceId().isEmpty()) {
|
||||
final var identifier = ((UntrustedIdentityException) exception).getSender();
|
||||
final var recipientId = account.getRecipientResolver()
|
||||
.resolveRecipient(new RecipientAddress(identifier));
|
||||
|
|
|
@ -68,10 +68,6 @@ public class RecipientHelper {
|
|||
.toSignalServiceAddress();
|
||||
}
|
||||
|
||||
public RecipientId resolveRecipient(final SignalServiceAddress address) {
|
||||
return account.getRecipientResolver().resolveRecipient(address);
|
||||
}
|
||||
|
||||
public Set<RecipientId> resolveRecipients(Collection<RecipientIdentifier.Single> recipients) throws UnregisteredRecipientException {
|
||||
final var recipientIds = new HashSet<RecipientId>(recipients.size());
|
||||
for (var number : recipients) {
|
||||
|
|
|
@ -475,9 +475,10 @@ public class SendHelper {
|
|||
senderKeyTargets = Set.of();
|
||||
} else {
|
||||
results.stream().filter(SendMessageResult::isSuccess).forEach(allResults::add);
|
||||
final var recipientResolver = account.getRecipientResolver();
|
||||
final var failedTargets = results.stream()
|
||||
.filter(r -> !r.isSuccess())
|
||||
.map(r -> context.getRecipientHelper().resolveRecipient(r.getAddress()))
|
||||
.map(r -> recipientResolver.resolveRecipient(r.getAddress()))
|
||||
.toList();
|
||||
if (!failedTargets.isEmpty()) {
|
||||
senderKeyTargets = new HashSet<>(senderKeyTargets);
|
||||
|
@ -724,7 +725,7 @@ public class SendHelper {
|
|||
|
||||
private void handleSendMessageResult(final SendMessageResult r) {
|
||||
if (r.isSuccess() && !r.getSuccess().isUnidentified()) {
|
||||
final var recipientId = context.getRecipientHelper().resolveRecipient(r.getAddress());
|
||||
final var recipientId = account.getRecipientResolver().resolveRecipient(r.getAddress());
|
||||
final var profile = account.getProfileStore().getProfile(recipientId);
|
||||
if (profile != null && (
|
||||
profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.ENABLED
|
||||
|
@ -738,7 +739,7 @@ public class SendHelper {
|
|||
}
|
||||
}
|
||||
if (r.isUnregisteredFailure()) {
|
||||
final var recipientId = context.getRecipientHelper().resolveRecipient(r.getAddress());
|
||||
final var recipientId = account.getRecipientResolver().resolveRecipient(r.getAddress());
|
||||
final var profile = account.getProfileStore().getProfile(recipientId);
|
||||
if (profile != null && (
|
||||
profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.ENABLED
|
||||
|
@ -752,7 +753,7 @@ public class SendHelper {
|
|||
}
|
||||
}
|
||||
if (r.getIdentityFailure() != null) {
|
||||
final var recipientId = context.getRecipientHelper().resolveRecipient(r.getAddress());
|
||||
final var recipientId = account.getRecipientResolver().resolveRecipient(r.getAddress());
|
||||
context.getIdentityHelper()
|
||||
.handleIdentityFailure(recipientId, r.getAddress().getServiceId(), r.getIdentityFailure());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue