X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/e1134d832a1460cc5e1bcc7edf5e908bf013e0bd..03bf0439593dc1c5e02bdd49e18d649d1c24e721:/src/main/java/org/asamk/signal/manager/Manager.java diff --git a/src/main/java/org/asamk/signal/manager/Manager.java b/src/main/java/org/asamk/signal/manager/Manager.java index 38c43753..7d2681ae 100644 --- a/src/main/java/org/asamk/signal/manager/Manager.java +++ b/src/main/java/org/asamk/signal/manager/Manager.java @@ -325,11 +325,9 @@ public class Manager implements Closeable { */ public Map areUsersRegistered(Set numbers) throws IOException { // Note "contactDetails" has no optionals. It only gives us info on users who are registered - List contactDetails = this.accountManager.getContacts(numbers); + Map contactDetails = getRegisteredUsers(numbers); - Set registeredUsers = contactDetails.stream() - .map(ContactTokenDetails::getNumber) - .collect(Collectors.toSet()); + Set registeredUsers = contactDetails.keySet(); return numbers.stream().collect(Collectors.toMap(x -> x, registeredUsers::contains)); } @@ -953,7 +951,7 @@ public class Manager implements Closeable { return sendMessage(messageBuilder, getSignalServiceAddresses(recipients)); } - public Pair> sendSelfMessage( + public Pair sendSelfMessage( String messageText, List attachments ) throws IOException, AttachmentInvalidException { final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder() @@ -1184,28 +1182,29 @@ public class Manager implements Closeable { private Collection getSignalServiceAddresses(Collection numbers) throws InvalidNumberException { final Set signalServiceAddresses = new HashSet<>(numbers.size()); - final Set missingUuids = new HashSet<>(); + final Set addressesMissingUuid = new HashSet<>(); for (String number : numbers) { final SignalServiceAddress resolvedAddress = canonicalizeAndResolveSignalServiceAddress(number); if (resolvedAddress.getUuid().isPresent()) { signalServiceAddresses.add(resolvedAddress); } else { - missingUuids.add(resolvedAddress); + addressesMissingUuid.add(resolvedAddress); } } + final Set numbersMissingUuid = addressesMissingUuid.stream() + .map(a -> a.getNumber().get()) + .collect(Collectors.toSet()); Map registeredUsers; try { - registeredUsers = accountManager.getRegisteredUsers(getIasKeyStore(), - missingUuids.stream().map(a -> a.getNumber().get()).collect(Collectors.toSet()), - CDS_MRENCLAVE); - } catch (IOException | Quote.InvalidQuoteFormatException | UnauthenticatedQuoteException | SignatureException | UnauthenticatedResponseException e) { + registeredUsers = getRegisteredUsers(numbersMissingUuid); + } catch (IOException e) { logger.warn("Failed to resolve uuids from server, ignoring: {}", e.getMessage()); - registeredUsers = new HashMap<>(); + registeredUsers = Map.of(); } - for (SignalServiceAddress address : missingUuids) { + for (SignalServiceAddress address : addressesMissingUuid) { final String number = address.getNumber().get(); if (registeredUsers.containsKey(number)) { final SignalServiceAddress newAddress = resolveSignalServiceAddress(new SignalServiceAddress( @@ -1220,6 +1219,14 @@ public class Manager implements Closeable { return signalServiceAddresses; } + private Map getRegisteredUsers(final Set numbersMissingUuid) throws IOException { + try { + return accountManager.getRegisteredUsers(getIasKeyStore(), numbersMissingUuid, CDS_MRENCLAVE); + } catch (Quote.InvalidQuoteFormatException | UnauthenticatedQuoteException | SignatureException | UnauthenticatedResponseException e) { + throw new IOException(e); + } + } + private Pair> sendMessage( SignalServiceDataMessage.Builder messageBuilder, Collection recipients ) throws IOException { @@ -1278,7 +1285,7 @@ public class Manager implements Closeable { } } - private Pair> sendSelfMessage( + private Pair sendSelfMessage( SignalServiceDataMessage.Builder messageBuilder ) throws IOException { final long timestamp = System.currentTimeMillis(); @@ -1294,7 +1301,7 @@ public class Manager implements Closeable { SignalServiceDataMessage message = messageBuilder.build(); final SendMessageResult result = sendSelfMessage(message); - return new Pair<>(timestamp, List.of(result)); + return new Pair<>(timestamp, result); } finally { account.save(); }