]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java
Improve handling of CDSI resource exhaustion
[signal-cli] / src / main / java / org / asamk / signal / dbus / DbusSignalImpl.java
index fef6821a7572ef9495ea14815af5d2e8a53f64d6..2223c96a6d31d2af3d6bf672523a3d09185c563c 100644 (file)
@@ -21,6 +21,7 @@ import org.asamk.signal.manager.api.Message;
 import org.asamk.signal.manager.api.NotAGroupMemberException;
 import org.asamk.signal.manager.api.NotPrimaryDeviceException;
 import org.asamk.signal.manager.api.PendingAdminApprovalException;
+import org.asamk.signal.manager.api.RateLimitException;
 import org.asamk.signal.manager.api.RecipientAddress;
 import org.asamk.signal.manager.api.RecipientIdentifier;
 import org.asamk.signal.manager.api.SendMessageResult;
@@ -31,6 +32,7 @@ import org.asamk.signal.manager.api.UnregisteredRecipientException;
 import org.asamk.signal.manager.api.UpdateGroup;
 import org.asamk.signal.manager.api.UpdateProfile;
 import org.asamk.signal.manager.api.UserStatus;
+import org.asamk.signal.util.DateUtils;
 import org.asamk.signal.util.SendMessageResultUtils;
 import org.freedesktop.dbus.DBusPath;
 import org.freedesktop.dbus.connections.impl.DBusConnection;
@@ -185,6 +187,8 @@ public class DbusSignalImpl implements Signal {
             m.addDeviceLink(deviceLinkUrl);
         } catch (IOException | InvalidDeviceLinkException e) {
             throw new Error.Failure(e.getClass().getSimpleName() + " Add device link failed. " + e.getMessage());
+        } catch (NotPrimaryDeviceException e) {
+            throw new Error.Failure("This command doesn't work on linked devices.");
         } catch (URISyntaxException e) {
             throw new Error.InvalidUri(e.getClass().getSimpleName()
                     + " Device link uri has invalid format: "
@@ -679,6 +683,10 @@ public class DbusSignalImpl implements Signal {
             registered = m.getUserStatus(new HashSet<>(numbers));
         } catch (IOException e) {
             throw new Error.Failure(e.getMessage());
+        } catch (RateLimitException e) {
+            throw new Error.Failure(e.getMessage()
+                    + ", retry at "
+                    + DateUtils.formatTimestamp(e.getNextAttemptTimestamp()));
         }
 
         return numbers.stream().map(number -> registered.get(number).uuid() != null).toList();
@@ -891,7 +899,7 @@ public class DbusSignalImpl implements Signal {
         }
 
         var errors = SendMessageResultUtils.getErrorMessagesFromSendMessageResults(results);
-        if (errors.size() == 0 || errors.size() < results.size()) {
+        if (errors.isEmpty() || errors.size() < results.size()) {
             return;
         }
 
@@ -1030,7 +1038,7 @@ public class DbusSignalImpl implements Signal {
             connection.exportObject(object);
             logger.debug("Exported dbus object: " + object.getObjectPath());
         } catch (DBusException e) {
-            e.printStackTrace();
+            logger.warn("Failed to export dbus object (" + object.getObjectPath() + "): " + e.getMessage());
         }
     }
 
@@ -1098,7 +1106,8 @@ public class DbusSignalImpl implements Signal {
 
         @Override
         public String getObjectPath() {
-            return getIdentityObjectPath(objectPath, identity.recipient().getLegacyIdentifier());
+            return getIdentityObjectPath(objectPath,
+                    identity.recipient().getLegacyIdentifier() + "_" + identity.recipient().getIdentifier());
         }
 
         @Override
@@ -1109,6 +1118,7 @@ public class DbusSignalImpl implements Signal {
             } catch (UnregisteredRecipientException e) {
                 throw new Error.Failure("The user " + e.getSender().getIdentifier() + " is not registered.");
             }
+            updateIdentities();
         }
 
         @Override
@@ -1135,6 +1145,7 @@ public class DbusSignalImpl implements Signal {
             } catch (UnregisteredRecipientException e) {
                 throw new Error.Failure("The user " + e.getSender().getIdentifier() + " is not registered.");
             }
+            updateIdentities();
         }
     }