]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java
Add removeContact command
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / ManagerImpl.java
index 93296a1c4f98775e5797c622926ad4a2bdde1246..269edb3b440d2b384445e798d5d72190e38ee986 100644 (file)
@@ -279,13 +279,17 @@ public class ManagerImpl implements Manager {
      *
      * @param numbers The set of phone number in question
      * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
-     * @throws IOException if its unable to get the contacts to check if they're registered
+     * @throws IOException if it's unable to get the contacts to check if they're registered
      */
     @Override
     public Map<String, Pair<String, UUID>> areUsersRegistered(Set<String> numbers) throws IOException {
         Map<String, String> canonicalizedNumbers = numbers.stream().collect(Collectors.toMap(n -> n, n -> {
             try {
-                return PhoneNumberFormatter.formatNumber(n, account.getAccount());
+                final var canonicalizedNumber = PhoneNumberFormatter.formatNumber(n, account.getAccount());
+                if (!canonicalizedNumber.equals(n)) {
+                    logger.debug("Normalized number {} to {}.", n, canonicalizedNumber);
+                }
+                return canonicalizedNumber;
             } catch (InvalidNumberException e) {
                 return "";
             }
@@ -708,15 +712,27 @@ public class ManagerImpl implements Manager {
             messageBuilder.withAttachments(attachmentHelper.uploadAttachments(attachments));
         }
         if (message.mentions().size() > 0) {
-            final var mentions = new ArrayList<SignalServiceDataMessage.Mention>();
-            for (final var m : message.mentions()) {
-                final var recipientId = resolveRecipient(m.recipient());
-                mentions.add(new SignalServiceDataMessage.Mention(resolveSignalServiceAddress(recipientId).getAci(),
-                        m.start(),
-                        m.length()));
-            }
-            messageBuilder.withMentions(mentions);
+            messageBuilder.withMentions(resolveMentions(message.mentions()));
+        }
+        if (message.quote().isPresent()) {
+            final var quote = message.quote().get();
+            messageBuilder.withQuote(new SignalServiceDataMessage.Quote(quote.timestamp(),
+                    resolveSignalServiceAddress(resolveRecipient(quote.author())),
+                    quote.message(),
+                    List.of(),
+                    resolveMentions(quote.mentions())));
+        }
+    }
+
+    private ArrayList<SignalServiceDataMessage.Mention> resolveMentions(final List<Message.Mention> mentionList) throws IOException {
+        final var mentions = new ArrayList<SignalServiceDataMessage.Mention>();
+        for (final var m : mentionList) {
+            final var recipientId = resolveRecipient(m.recipient());
+            mentions.add(new SignalServiceDataMessage.Mention(resolveSignalServiceAddress(recipientId).getAci(),
+                    m.start(),
+                    m.length()));
         }
+        return mentions;
     }
 
     @Override
@@ -762,6 +778,16 @@ public class ManagerImpl implements Manager {
         }
     }
 
+    @Override
+    public void deleteRecipient(final RecipientIdentifier.Single recipient) throws IOException {
+        account.removeRecipient(resolveRecipient(recipient));
+    }
+
+    @Override
+    public void deleteContact(final RecipientIdentifier.Single recipient) throws IOException {
+        account.getContactStore().deleteContact(resolveRecipient(recipient));
+    }
+
     @Override
     public void setContactName(
             RecipientIdentifier.Single recipient, String name