mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Use record patterns
This commit is contained in:
parent
f26a0d2891
commit
1295ef69ca
1 changed files with 9 additions and 10 deletions
|
@ -25,6 +25,7 @@ import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
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.config.ServiceConfig.MAXIMUM_ONE_OFF_REQUEST_SIZE;
|
||||||
import static org.asamk.signal.manager.util.Utils.handleResponseException;
|
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) {
|
if (recipient instanceof RecipientIdentifier.Uuid(UUID uuid)) {
|
||||||
return account.getRecipientResolver().resolveRecipient(ACI.from(uuidRecipient.uuid()));
|
return account.getRecipientResolver().resolveRecipient(ACI.from(uuid));
|
||||||
} else if (recipient instanceof RecipientIdentifier.Pni pniRecipient) {
|
} else if (recipient instanceof RecipientIdentifier.Pni(UUID pni)) {
|
||||||
return account.getRecipientResolver().resolveRecipient(PNI.from(pniRecipient.pni()));
|
return account.getRecipientResolver().resolveRecipient(PNI.from(pni));
|
||||||
} else if (recipient instanceof RecipientIdentifier.Number numberRecipient) {
|
} else if (recipient instanceof RecipientIdentifier.Number(String number)) {
|
||||||
final var number = numberRecipient.number();
|
|
||||||
return account.getRecipientStore().resolveRecipientByNumber(number, () -> {
|
return account.getRecipientStore().resolveRecipientByNumber(number, () -> {
|
||||||
try {
|
try {
|
||||||
return getRegisteredUserByNumber(number);
|
return getRegisteredUserByNumber(number);
|
||||||
|
@ -90,8 +90,7 @@ public class RecipientHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (recipient instanceof RecipientIdentifier.Username usernameRecipient) {
|
} else if (recipient instanceof RecipientIdentifier.Username(String username)) {
|
||||||
var username = usernameRecipient.username();
|
|
||||||
return resolveRecipientByUsernameOrLink(username, false);
|
return resolveRecipientByUsernameOrLink(username, false);
|
||||||
}
|
}
|
||||||
throw new AssertionError("Unexpected RecipientIdentifier: " + recipient);
|
throw new AssertionError("Unexpected RecipientIdentifier: " + recipient);
|
||||||
|
@ -145,8 +144,8 @@ public class RecipientHelper {
|
||||||
try {
|
try {
|
||||||
return Optional.of(resolveRecipient(recipient));
|
return Optional.of(resolveRecipient(recipient));
|
||||||
} catch (UnregisteredRecipientException e) {
|
} catch (UnregisteredRecipientException e) {
|
||||||
if (recipient instanceof RecipientIdentifier.Number r) {
|
if (recipient instanceof RecipientIdentifier.Number(String number)) {
|
||||||
return account.getRecipientStore().resolveRecipientByNumberOptional(r.number());
|
return account.getRecipientStore().resolveRecipientByNumberOptional(number);
|
||||||
} else {
|
} else {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue