]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java
Implement sendGroupTying dbus method
[signal-cli] / src / main / java / org / asamk / signal / dbus / DbusSignalImpl.java
index 4a07e55e79a8c044836cd986d16571aaef9e1a35..d306b3803b9810ee3e3d8fd08316c89ab551c64e 100644 (file)
@@ -238,22 +238,6 @@ public class DbusSignalImpl implements Signal {
         }
     }
 
-    @Override
-    public long sendGroupRemoteDeleteMessage(
-            final long targetSentTimestamp, final byte[] groupId
-    ) {
-        try {
-            final var results = m.sendRemoteDeleteMessage(targetSentTimestamp,
-                    Set.of(new RecipientIdentifier.Group(getGroupId(groupId))));
-            checkSendMessageResults(results.timestamp(), results.results());
-            return results.timestamp();
-        } catch (IOException e) {
-            throw new Error.Failure(e.getMessage());
-        } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
-            throw new Error.GroupNotFound(e.getMessage());
-        }
-    }
-
     @Override
     public long sendMessageReaction(
             final String emoji,
@@ -401,7 +385,7 @@ public class DbusSignalImpl implements Signal {
     public long sendGroupMessage(final String message, final List<String> attachments, final byte[] groupId) {
         try {
             var results = m.sendMessage(new Message(message, attachments, List.of(), Optional.empty()),
-                    Set.of(new RecipientIdentifier.Group(getGroupId(groupId))));
+                    Set.of(getGroupRecipientIdentifier(groupId)));
             checkSendMessageResults(results.timestamp(), results.results());
             return results.timestamp();
         } catch (IOException e) {
@@ -413,6 +397,37 @@ public class DbusSignalImpl implements Signal {
         }
     }
 
+    @Override
+    public void sendGroupTyping(
+            final byte[] groupId, final boolean stop
+    ) throws Error.Failure, Error.GroupNotFound, Error.UntrustedIdentity {
+        try {
+            final var results = m.sendTypingMessage(stop ? TypingAction.STOP : TypingAction.START,
+                    Set.of(getGroupRecipientIdentifier(groupId)));
+            checkSendMessageResults(results.timestamp(), results.results());
+        } catch (IOException e) {
+            throw new Error.Failure(e.getMessage());
+        } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
+            throw new Error.GroupNotFound(e.getMessage());
+        }
+    }
+
+    @Override
+    public long sendGroupRemoteDeleteMessage(
+            final long targetSentTimestamp, final byte[] groupId
+    ) {
+        try {
+            final var results = m.sendRemoteDeleteMessage(targetSentTimestamp,
+                    Set.of(getGroupRecipientIdentifier(groupId)));
+            checkSendMessageResults(results.timestamp(), results.results());
+            return results.timestamp();
+        } catch (IOException e) {
+            throw new Error.Failure(e.getMessage());
+        } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
+            throw new Error.GroupNotFound(e.getMessage());
+        }
+    }
+
     @Override
     public long sendGroupMessageReaction(
             final String emoji,
@@ -426,7 +441,7 @@ public class DbusSignalImpl implements Signal {
                     remove,
                     getSingleRecipientIdentifier(targetAuthor, m.getSelfNumber()),
                     targetSentTimestamp,
-                    Set.of(new RecipientIdentifier.Group(getGroupId(groupId))));
+                    Set.of(getGroupRecipientIdentifier(groupId)));
             checkSendMessageResults(results.timestamp(), results.results());
             return results.timestamp();
         } catch (IOException e) {
@@ -854,6 +869,10 @@ public class DbusSignalImpl implements Signal {
         }
     }
 
+    private RecipientIdentifier.Group getGroupRecipientIdentifier(final byte[] groupId) {
+        return new RecipientIdentifier.Group(getGroupId(groupId));
+    }
+
     private static GroupId getGroupId(byte[] groupId) throws DBusExecutionException {
         try {
             return GroupId.unknownVersion(groupId);