X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/7e7e4150e19a65c646bb3f4ec33b5ec87224f8cf..d248f249e37f7b35a3b7dd69f2a06af8eddd3996:/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 adef6f96..df21d94d 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java @@ -110,12 +110,28 @@ public class DbusManagerImpl implements Manager { @Override public Configuration getConfiguration() { - throw new UnsupportedOperationException(); + final var configuration = getRemoteObject(new DBusPath(signal.getObjectPath() + "/Configuration"), + Signal.Configuration.class).GetAll("org.asamk.Signal.Configuration"); + return new Configuration(Optional.of((Boolean) configuration.get("ReadReceipts").getValue()), + Optional.of((Boolean) configuration.get("UnidentifiedDeliveryIndicators").getValue()), + Optional.of((Boolean) configuration.get("TypingIndicators").getValue()), + Optional.of((Boolean) configuration.get("LinkPreviews").getValue())); } @Override - public void updateConfiguration(Configuration configuration) throws IOException { - throw new UnsupportedOperationException(); + public void updateConfiguration(Configuration newConfiguration) throws IOException { + final var configuration = getRemoteObject(new DBusPath(signal.getObjectPath() + "/Configuration"), + Signal.Configuration.class); + newConfiguration.readReceipts() + .ifPresent(v -> configuration.Set("org.asamk.Signal.Configuration", "ReadReceipts", v)); + newConfiguration.unidentifiedDeliveryIndicators() + .ifPresent(v -> configuration.Set("org.asamk.Signal.Configuration", + "UnidentifiedDeliveryIndicators", + v)); + newConfiguration.typingIndicators() + .ifPresent(v -> configuration.Set("org.asamk.Signal.Configuration", "TypingIndicators", v)); + newConfiguration.linkPreviews() + .ifPresent(v -> configuration.Set("org.asamk.Signal.Configuration", "LinkPreviews", v)); } @Override @@ -131,17 +147,17 @@ public class DbusManagerImpl implements Manager { emptyIfNull(about), emptyIfNull(aboutEmoji), avatar == null ? "" : avatar.map(File::getPath).orElse(""), - avatar != null && !avatar.isPresent()); + avatar != null && avatar.isEmpty()); } @Override public void unregister() throws IOException { - throw new UnsupportedOperationException(); + signal.unregister(); } @Override public void deleteAccount() throws IOException { - throw new UnsupportedOperationException(); + signal.deleteAccount(); } @Override @@ -160,7 +176,7 @@ public class DbusManagerImpl implements Manager { (long) device.get("Created").getValue(), (long) device.get("LastSeen").getValue(), thisDevice.equals(d.getObjectPath())); - }).collect(Collectors.toList()); + }).toList(); } @Override @@ -191,7 +207,7 @@ public class DbusManagerImpl implements Manager { @Override public List getGroups() { final var groups = signal.listGroups(); - return groups.stream().map(Signal.StructGroup::getObjectPath).map(this::getGroup).collect(Collectors.toList()); + return groups.stream().map(Signal.StructGroup::getObjectPath).map(this::getGroup).toList(); } @Override @@ -208,7 +224,8 @@ public class DbusManagerImpl implements Manager { @Override public void deleteGroup(final GroupId groupId) throws IOException { - throw new UnsupportedOperationException(); + final var group = getRemoteObject(signal.getGroup(groupId.serialize()), Signal.Group.class); + group.deleteGroup(); } @Override @@ -216,7 +233,7 @@ public class DbusManagerImpl implements Manager { final String name, final Set members, final File avatarFile ) throws IOException, AttachmentInvalidException { final var newGroupId = signal.createGroup(emptyIfNull(name), - members.stream().map(RecipientIdentifier.Single::getIdentifier).collect(Collectors.toList()), + members.stream().map(RecipientIdentifier.Single::getIdentifier).toList(), avatarFile == null ? "" : avatarFile.getPath()); return new Pair<>(GroupId.unknownVersion(newGroupId), new SendGroupMessageResults(0, List.of())); } @@ -254,28 +271,22 @@ public class DbusManagerImpl implements Manager { : GroupPermission.EVERY_MEMBER.name()); } if (updateGroup.getMembers() != null) { - group.addMembers(updateGroup.getMembers() - .stream() - .map(RecipientIdentifier.Single::getIdentifier) - .collect(Collectors.toList())); + group.addMembers(updateGroup.getMembers().stream().map(RecipientIdentifier.Single::getIdentifier).toList()); } if (updateGroup.getRemoveMembers() != null) { group.removeMembers(updateGroup.getRemoveMembers() .stream() .map(RecipientIdentifier.Single::getIdentifier) - .collect(Collectors.toList())); + .toList()); } if (updateGroup.getAdmins() != null) { - group.addAdmins(updateGroup.getAdmins() - .stream() - .map(RecipientIdentifier.Single::getIdentifier) - .collect(Collectors.toList())); + group.addAdmins(updateGroup.getAdmins().stream().map(RecipientIdentifier.Single::getIdentifier).toList()); } if (updateGroup.getRemoveAdmins() != null) { group.removeAdmins(updateGroup.getRemoveAdmins() .stream() .map(RecipientIdentifier.Single::getIdentifier) - .collect(Collectors.toList())); + .toList()); } if (updateGroup.isResetGroupLink()) { group.resetLink(); @@ -307,7 +318,8 @@ public class DbusManagerImpl implements Manager { signal.sendTyping(signal.getSelfNumber(), action == TypingAction.STOP); return 0L; }, groupId -> { - throw new UnsupportedOperationException(); + signal.sendGroupTyping(groupId, action == TypingAction.STOP); + return 0L; }); } @@ -375,20 +387,18 @@ public class DbusManagerImpl implements Manager { @Override public SendMessageResults sendEndSessionMessage(final Set recipients) throws IOException { - signal.sendEndSessionMessage(recipients.stream() - .map(RecipientIdentifier.Single::getIdentifier) - .collect(Collectors.toList())); + signal.sendEndSessionMessage(recipients.stream().map(RecipientIdentifier.Single::getIdentifier).toList()); return new SendMessageResults(0, Map.of()); } @Override public void deleteRecipient(final RecipientIdentifier.Single recipient) throws IOException { - throw new UnsupportedOperationException(); + signal.deleteRecipient(recipient.getIdentifier()); } @Override public void deleteContact(final RecipientIdentifier.Single recipient) throws IOException { - throw new UnsupportedOperationException(); + signal.deleteContact(recipient.getIdentifier()); } @Override @@ -632,7 +642,7 @@ public class DbusManagerImpl implements Manager { .filter(r -> r instanceof RecipientIdentifier.Single) .map(RecipientIdentifier.Single.class::cast) .map(RecipientIdentifier.Single::getIdentifier) - .collect(Collectors.toList()); + .toList(); if (singleRecipients.size() > 0) { timestamp = recipientsHandler.apply(singleRecipients); } @@ -644,7 +654,7 @@ public class DbusManagerImpl implements Manager { .filter(r -> r instanceof RecipientIdentifier.Group) .map(RecipientIdentifier.Group.class::cast) .map(RecipientIdentifier.Group::groupId) - .collect(Collectors.toList()); + .toList(); for (final var groupId : groupRecipients) { timestamp = groupHandler.apply(groupId.serialize()); } @@ -786,9 +796,8 @@ public class DbusManagerImpl implements Manager { private void notifyMessageHandlers(final MessageEnvelope envelope) { synchronized (messageHandlers) { - Stream.concat(messageHandlers.stream(), weakHandlers.stream()).forEach(h -> { - h.handleMessage(envelope, null); - }); + Stream.concat(messageHandlers.stream(), weakHandlers.stream()) + .forEach(h -> h.handleMessage(envelope, null)); } } @@ -827,7 +836,7 @@ public class DbusManagerImpl implements Manager { getValue(a, "isVoiceNote"), getValue(a, "isGif"), getValue(a, "isBorderless")); - }).collect(Collectors.toList()); + }).toList(); } @SuppressWarnings("unchecked")