recipientIdentifiers,
Optional.ofNullable(name));
- if (outputWriter instanceof PlainTextWriter writer) {
- for (var r : recipients) {
- final var contact = r.getContact() == null ? Contact.newBuilder().build() : r.getContact();
- final var profile = r.getProfile() == null ? Profile.newBuilder().build() : r.getProfile();
- writer.println(
- "Number: {} Name: {} Profile name: {} Username: {} Color: {} Blocked: {} Message expiration: {}",
- r.getAddress().getLegacyIdentifier(),
- contact.getName(),
- profile.getDisplayName(),
- r.getAddress().username().orElse(""),
- contact.getColor(),
- contact.isBlocked(),
- contact.getMessageExpirationTime() == 0
- ? "disabled"
- : contact.getMessageExpirationTime() + "s");
+ switch (outputWriter) {
+ case PlainTextWriter writer -> {
+ for (var r : recipients) {
+ final var contact = r.getContact() == null ? Contact.newBuilder().build() : r.getContact();
+ final var profile = r.getProfile() == null ? Profile.newBuilder().build() : r.getProfile();
+ writer.println(
+ "Number: {} Name: {} Profile name: {} Username: {} Color: {} Blocked: {} Message expiration: {}",
+ r.getAddress().getLegacyIdentifier(),
+ contact.getName(),
+ profile.getDisplayName(),
+ r.getAddress().username().orElse(""),
+ contact.getColor(),
+ contact.isBlocked(),
+ contact.getMessageExpirationTime() == 0
+ ? "disabled"
+ : contact.getMessageExpirationTime() + "s");
+ }
+ }
+ case JsonWriter writer -> {
+ final var jsonContacts = recipients.stream().map(r -> {
+ final var address = r.getAddress();
+ final var contact = r.getContact() == null ? Contact.newBuilder().build() : r.getContact();
+ return new JsonContact(address.number().orElse(null),
+ address.uuid().map(UUID::toString).orElse(null),
+ address.username().orElse(null),
+ contact.getName(),
+ contact.getColor(),
+ contact.isBlocked(),
+ contact.getMessageExpirationTime(),
+ r.getProfile() == null
+ ? null
+ : new JsonContact.JsonProfile(r.getProfile().getLastUpdateTimestamp(),
+ r.getProfile().getGivenName(),
+ r.getProfile().getFamilyName(),
+ r.getProfile().getAbout(),
+ r.getProfile().getAboutEmoji(),
+ r.getProfile().getMobileCoinAddress() == null
+ ? null
+ : Base64.getEncoder()
+ .encodeToString(r.getProfile().getMobileCoinAddress())));
+ }).toList();
+ writer.write(jsonContacts);
}
- } else {
- final var writer = (JsonWriter) outputWriter;
- final var jsonContacts = recipients.stream().map(r -> {
- final var address = r.getAddress();
- final var contact = r.getContact() == null ? Contact.newBuilder().build() : r.getContact();
- return new JsonContact(address.number().orElse(null),
- address.uuid().map(UUID::toString).orElse(null),
- address.username().orElse(null),
- contact.getName(),
- contact.getColor(),
- contact.isBlocked(),
- contact.getMessageExpirationTime(),
- r.getProfile() == null
- ? null
- : new JsonContact.JsonProfile(r.getProfile().getLastUpdateTimestamp(),
- r.getProfile().getGivenName(),
- r.getProfile().getFamilyName(),
- r.getProfile().getAbout(),
- r.getProfile().getAboutEmoji(),
- r.getProfile().getMobileCoinAddress() == null
- ? null
- : Base64.getEncoder()
- .encodeToString(r.getProfile().getMobileCoinAddress())));
- }).toList();
-
- writer.write(jsonContacts);
}
}