X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/382d8d22d0ccad109106b140616638799cc646f6..62687d103fab1ade650b920008060c220361d581:/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java diff --git a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java index 7f0c3b31..4a07e55e 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java @@ -2,7 +2,6 @@ package org.asamk.signal.dbus; import org.asamk.Signal; import org.asamk.signal.BaseConfig; -import org.asamk.signal.DbusReceiveMessageHandler; import org.asamk.signal.manager.AttachmentInvalidException; import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.NotMasterDeviceException; @@ -27,7 +26,7 @@ import org.asamk.signal.manager.groups.LastGroupAdminException; import org.asamk.signal.manager.groups.NotAGroupMemberException; import org.asamk.signal.manager.storage.recipients.Profile; import org.asamk.signal.manager.storage.recipients.RecipientAddress; -import org.asamk.signal.util.ErrorUtils; +import org.asamk.signal.util.SendMessageResultUtils; import org.freedesktop.dbus.DBusPath; import org.freedesktop.dbus.connections.impl.DBusConnection; import org.freedesktop.dbus.exceptions.DBusException; @@ -112,7 +111,7 @@ public class DbusSignalImpl implements Signal { @Override public void subscribeReceive() { if (dbusMessageHandler == null) { - dbusMessageHandler = new DbusReceiveMessageHandler(m, connection, objectPath); + dbusMessageHandler = new DbusReceiveMessageHandler(connection, objectPath); m.addReceiveHandler(dbusMessageHandler); } subscriberCount++; @@ -192,15 +191,13 @@ public class DbusSignalImpl implements Signal { @Override public long sendMessage(final String message, final List attachments, final String recipient) { - var recipients = new ArrayList(1); - recipients.add(recipient); - return sendMessage(message, attachments, recipients); + return sendMessage(message, attachments, List.of(recipient)); } @Override public long sendMessage(final String message, final List attachments, final List recipients) { try { - final var results = m.sendMessage(new Message(message, attachments, List.of()), + final var results = m.sendMessage(new Message(message, attachments, List.of(), Optional.empty()), getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream() .map(RecipientIdentifier.class::cast) .collect(Collectors.toSet())); @@ -220,9 +217,7 @@ public class DbusSignalImpl implements Signal { public long sendRemoteDeleteMessage( final long targetSentTimestamp, final String recipient ) { - var recipients = new ArrayList(1); - recipients.add(recipient); - return sendRemoteDeleteMessage(targetSentTimestamp, recipients); + return sendRemoteDeleteMessage(targetSentTimestamp, List.of(recipient)); } @Override @@ -267,9 +262,7 @@ public class DbusSignalImpl implements Signal { final long targetSentTimestamp, final String recipient ) { - var recipients = new ArrayList(1); - recipients.add(recipient); - return sendMessageReaction(emoji, remove, targetAuthor, targetSentTimestamp, recipients); + return sendMessageReaction(emoji, remove, targetAuthor, targetSentTimestamp, List.of(recipient)); } @Override @@ -302,10 +295,8 @@ public class DbusSignalImpl implements Signal { final String recipient, final boolean stop ) throws Error.Failure, Error.GroupNotFound, Error.UntrustedIdentity { try { - var recipients = new ArrayList(1); - recipients.add(recipient); final var results = m.sendTypingMessage(stop ? TypingAction.STOP : TypingAction.START, - getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream() + getSingleRecipientIdentifiers(List.of(recipient), m.getSelfNumber()).stream() .map(RecipientIdentifier.class::cast) .collect(Collectors.toSet())); checkSendMessageResults(results.timestamp(), results.results()); @@ -365,7 +356,7 @@ public class DbusSignalImpl implements Signal { final String message, final List attachments ) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity { try { - final var results = m.sendMessage(new Message(message, attachments, List.of()), + final var results = m.sendMessage(new Message(message, attachments, List.of(), Optional.empty()), Set.of(RecipientIdentifier.NoteToSelf.INSTANCE)); checkSendMessageResults(results.timestamp(), results.results()); return results.timestamp(); @@ -388,10 +379,28 @@ public class DbusSignalImpl implements Signal { } } + @Override + public void deleteRecipient(final String recipient) throws Error.Failure { + try { + m.deleteRecipient(getSingleRecipientIdentifier(recipient, m.getSelfNumber())); + } catch (IOException e) { + throw new Error.Failure("Recipient not found"); + } + } + + @Override + public void deleteContact(final String recipient) throws Error.Failure { + try { + m.deleteContact(getSingleRecipientIdentifier(recipient, m.getSelfNumber())); + } catch (IOException e) { + throw new Error.Failure("Contact not found"); + } + } + @Override public long sendGroupMessage(final String message, final List attachments, final byte[] groupId) { try { - var results = m.sendMessage(new Message(message, attachments, List.of()), + var results = m.sendMessage(new Message(message, attachments, List.of(), Optional.empty()), Set.of(new RecipientIdentifier.Group(getGroupId(groupId)))); checkSendMessageResults(results.timestamp(), results.results()); return results.timestamp(); @@ -482,11 +491,7 @@ public class DbusSignalImpl implements Signal { @Override public List getGroupIds() { var groups = m.getGroups(); - var ids = new ArrayList(groups.size()); - for (var group : groups) { - ids.add(group.groupId().serialize()); - } - return ids; + return groups.stream().map(g -> g.groupId().serialize()).toList(); } @Override @@ -578,9 +583,8 @@ public class DbusSignalImpl implements Signal { @Override public List isRegistered(List numbers) { - var results = new ArrayList(); if (numbers.isEmpty()) { - return results; + return List.of(); } Map> registered; @@ -593,7 +597,7 @@ public class DbusSignalImpl implements Signal { return numbers.stream().map(number -> { var uuid = registered.get(number).second(); return uuid != null; - }).collect(Collectors.toList()); + }).toList(); } @Override @@ -662,10 +666,10 @@ public class DbusSignalImpl implements Signal { public List listNumbers() { return Stream.concat(m.getIdentities().stream().map(Identity::recipient), m.getContacts().stream().map(Pair::first)) - .map(a -> a.getNumber().orElse(null)) + .map(a -> a.number().orElse(null)) .filter(Objects::nonNull) .distinct() - .collect(Collectors.toList()); + .toList(); } @Override @@ -681,7 +685,7 @@ public class DbusSignalImpl implements Signal { // Try profiles if no contact name was found for (var identity : m.getIdentities()) { final var address = identity.recipient(); - var number = address.getNumber().orElse(null); + var number = address.number().orElse(null); if (number != null) { Profile profile = null; try { @@ -764,7 +768,7 @@ public class DbusSignalImpl implements Signal { } private static void checkSendMessageResult(long timestamp, SendMessageResult result) throws DBusExecutionException { - var error = ErrorUtils.getErrorMessageFromSendMessageResult(result); + var error = SendMessageResultUtils.getErrorMessageFromSendMessageResult(result); if (error == null) { return; @@ -788,7 +792,7 @@ public class DbusSignalImpl implements Signal { return; } - var errors = ErrorUtils.getErrorMessagesFromSendMessageResults(results); + var errors = SendMessageResultUtils.getErrorMessagesFromSendMessageResults(results); if (errors.size() == 0) { return; } @@ -811,7 +815,7 @@ public class DbusSignalImpl implements Signal { return; } - var errors = ErrorUtils.getErrorMessagesFromSendMessageResults(results); + var errors = SendMessageResultUtils.getErrorMessagesFromSendMessageResults(results); if (errors.size() == 0) { return; } @@ -827,7 +831,7 @@ public class DbusSignalImpl implements Signal { } private static List getRecipientStrings(final Set members) { - return members.stream().map(RecipientAddress::getLegacyIdentifier).collect(Collectors.toList()); + return members.stream().map(RecipientAddress::getLegacyIdentifier).toList(); } private static Set getSingleRecipientIdentifiers(