X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/6dabf4550bf7cd710a33648b898bc21fe3772d35..53f47d42fc30a86a9bb6cd08f4678a756f4a4aaf:/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 bee87d74..29889c3d 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java @@ -22,6 +22,7 @@ import org.asamk.signal.manager.api.StickerPackInvalidException; import org.asamk.signal.manager.api.StickerPackUrl; import org.asamk.signal.manager.api.TypingAction; import org.asamk.signal.manager.api.UpdateGroup; +import org.asamk.signal.manager.api.UserStatus; import org.asamk.signal.manager.groups.GroupId; import org.asamk.signal.manager.groups.GroupInviteLinkUrl; import org.asamk.signal.manager.groups.GroupNotFoundException; @@ -46,13 +47,14 @@ import java.net.URI; import java.net.URISyntaxException; import java.time.Duration; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.UUID; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; import java.util.function.Supplier; @@ -86,14 +88,16 @@ public class DbusManagerImpl implements Manager { } @Override - public Map> areUsersRegistered(final Set numbers) throws IOException { + public Map getUserStatus(final Set numbers) throws IOException { final var numbersList = new ArrayList<>(numbers); final var registered = signal.isRegistered(numbersList); - final var result = new HashMap>(); + final var result = new HashMap(); for (var i = 0; i < numbersList.size(); i++) { result.put(numbersList.get(i), - new Pair<>(numbersList.get(i), registered.get(i) ? RecipientAddress.UNKNOWN_UUID : null)); + new UserStatus(numbersList.get(i), + registered.get(i) ? RecipientAddress.UNKNOWN_UUID : null, + false)); } return result; } @@ -407,17 +411,21 @@ public class DbusManagerImpl implements Manager { } @Override - public void setContactBlocked( - final RecipientIdentifier.Single recipient, final boolean blocked + public void setContactsBlocked( + final Collection recipients, final boolean blocked ) throws NotMasterDeviceException, IOException { - signal.setContactBlocked(recipient.getIdentifier(), blocked); + for (final var recipient : recipients) { + signal.setContactBlocked(recipient.getIdentifier(), blocked); + } } @Override - public void setGroupBlocked( - final GroupId groupId, final boolean blocked + public void setGroupsBlocked( + final Collection groupIds, final boolean blocked ) throws GroupNotFoundException, IOException { - setGroupProperty(groupId, "IsBlocked", blocked); + for (final var groupId : groupIds) { + setGroupProperty(groupId, "IsBlocked", blocked); + } } private void setGroupProperty(final GroupId groupId, final String propertyName, final boolean blocked) { @@ -540,7 +548,14 @@ public class DbusManagerImpl implements Manager { @Override public List> getContacts() { - throw new UnsupportedOperationException(); + return signal.listNumbers().stream().map(n -> { + final var contactName = signal.getContactName(n); + if (contactName.length() == 0) { + return null; + } + return new Pair<>(new RecipientAddress(null, n), + new Contact(contactName, null, 0, signal.isContactBlocked(n), false)); + }).filter(Objects::nonNull).toList(); } @Override @@ -575,6 +590,9 @@ public class DbusManagerImpl implements Manager { ((List) group.get("Admins").getValue()).stream() .map(m -> new RecipientAddress(null, m)) .collect(Collectors.toSet()), + ((List) group.get("Banned").getValue()).stream() + .map(m -> new RecipientAddress(null, m)) + .collect(Collectors.toSet()), (boolean) group.get("IsBlocked").getValue(), (int) group.get("MessageExpirationTimer").getValue(), GroupPermission.valueOf((String) group.get("PermissionAddMember").getValue()), @@ -621,6 +639,10 @@ public class DbusManagerImpl implements Manager { throw new UnsupportedOperationException(); } + @Override + public void addAddressChangedListener(final Runnable listener) { + } + @Override public void addClosedListener(final Runnable listener) { synchronized (closedListeners) { @@ -771,7 +793,7 @@ public class DbusManagerImpl implements Manager { ? Optional.empty() : Optional.of(new RecipientAddress(null, syncReceived.getDestination())), Set.of(), - new MessageEnvelope.Data(syncReceived.getTimestamp(), + Optional.of(new MessageEnvelope.Data(syncReceived.getTimestamp(), syncReceived.getGroupId().length > 0 ? Optional.of(new MessageEnvelope.Data.GroupContext(GroupId.unknownVersion( syncReceived.getGroupId()), false, 0)) @@ -791,7 +813,7 @@ public class DbusManagerImpl implements Manager { Optional.empty(), List.of(), List.of(), - List.of()))), + List.of())))), Optional.empty(), List.of(), List.of(),