Convert RecipientAddress to record

This commit is contained in:
AsamK 2021-12-06 18:55:37 +01:00
parent c3a9022bec
commit 8867a7b9ee
14 changed files with 59 additions and 91 deletions

View file

@ -43,8 +43,8 @@ public class ListContactsCommand implements JsonRpcLocalCommand {
final var jsonContacts = contacts.stream().map(contactPair -> {
final var address = contactPair.first();
final var contact = contactPair.second();
return new JsonContact(address.getNumber().orElse(null),
address.getUuid().map(UUID::toString).orElse(null),
return new JsonContact(address.number().orElse(null),
address.uuid().map(UUID::toString).orElse(null),
contact.getName(),
contact.isBlocked(),
contact.getMessageExpirationTime());

View file

@ -41,8 +41,8 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
private static Set<JsonGroupMember> resolveJsonMembers(Set<RecipientAddress> addresses) {
return addresses.stream()
.map(address -> new JsonGroupMember(address.getNumber().orElse(null),
address.getUuid().map(UUID::toString).orElse(null)))
.map(address -> new JsonGroupMember(address.number().orElse(null),
address.uuid().map(UUID::toString).orElse(null)))
.collect(Collectors.toSet());
}

View file

@ -31,7 +31,7 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
private static void printIdentityFingerprint(PlainTextWriter writer, Identity theirId) {
writer.println("{}: {} Added: {} Fingerprint: {} Safety Number: {}",
theirId.recipient().getNumber().orElse(null),
theirId.recipient().number().orElse(null),
theirId.trustLevel(),
theirId.dateAdded(),
Hex.toString(theirId.getFingerprint()),
@ -67,8 +67,8 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
final var address = id.recipient();
var safetyNumber = Util.formatSafetyNumber(id.safetyNumber());
var scannableSafetyNumber = id.scannableSafetyNumber();
return new JsonIdentity(address.getNumber().orElse(null),
address.getUuid().map(UUID::toString).orElse(null),
return new JsonIdentity(address.number().orElse(null),
address.uuid().map(UUID::toString).orElse(null),
Hex.toString(id.getFingerprint()),
safetyNumber,
scannableSafetyNumber == null

View file

@ -679,7 +679,7 @@ public class DbusSignalImpl implements Signal {
public List<String> listNumbers() {
return Stream.concat(m.getIdentities().stream().map(Identity::recipient),
m.getContacts().stream().map(Pair::first))
.map(a -> a.getNumber().orElse(null))
.map(a -> a.number().orElse(null))
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
@ -698,7 +698,7 @@ public class DbusSignalImpl implements Signal {
// Try profiles if no contact name was found
for (var identity : m.getIdentities()) {
final var address = identity.recipient();
var number = address.getNumber().orElse(null);
var number = address.number().orElse(null);
if (number != null) {
Profile profile = null;
try {

View file

@ -9,8 +9,8 @@ public record JsonMention(@Deprecated String name, String number, String uuid, i
static JsonMention from(MessageEnvelope.Data.Mention mention) {
final var address = mention.recipient();
return new JsonMention(address.getLegacyIdentifier(),
address.getNumber().orElse(null),
address.getUuid().map(UUID::toString).orElse(null),
address.number().orElse(null),
address.uuid().map(UUID::toString).orElse(null),
mention.start(),
mention.length());
}

View file

@ -34,14 +34,14 @@ public record JsonMessageEnvelope(
if (envelope.sourceAddress().isPresent()) {
final var sourceAddress = envelope.sourceAddress().get();
source = sourceAddress.getLegacyIdentifier();
sourceNumber = sourceAddress.getNumber().orElse(null);
sourceUuid = sourceAddress.getUuid().map(UUID::toString).orElse(null);
sourceNumber = sourceAddress.number().orElse(null);
sourceUuid = sourceAddress.uuid().map(UUID::toString).orElse(null);
sourceDevice = envelope.sourceDevice();
} else if (exception instanceof UntrustedIdentityException e) {
final var sender = e.getSender();
source = sender.getLegacyIdentifier();
sourceNumber = sender.getNumber().orElse(null);
sourceUuid = sender.getUuid().map(UUID::toString).orElse(null);
sourceNumber = sender.number().orElse(null);
sourceUuid = sender.uuid().map(UUID::toString).orElse(null);
sourceDevice = e.getSenderDevice();
} else {
source = null;

View file

@ -23,8 +23,8 @@ public record JsonQuote(
final var id = quote.id();
final var address = quote.author();
final var author = address.getLegacyIdentifier();
final var authorNumber = address.getNumber().orElse(null);
final var authorUuid = address.getUuid().map(UUID::toString).orElse(null);
final var authorNumber = address.number().orElse(null);
final var authorUuid = address.uuid().map(UUID::toString).orElse(null);
final var text = quote.text().orElse(null);
final var mentions = quote.mentions().size() > 0 ? quote.mentions()

View file

@ -17,8 +17,8 @@ public record JsonReaction(
final var emoji = reaction.emoji();
final var address = reaction.targetAuthor();
final var targetAuthor = address.getLegacyIdentifier();
final var targetAuthorNumber = address.getNumber().orElse(null);
final var targetAuthorUuid = address.getUuid().map(UUID::toString).orElse(null);
final var targetAuthorNumber = address.number().orElse(null);
final var targetAuthorUuid = address.uuid().map(UUID::toString).orElse(null);
final var targetSentTimestamp = reaction.targetSentTimestamp();
final var isRemove = reaction.isRemove();
return new JsonReaction(emoji,

View file

@ -17,8 +17,8 @@ record JsonSyncDataMessage(
if (transcriptMessage.destination().isPresent()) {
final var address = transcriptMessage.destination().get();
return new JsonSyncDataMessage(address.getLegacyIdentifier(),
address.getNumber().orElse(null),
address.getUuid().map(UUID::toString).orElse(null),
address.number().orElse(null),
address.uuid().map(UUID::toString).orElse(null),
JsonDataMessage.from(transcriptMessage.message()));
} else {

View file

@ -11,8 +11,8 @@ record JsonSyncReadMessage(
static JsonSyncReadMessage from(MessageEnvelope.Sync.Read readMessage) {
final var senderAddress = readMessage.sender();
final var sender = senderAddress.getLegacyIdentifier();
final var senderNumber = senderAddress.getNumber().orElse(null);
final var senderUuid = senderAddress.getUuid().map(UUID::toString).orElse(null);
final var senderNumber = senderAddress.number().orElse(null);
final var senderUuid = senderAddress.uuid().map(UUID::toString).orElse(null);
final var timestamp = readMessage.timestamp();
return new JsonSyncReadMessage(sender, senderNumber, senderUuid, timestamp);
}