X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/496cd5e6219b54e01d0a3b175cb77457001ce7dc..5f941004f5006b286690df2a93bc47ace3b59270:/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java diff --git a/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java b/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java index 5b33b039..11800be2 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java @@ -32,6 +32,7 @@ import org.asamk.signal.manager.groups.LastGroupAdminException; import org.asamk.signal.manager.groups.NotAGroupMemberException; import org.asamk.signal.manager.storage.recipients.Contact; import org.asamk.signal.manager.storage.recipients.Profile; +import org.asamk.signal.manager.storage.recipients.Recipient; import org.asamk.signal.manager.storage.recipients.RecipientAddress; import org.freedesktop.dbus.DBusMap; import org.freedesktop.dbus.DBusPath; @@ -547,14 +548,32 @@ public class DbusManagerImpl implements Manager { } @Override - public List> getContacts() { - return signal.listNumbers().stream().map(n -> { + public List getRecipients( + final boolean onlyContacts, + final Optional blocked, + final Collection addresses, + final Optional name + ) { + final var numbers = addresses.stream() + .filter(s -> s instanceof RecipientIdentifier.Number) + .map(s -> ((RecipientIdentifier.Number) s).number()) + .collect(Collectors.toSet()); + return signal.listNumbers().stream().filter(n -> addresses.isEmpty() || numbers.contains(n)).map(n -> { + final var contactBlocked = signal.isContactBlocked(n); + if (blocked.isPresent() && blocked.get() != contactBlocked) { + return null; + } final var contactName = signal.getContactName(n); - if (contactName.length() == 0) { + if (onlyContacts && contactName.length() == 0) { + return null; + } + if (name.isPresent() && !name.get().equals(contactName)) { return null; } - return new Pair<>(new RecipientAddress(null, n), - new Contact(contactName, null, 0, signal.isContactBlocked(n), false, false)); + return Recipient.newBuilder() + .withAddress(new RecipientAddress(null, n)) + .withContact(new Contact(contactName, null, 0, contactBlocked, false, false)) + .build(); }).filter(Objects::nonNull).toList(); }