]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java
Add support for sending stickers
[signal-cli] / src / main / java / org / asamk / signal / dbus / DbusSignalImpl.java
index b6f7df0ab052a8170a19ee9c98cee0e4c1a478ea..68218947b57fd4e94b9a1bbe4c21b53063710d3b 100644 (file)
@@ -10,12 +10,14 @@ import org.asamk.signal.manager.api.Identity;
 import org.asamk.signal.manager.api.InactiveGroupLinkException;
 import org.asamk.signal.manager.api.InvalidDeviceLinkException;
 import org.asamk.signal.manager.api.InvalidNumberException;
+import org.asamk.signal.manager.api.InvalidStickerException;
 import org.asamk.signal.manager.api.Message;
 import org.asamk.signal.manager.api.Pair;
 import org.asamk.signal.manager.api.RecipientIdentifier;
 import org.asamk.signal.manager.api.SendMessageResult;
 import org.asamk.signal.manager.api.SendMessageResults;
 import org.asamk.signal.manager.api.TypingAction;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
 import org.asamk.signal.manager.api.UpdateGroup;
 import org.asamk.signal.manager.groups.GroupId;
 import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
@@ -198,7 +200,11 @@ public class DbusSignalImpl implements Signal {
     @Override
     public long sendMessage(final String message, final List<String> attachments, final List<String> recipients) {
         try {
-            final var results = m.sendMessage(new Message(message, attachments, List.of(), Optional.empty()),
+            final var results = m.sendMessage(new Message(message,
+                            attachments,
+                            List.of(),
+                            Optional.empty(),
+                            Optional.empty()),
                     getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream()
                             .map(RecipientIdentifier.class::cast)
                             .collect(Collectors.toSet()));
@@ -207,10 +213,12 @@ public class DbusSignalImpl implements Signal {
             return results.timestamp();
         } catch (AttachmentInvalidException e) {
             throw new Error.AttachmentInvalid(e.getMessage());
-        } catch (IOException e) {
+        } catch (IOException | InvalidStickerException e) {
             throw new Error.Failure(e);
         } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
             throw new Error.GroupNotFound(e.getMessage());
+        } catch (UnregisteredRecipientException e) {
+            throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
         }
     }
 
@@ -272,6 +280,8 @@ public class DbusSignalImpl implements Signal {
             throw new Error.Failure(e.getMessage());
         } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
             throw new Error.GroupNotFound(e.getMessage());
+        } catch (UnregisteredRecipientException e) {
+            throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
         }
     }
 
@@ -341,16 +351,21 @@ public class DbusSignalImpl implements Signal {
             final String message, final List<String> attachments
     ) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity {
         try {
-            final var results = m.sendMessage(new Message(message, attachments, List.of(), Optional.empty()),
-                    Set.of(RecipientIdentifier.NoteToSelf.INSTANCE));
+            final var results = m.sendMessage(new Message(message,
+                    attachments,
+                    List.of(),
+                    Optional.empty(),
+                    Optional.empty()), Set.of(RecipientIdentifier.NoteToSelf.INSTANCE));
             checkSendMessageResults(results);
             return results.timestamp();
         } catch (AttachmentInvalidException e) {
             throw new Error.AttachmentInvalid(e.getMessage());
-        } catch (IOException e) {
+        } catch (IOException | InvalidStickerException e) {
             throw new Error.Failure(e.getMessage());
         } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
             throw new Error.GroupNotFound(e.getMessage());
+        } catch (UnregisteredRecipientException e) {
+            throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
         }
     }
 
@@ -366,35 +381,32 @@ 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");
-        }
+        m.deleteRecipient(getSingleRecipientIdentifier(recipient, m.getSelfNumber()));
     }
 
     @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");
-        }
+        m.deleteContact(getSingleRecipientIdentifier(recipient, m.getSelfNumber()));
     }
 
     @Override
     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(getGroupRecipientIdentifier(groupId)));
+            var results = m.sendMessage(new Message(message,
+                    attachments,
+                    List.of(),
+                    Optional.empty(),
+                    Optional.empty()), Set.of(getGroupRecipientIdentifier(groupId)));
             checkSendMessageResults(results);
             return results.timestamp();
-        } catch (IOException e) {
+        } catch (IOException | InvalidStickerException e) {
             throw new Error.Failure(e.getMessage());
         } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
             throw new Error.GroupNotFound(e.getMessage());
         } catch (AttachmentInvalidException e) {
             throw new Error.AttachmentInvalid(e.getMessage());
+        } catch (UnregisteredRecipientException e) {
+            throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
         }
     }
 
@@ -449,6 +461,8 @@ public class DbusSignalImpl implements Signal {
             throw new Error.Failure(e.getMessage());
         } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
             throw new Error.GroupNotFound(e.getMessage());
+        } catch (UnregisteredRecipientException e) {
+            throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
         }
     }
 
@@ -468,6 +482,8 @@ public class DbusSignalImpl implements Signal {
             throw new Error.Failure("This command doesn't work on linked devices.");
         } catch (IOException e) {
             throw new Error.Failure("Contact is not registered.");
+        } catch (UnregisteredRecipientException e) {
+            throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
         }
     }
 
@@ -477,6 +493,8 @@ public class DbusSignalImpl implements Signal {
             m.setExpirationTimer(getSingleRecipientIdentifier(number, m.getSelfNumber()), expiration);
         } catch (IOException e) {
             throw new Error.Failure(e.getMessage());
+        } catch (UnregisteredRecipientException e) {
+            throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
         }
     }
 
@@ -488,6 +506,8 @@ public class DbusSignalImpl implements Signal {
             throw new Error.Failure("This command doesn't work on linked devices.");
         } catch (IOException e) {
             throw new Error.Failure(e.getMessage());
+        } catch (UnregisteredRecipientException e) {
+            throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
         }
     }
 
@@ -584,6 +604,8 @@ public class DbusSignalImpl implements Signal {
             throw new Error.GroupNotFound(e.getMessage());
         } catch (AttachmentInvalidException e) {
             throw new Error.AttachmentInvalid(e.getMessage());
+        } catch (UnregisteredRecipientException e) {
+            throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
         }
     }
 
@@ -658,6 +680,8 @@ public class DbusSignalImpl implements Signal {
             m.setRegistrationLockPin(Optional.empty());
         } catch (IOException e) {
             throw new Error.Failure("Remove pin error: " + e.getMessage());
+        } catch (NotMasterDeviceException e) {
+            throw new Error.Failure("This command doesn't work on linked devices.");
         }
     }
 
@@ -667,6 +691,8 @@ public class DbusSignalImpl implements Signal {
             m.setRegistrationLockPin(Optional.of(registrationLockPin));
         } catch (IOException e) {
             throw new Error.Failure("Set pin error: " + e.getMessage());
+        } catch (NotMasterDeviceException e) {
+            throw new Error.Failure("This command doesn't work on linked devices.");
         }
     }
 
@@ -707,7 +733,7 @@ public class DbusSignalImpl implements Signal {
                 Profile profile = null;
                 try {
                     profile = m.getRecipientProfile(RecipientIdentifier.Single.fromAddress(address));
-                } catch (IOException ignored) {
+                } catch (IOException | UnregisteredRecipientException ignored) {
                 }
                 if (profile != null && profile.getDisplayName().equals(name)) {
                     numbers.add(number);
@@ -726,6 +752,8 @@ public class DbusSignalImpl implements Signal {
             throw new Error.GroupNotFound(e.getMessage());
         } catch (IOException | LastGroupAdminException e) {
             throw new Error.Failure(e.getMessage());
+        } catch (UnregisteredRecipientException e) {
+            throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
         }
     }
 
@@ -1149,6 +1177,8 @@ public class DbusSignalImpl implements Signal {
                 throw new Error.Failure(e.getMessage());
             } catch (LastGroupAdminException e) {
                 throw new Error.LastGroupAdmin(e.getMessage());
+            } catch (UnregisteredRecipientException e) {
+                throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
             }
         }
 
@@ -1262,6 +1292,8 @@ public class DbusSignalImpl implements Signal {
                 throw new Error.GroupNotFound(e.getMessage());
             } catch (AttachmentInvalidException e) {
                 throw new Error.AttachmentInvalid(e.getMessage());
+            } catch (UnregisteredRecipientException e) {
+                throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
             }
         }
     }