Added AsamK's changes

This commit is contained in:
david-harley 2021-02-19 09:54:08 +10:30
parent 7191e4371b
commit 50d6b26faf
8 changed files with 63 additions and 81 deletions

View file

@ -463,9 +463,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (contact.getPhone().isPresent()) {
System.out.println(" - Phone details:");
int i = 0;
for (SharedContact.Phone phone : contact.getPhone().get()) {
System.out.println(" - No. " + i + ":");
System.out.println(" - Phone:");
if (phone.getValue() != null) {
System.out.println(" - Number: " + phone.getValue());
}
@ -475,15 +474,13 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (phone.getLabel().isPresent() && !phone.getLabel().get().isBlank()) {
System.out.println(" - Label: " + phone.getLabel().get());
}
i++;
}
}
if (contact.getEmail().isPresent()) {
System.out.println(" - Email details:");
int i = 0;
for (SharedContact.Email email : contact.getEmail().get()) {
System.out.println(" - No. " + i + ":");
System.out.println(" - Email:");
if (email.getValue() != null) {
System.out.println(" - Value: " + email.getValue());
}
@ -498,9 +495,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (contact.getAddress().isPresent()) {
System.out.println(" - Address details:");
int i = 0;
for (SharedContact.PostalAddress address : contact.getAddress().get()) {
System.out.println(" - No. " + i + ":");
System.out.println(" - Address:");
if (address.getType() != null) {
System.out.println(" - Type: " + address.getType());
}
@ -528,7 +524,6 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (address.getCountry().isPresent() && !address.getCountry().get().isBlank()) {
System.out.println(" - Country: " + address.getCountry().get());
}
i++;
}
}

View file

@ -2,6 +2,7 @@ package org.asamk.signal.json;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.asamk.signal.util.Util;
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
public class JsonContactAddress {
@ -33,27 +34,15 @@ public class JsonContactAddress {
@JsonProperty
private final String country;
private String getValueIfActuallyPopulated(String string) {
if (string == null || string.isBlank()) {
return null;
}
return string;
}
public JsonContactAddress(SharedContact.PostalAddress address) {
type = address.getType();
label = getValueIfActuallyPopulated(address.getLabel().orNull());
street = getValueIfActuallyPopulated(address.getStreet().orNull());
pobox = getValueIfActuallyPopulated(address.getPobox().orNull());
neighborhood = getValueIfActuallyPopulated(address.getNeighborhood().orNull());
city = getValueIfActuallyPopulated(address.getCity().orNull());
region = getValueIfActuallyPopulated(address.getRegion().orNull());
postcode = getValueIfActuallyPopulated(address.getPostcode().orNull());
country = getValueIfActuallyPopulated(address.getCountry().orNull());
if (country == null) {
System.out.println("Is null");
} else {
System.out.println("Present: " + country);
}
label = Util.getStringIfNotBlank(address.getLabel());
street = Util.getStringIfNotBlank(address.getStreet());
pobox = Util.getStringIfNotBlank(address.getPobox());
neighborhood = Util.getStringIfNotBlank(address.getNeighborhood());
city = Util.getStringIfNotBlank(address.getCity());
region = Util.getStringIfNotBlank(address.getRegion());
postcode = Util.getStringIfNotBlank(address.getPostcode());
country = Util.getStringIfNotBlank(address.getCountry());
}
}

View file

@ -2,6 +2,7 @@ package org.asamk.signal.json;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.asamk.signal.util.Util;
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
public class JsonContactEmail {
@ -15,16 +16,9 @@ public class JsonContactEmail {
@JsonProperty
private final String label;
private String getValueIfPresent(String string) {
if (string == null || string.isBlank()) {
return null;
}
return string;
}
public JsonContactEmail(SharedContact.Email email) {
value = email.getValue();
type = email.getType();
label = getValueIfPresent(email.getLabel().orNull());
label = Util.getStringIfNotBlank(email.getLabel());
}
}

View file

@ -0,0 +1,36 @@
package org.asamk.signal.json;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.asamk.signal.util.Util;
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
public class JsonContactName {
@JsonProperty
private final String display;
@JsonProperty
private final String given;
@JsonProperty
private final String family;
@JsonProperty
private final String prefix;
@JsonProperty
private final String suffix;
@JsonProperty
private final String middle;
public JsonContactName(SharedContact.Name name) {
display = Util.getStringIfNotBlank(name.getDisplay());
given = Util.getStringIfNotBlank(name.getGiven());
family = Util.getStringIfNotBlank(name.getFamily());
prefix = Util.getStringIfNotBlank(name.getPrefix());
suffix = Util.getStringIfNotBlank(name.getSuffix());
middle = Util.getStringIfNotBlank(name.getMiddle());
}
}

View file

@ -2,6 +2,7 @@ package org.asamk.signal.json;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.asamk.signal.util.Util;
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
public class JsonContactPhone {
@ -15,16 +16,9 @@ public class JsonContactPhone {
@JsonProperty
private final String label;
private String getValueIfPresent(String string) {
if (string == null || string.isBlank()) {
return null;
}
return string;
}
public JsonContactPhone(SharedContact.Phone phone) {
value = phone.getValue();
type = phone.getType();
label = getValueIfPresent(phone.getLabel().orNull());
label = Util.getStringIfNotBlank(phone.getLabel());
}
}

View file

@ -1,35 +0,0 @@
package org.asamk.signal.json;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
public class JsonName {
@JsonProperty
private final String display;
@JsonProperty
private final String given;
@JsonProperty
private final String family;
@JsonProperty
private final String prefix;
@JsonProperty
private final String suffix;
@JsonProperty
private final String middle;
public JsonName(SharedContact.Name name) {
display = name.getDisplay().orNull();
given = name.getGiven().orNull();
family = name.getFamily().orNull();
prefix = name.getPrefix().orNull();
suffix = name.getSuffix().orNull();
middle = name.getMiddle().orNull();
}
}

View file

@ -11,7 +11,7 @@ import java.util.stream.Collectors;
public class JsonSharedContact {
@JsonProperty
final JsonName name;
final JsonContactName name;
@JsonProperty
final JsonContactAvatar avatar;
@ -33,7 +33,7 @@ public class JsonSharedContact {
public JsonSharedContact(SharedContact contact) {
name = new JsonName(contact.getName());
name = new JsonContactName(contact.getName());
if (contact.getAvatar().isPresent()) {
avatar = new JsonContactAvatar(contact.getAvatar().get());
} else {

View file

@ -2,12 +2,21 @@ package org.asamk.signal.util;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupIdFormatException;
import org.whispersystems.libsignal.util.guava.Optional;
public class Util {
private Util() {
}
public static String getStringIfNotBlank(Optional<String> value) {
String string = value.orNull();
if (string == null || string.isBlank()) {
return null;
}
return string;
}
public static String formatSafetyNumber(String digits) {
final int partCount = 12;
int partSize = digits.length() / partCount;