]> nmode's Git Repositories - signal-cli/commitdiff
Use record patterns
authorAsamK <asamk@gmx.de>
Sun, 16 Mar 2025 21:07:29 +0000 (22:07 +0100)
committerAsamK <asamk@gmx.de>
Sun, 16 Mar 2025 21:07:29 +0000 (22:07 +0100)
lib/src/main/java/org/asamk/signal/manager/helper/RecipientHelper.java

index 58e7ba59fb85e705254486982b2fe80ff1ea1e75..5a3524ec5c733e8bcece8c7e70d7b4b4335bb1df 100644 (file)
@@ -25,6 +25,7 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
+import java.util.UUID;
 
 import static org.asamk.signal.manager.config.ServiceConfig.MAXIMUM_ONE_OFF_REQUEST_SIZE;
 import static org.asamk.signal.manager.util.Utils.handleResponseException;
 
 import static org.asamk.signal.manager.config.ServiceConfig.MAXIMUM_ONE_OFF_REQUEST_SIZE;
 import static org.asamk.signal.manager.util.Utils.handleResponseException;
@@ -77,12 +78,11 @@ public class RecipientHelper {
     }
 
     public RecipientId resolveRecipient(final RecipientIdentifier.Single recipient) throws UnregisteredRecipientException {
     }
 
     public RecipientId resolveRecipient(final RecipientIdentifier.Single recipient) throws UnregisteredRecipientException {
-        if (recipient instanceof RecipientIdentifier.Uuid uuidRecipient) {
-            return account.getRecipientResolver().resolveRecipient(ACI.from(uuidRecipient.uuid()));
-        } else if (recipient instanceof RecipientIdentifier.Pni pniRecipient) {
-            return account.getRecipientResolver().resolveRecipient(PNI.from(pniRecipient.pni()));
-        } else if (recipient instanceof RecipientIdentifier.Number numberRecipient) {
-            final var number = numberRecipient.number();
+        if (recipient instanceof RecipientIdentifier.Uuid(UUID uuid)) {
+            return account.getRecipientResolver().resolveRecipient(ACI.from(uuid));
+        } else if (recipient instanceof RecipientIdentifier.Pni(UUID pni)) {
+            return account.getRecipientResolver().resolveRecipient(PNI.from(pni));
+        } else if (recipient instanceof RecipientIdentifier.Number(String number)) {
             return account.getRecipientStore().resolveRecipientByNumber(number, () -> {
                 try {
                     return getRegisteredUserByNumber(number);
             return account.getRecipientStore().resolveRecipientByNumber(number, () -> {
                 try {
                     return getRegisteredUserByNumber(number);
@@ -90,8 +90,7 @@ public class RecipientHelper {
                     return null;
                 }
             });
                     return null;
                 }
             });
-        } else if (recipient instanceof RecipientIdentifier.Username usernameRecipient) {
-            var username = usernameRecipient.username();
+        } else if (recipient instanceof RecipientIdentifier.Username(String username)) {
             return resolveRecipientByUsernameOrLink(username, false);
         }
         throw new AssertionError("Unexpected RecipientIdentifier: " + recipient);
             return resolveRecipientByUsernameOrLink(username, false);
         }
         throw new AssertionError("Unexpected RecipientIdentifier: " + recipient);
@@ -145,8 +144,8 @@ public class RecipientHelper {
         try {
             return Optional.of(resolveRecipient(recipient));
         } catch (UnregisteredRecipientException e) {
         try {
             return Optional.of(resolveRecipient(recipient));
         } catch (UnregisteredRecipientException e) {
-            if (recipient instanceof RecipientIdentifier.Number r) {
-                return account.getRecipientStore().resolveRecipientByNumberOptional(r.number());
+            if (recipient instanceof RecipientIdentifier.Number(String number)) {
+                return account.getRecipientStore().resolveRecipientByNumberOptional(number);
             } else {
                 return Optional.empty();
             }
             } else {
                 return Optional.empty();
             }