final var result = sendHelper.sendSelfMessage(messageBuilder);
results.put(recipient, List.of(result));
} else if (recipient instanceof RecipientIdentifier.Group group) {
- final var result = sendHelper.sendAsGroupMessage(messageBuilder, group.groupId);
+ final var result = sendHelper.sendAsGroupMessage(messageBuilder, group.groupId());
results.put(recipient, result);
}
}
final var recipientId = resolveRecipient((RecipientIdentifier.Single) recipient);
sendHelper.sendTypingMessage(message, recipientId);
} else if (recipient instanceof RecipientIdentifier.Group) {
- final var groupId = ((RecipientIdentifier.Group) recipient).groupId;
+ final var groupId = ((RecipientIdentifier.Group) recipient).groupId();
final var message = new SignalServiceTypingMessage(action, timestamp, Optional.of(groupId.serialize()));
sendHelper.sendGroupTypingMessage(message, groupId);
}
private RecipientId resolveRecipient(final RecipientIdentifier.Single recipient) throws IOException {
if (recipient instanceof RecipientIdentifier.Uuid) {
- return account.getRecipientStore().resolveRecipient(((RecipientIdentifier.Uuid) recipient).uuid);
+ return account.getRecipientStore().resolveRecipient(((RecipientIdentifier.Uuid) recipient).uuid());
} else {
- final var number = ((RecipientIdentifier.Number) recipient).number;
+ final var number = ((RecipientIdentifier.Number) recipient).number();
return account.getRecipientStore().resolveRecipient(number, () -> {
try {
return getRegisteredUser(number);
import java.util.UUID;
-public sealed abstract class RecipientIdentifier {
+public sealed interface RecipientIdentifier {
- public static final class NoteToSelf extends RecipientIdentifier {
+ record NoteToSelf() implements RecipientIdentifier {
public static NoteToSelf INSTANCE = new NoteToSelf();
-
- private NoteToSelf() {
- }
}
- public sealed static abstract class Single extends RecipientIdentifier {
+ sealed interface Single extends RecipientIdentifier {
- public static Single fromString(String identifier, String localNumber) throws InvalidNumberException {
+ static Single fromString(String identifier, String localNumber) throws InvalidNumberException {
return UuidUtil.isUuid(identifier)
? new Uuid(UUID.fromString(identifier))
: new Number(PhoneNumberFormatter.formatNumber(identifier, localNumber));
}
- public static Single fromAddress(SignalServiceAddress address) {
+ static Single fromAddress(SignalServiceAddress address) {
return new Uuid(address.getUuid());
}
- public static Single fromAddress(RecipientAddress address) {
+ static Single fromAddress(RecipientAddress address) {
if (address.getNumber().isPresent()) {
return new Number(address.getNumber().get());
} else if (address.getUuid().isPresent()) {
throw new AssertionError("RecipientAddress without identifier");
}
- public abstract String getIdentifier();
+ String getIdentifier();
}
- public static final class Uuid extends Single {
-
- public final UUID uuid;
-
- public Uuid(final UUID uuid) {
- this.uuid = uuid;
- }
-
- @Override
- public boolean equals(final Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- final Uuid uuid1 = (Uuid) o;
-
- return uuid.equals(uuid1.uuid);
- }
-
- @Override
- public int hashCode() {
- return uuid.hashCode();
- }
+ record Uuid(UUID uuid) implements Single {
@Override
public String getIdentifier() {
}
}
- public static final class Number extends Single {
-
- public final String number;
-
- public Number(final String number) {
- this.number = number;
- }
-
- @Override
- public boolean equals(final Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- final Number number1 = (Number) o;
-
- return number.equals(number1.number);
- }
-
- @Override
- public int hashCode() {
- return number.hashCode();
- }
+ record Number(String number) implements Single {
@Override
public String getIdentifier() {
}
}
- public static final class Group extends RecipientIdentifier {
-
- public final GroupId groupId;
-
- public Group(final GroupId groupId) {
- this.groupId = groupId;
- }
-
- @Override
- public boolean equals(final Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- final Group group = (Group) o;
-
- return groupId.equals(group.groupId);
- }
-
- @Override
- public int hashCode() {
- return groupId.hashCode();
- }
- }
+ record Group(GroupId groupId) implements RecipientIdentifier {}
}