]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/Manager.java
Add optional content type to json sticker pack manifest
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / Manager.java
index 55b57828eda9581904655ce4ea34532f48b706da..2500371f566a231c342ee396c21543c759d4556e 100644 (file)
@@ -17,6 +17,7 @@
 package org.asamk.signal.manager;
 
 import org.asamk.signal.manager.api.Device;
+import org.asamk.signal.manager.api.TypingAction;
 import org.asamk.signal.manager.config.ServiceConfig;
 import org.asamk.signal.manager.config.ServiceEnvironment;
 import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
@@ -87,6 +88,7 @@ import org.whispersystems.signalservice.api.SignalServiceMessagePipe;
 import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
 import org.whispersystems.signalservice.api.SignalServiceMessageSender;
 import org.whispersystems.signalservice.api.SignalSessionLock;
+import org.whispersystems.signalservice.api.crypto.ContentHint;
 import org.whispersystems.signalservice.api.crypto.SignalServiceCipher;
 import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
 import org.whispersystems.signalservice.api.groupsv2.ClientZkOperations;
@@ -105,6 +107,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
 import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
 import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
 import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
+import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
 import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
 import org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage;
 import org.whispersystems.signalservice.api.messages.multidevice.DeviceContact;
@@ -1534,7 +1537,7 @@ public class Manager implements Closeable {
 
     private void sendSyncMessage(SignalServiceSyncMessage message) throws IOException, UntrustedIdentityException {
         var messageSender = createMessageSender();
-        messageSender.sendMessage(message, unidentifiedAccessHelper.getAccessForSync());
+        messageSender.sendSyncMessage(message, unidentifiedAccessHelper.getAccessForSync());
     }
 
     private Set<RecipientId> getSignalServiceAddresses(Collection<String> numbers) throws InvalidNumberException {
@@ -1596,6 +1599,40 @@ public class Manager implements Closeable {
         }
     }
 
+    public void sendTypingMessage(
+            TypingAction action, Set<String> recipients
+    ) throws IOException, UntrustedIdentityException, InvalidNumberException {
+        sendTypingMessageInternal(action, getSignalServiceAddresses(recipients));
+    }
+
+    private void sendTypingMessageInternal(
+            TypingAction action, Set<RecipientId> recipientIds
+    ) throws IOException, UntrustedIdentityException {
+        final var timestamp = System.currentTimeMillis();
+        var message = new SignalServiceTypingMessage(action.toSignalService(), timestamp, Optional.absent());
+        var messageSender = createMessageSender();
+        for (var recipientId : recipientIds) {
+            final var address = resolveSignalServiceAddress(recipientId);
+            messageSender.sendTyping(address, unidentifiedAccessHelper.getAccessFor(recipientId), message);
+        }
+    }
+
+    public void sendGroupTypingMessage(
+            TypingAction action, GroupId groupId
+    ) throws IOException, NotAGroupMemberException, GroupNotFoundException {
+        final var timestamp = System.currentTimeMillis();
+        final var g = getGroupForSending(groupId);
+        final var message = new SignalServiceTypingMessage(action.toSignalService(),
+                timestamp,
+                Optional.of(groupId.serialize()));
+        final var messageSender = createMessageSender();
+        final var recipientIdList = new ArrayList<>(g.getMembersWithout(account.getSelfRecipientId()));
+        final var addresses = recipientIdList.stream()
+                .map(this::resolveSignalServiceAddress)
+                .collect(Collectors.toList());
+        messageSender.sendTyping(addresses, unidentifiedAccessHelper.getAccessFor(recipientIdList), message, null);
+    }
+
     private Pair<Long, List<SendMessageResult>> sendMessage(
             SignalServiceDataMessage.Builder messageBuilder, Set<RecipientId> recipientIds
     ) throws IOException {
@@ -1614,9 +1651,10 @@ public class Manager implements Closeable {
                     final var addresses = recipientIdList.stream()
                             .map(this::resolveSignalServiceAddress)
                             .collect(Collectors.toList());
-                    var result = messageSender.sendMessage(addresses,
+                    var result = messageSender.sendDataMessage(addresses,
                             unidentifiedAccessHelper.getAccessFor(recipientIdList),
                             isRecipientUpdate,
+                            ContentHint.DEFAULT,
                             message);
 
                     for (var r : result) {
@@ -1691,7 +1729,7 @@ public class Manager implements Closeable {
 
         try {
             var startTime = System.currentTimeMillis();
-            messageSender.sendMessage(syncMessage, unidentifiedAccess);
+            messageSender.sendSyncMessage(syncMessage, unidentifiedAccess);
             return SendMessageResult.success(recipient,
                     unidentifiedAccess.isPresent(),
                     false,
@@ -1709,11 +1747,15 @@ public class Manager implements Closeable {
         final var address = resolveSignalServiceAddress(recipientId);
         try {
             try {
-                return messageSender.sendMessage(address, unidentifiedAccessHelper.getAccessFor(recipientId), message);
+                return messageSender.sendDataMessage(address,
+                        unidentifiedAccessHelper.getAccessFor(recipientId),
+                        ContentHint.DEFAULT,
+                        message);
             } catch (UnregisteredUserException e) {
                 final var newRecipientId = refreshRegisteredUser(recipientId);
-                return messageSender.sendMessage(resolveSignalServiceAddress(newRecipientId),
+                return messageSender.sendDataMessage(resolveSignalServiceAddress(newRecipientId),
                         unidentifiedAccessHelper.getAccessFor(newRecipientId),
+                        ContentHint.DEFAULT,
                         message);
             }
         } catch (UntrustedIdentityException e) {