mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 05:08:03 +01:00
Identify receipt destinations by UUID instead of e164
This commit is contained in:
committed by
Jon Chambers
parent
cd49ea43c0
commit
c2ba8ab562
@@ -498,7 +498,7 @@ public class MessageController {
|
||||
try {
|
||||
receiptSender.sendReceipt(
|
||||
new AuthenticatedAccount(() -> new Pair<>(destination, destination.getMasterDevice().get())),
|
||||
source.getNumber(), timestamp);
|
||||
source.getUuid(), timestamp);
|
||||
} catch (final NoSuchUserException ignored) {
|
||||
}
|
||||
}, receiptDelay.toMillis(), TimeUnit.MILLISECONDS);
|
||||
@@ -583,7 +583,7 @@ public class MessageController {
|
||||
WebSocketConnection.recordMessageDeliveryDuration(message.get().getTimestamp(), auth.getAuthenticatedDevice());
|
||||
if (!Util.isEmpty(message.get().getSource())
|
||||
&& message.get().getType() != Envelope.Type.SERVER_DELIVERY_RECEIPT_VALUE) {
|
||||
receiptSender.sendReceipt(auth, message.get().getSource(), message.get().getTimestamp());
|
||||
receiptSender.sendReceipt(auth, message.get().getSourceUuid(), message.get().getTimestamp());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,28 +4,15 @@
|
||||
*/
|
||||
package org.whispersystems.textsecuregcm.controllers;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class NoSuchUserException extends Exception {
|
||||
|
||||
private List<String> missing;
|
||||
|
||||
public NoSuchUserException(String user) {
|
||||
super(user);
|
||||
missing = new LinkedList<>();
|
||||
missing.add(user);
|
||||
}
|
||||
|
||||
public NoSuchUserException(List<String> missing) {
|
||||
this.missing = missing;
|
||||
public NoSuchUserException(final UUID uuid) {
|
||||
super(uuid.toString());
|
||||
}
|
||||
|
||||
public NoSuchUserException(Exception e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
public List<String> getMissing() {
|
||||
return missing;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.whispersystems.textsecuregcm.push;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.textsecuregcm.auth.AuthenticatedAccount;
|
||||
@@ -22,21 +22,21 @@ public class ReceiptSender {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ReceiptSender.class);
|
||||
|
||||
public ReceiptSender(AccountsManager accountManager,
|
||||
MessageSender messageSender) {
|
||||
public ReceiptSender(final AccountsManager accountManager, final MessageSender messageSender) {
|
||||
this.accountManager = accountManager;
|
||||
this.messageSender = messageSender;
|
||||
}
|
||||
|
||||
public void sendReceipt(AuthenticatedAccount source, String destination, long messageId)
|
||||
throws NoSuchUserException {
|
||||
public void sendReceipt(AuthenticatedAccount source, UUID destinationUuid, long messageId) throws NoSuchUserException {
|
||||
final Account sourceAccount = source.getAccount();
|
||||
if (sourceAccount.getNumber().equals(destination)) {
|
||||
if (sourceAccount.getUuid().equals(destinationUuid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Account destinationAccount = getDestinationAccount(destination);
|
||||
Envelope.Builder message = Envelope.newBuilder()
|
||||
final Account destinationAccount = accountManager.get(destinationUuid)
|
||||
.orElseThrow(() -> new NoSuchUserException(destinationUuid));
|
||||
|
||||
final Envelope.Builder message = Envelope.newBuilder()
|
||||
.setServerTimestamp(System.currentTimeMillis())
|
||||
.setSource(sourceAccount.getNumber())
|
||||
.setSourceUuid(sourceAccount.getUuid().toString())
|
||||
@@ -51,22 +51,9 @@ public class ReceiptSender {
|
||||
for (final Device destinationDevice : destinationAccount.getDevices()) {
|
||||
try {
|
||||
messageSender.sendMessage(destinationAccount, destinationDevice, message.build(), false);
|
||||
} catch (NotPushRegisteredException e) {
|
||||
} catch (final NotPushRegisteredException e) {
|
||||
logger.info("User no longer push registered for delivery receipt: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Account getDestinationAccount(String destination)
|
||||
throws NoSuchUserException
|
||||
{
|
||||
Optional<Account> account = accountManager.get(destination);
|
||||
|
||||
if (account.isEmpty()) {
|
||||
throw new NoSuchUserException(destination);
|
||||
}
|
||||
|
||||
return account.get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -207,11 +207,13 @@ public class WebSocketConnection implements MessageAvailabilityListener, Displac
|
||||
if (!message.hasSource()) return;
|
||||
|
||||
try {
|
||||
receiptSender.sendReceipt(auth, message.getSource(), message.getTimestamp());
|
||||
receiptSender.sendReceipt(auth, UUID.fromString(message.getSourceUuid()), message.getTimestamp());
|
||||
} catch (NoSuchUserException e) {
|
||||
logger.info("No longer registered " + e.getMessage());
|
||||
logger.info("No longer registered: {}", e.getMessage());
|
||||
} catch (WebApplicationException e) {
|
||||
logger.warn("Bad federated response for receipt: " + e.getResponse().getStatus());
|
||||
logger.warn("Bad federated response for receipt: {}", e.getResponse().getStatus());
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.error("Could not parse UUID: {}", message.getSourceUuid());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user