mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-03 04:50:37 +00:00
Added AsamK's changes
This commit is contained in:
parent
7191e4371b
commit
50d6b26faf
8 changed files with 63 additions and 81 deletions
|
@ -463,9 +463,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
|
|
||||||
if (contact.getPhone().isPresent()) {
|
if (contact.getPhone().isPresent()) {
|
||||||
System.out.println(" - Phone details:");
|
System.out.println(" - Phone details:");
|
||||||
int i = 0;
|
|
||||||
for (SharedContact.Phone phone : contact.getPhone().get()) {
|
for (SharedContact.Phone phone : contact.getPhone().get()) {
|
||||||
System.out.println(" - No. " + i + ":");
|
System.out.println(" - Phone:");
|
||||||
if (phone.getValue() != null) {
|
if (phone.getValue() != null) {
|
||||||
System.out.println(" - Number: " + phone.getValue());
|
System.out.println(" - Number: " + phone.getValue());
|
||||||
}
|
}
|
||||||
|
@ -475,15 +474,13 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
if (phone.getLabel().isPresent() && !phone.getLabel().get().isBlank()) {
|
if (phone.getLabel().isPresent() && !phone.getLabel().get().isBlank()) {
|
||||||
System.out.println(" - Label: " + phone.getLabel().get());
|
System.out.println(" - Label: " + phone.getLabel().get());
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contact.getEmail().isPresent()) {
|
if (contact.getEmail().isPresent()) {
|
||||||
System.out.println(" - Email details:");
|
System.out.println(" - Email details:");
|
||||||
int i = 0;
|
|
||||||
for (SharedContact.Email email : contact.getEmail().get()) {
|
for (SharedContact.Email email : contact.getEmail().get()) {
|
||||||
System.out.println(" - No. " + i + ":");
|
System.out.println(" - Email:");
|
||||||
if (email.getValue() != null) {
|
if (email.getValue() != null) {
|
||||||
System.out.println(" - Value: " + email.getValue());
|
System.out.println(" - Value: " + email.getValue());
|
||||||
}
|
}
|
||||||
|
@ -498,9 +495,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
|
|
||||||
if (contact.getAddress().isPresent()) {
|
if (contact.getAddress().isPresent()) {
|
||||||
System.out.println(" - Address details:");
|
System.out.println(" - Address details:");
|
||||||
int i = 0;
|
|
||||||
for (SharedContact.PostalAddress address : contact.getAddress().get()) {
|
for (SharedContact.PostalAddress address : contact.getAddress().get()) {
|
||||||
System.out.println(" - No. " + i + ":");
|
System.out.println(" - Address:");
|
||||||
if (address.getType() != null) {
|
if (address.getType() != null) {
|
||||||
System.out.println(" - Type: " + address.getType());
|
System.out.println(" - Type: " + address.getType());
|
||||||
}
|
}
|
||||||
|
@ -528,7 +524,6 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
if (address.getCountry().isPresent() && !address.getCountry().get().isBlank()) {
|
if (address.getCountry().isPresent() && !address.getCountry().get().isBlank()) {
|
||||||
System.out.println(" - Country: " + address.getCountry().get());
|
System.out.println(" - Country: " + address.getCountry().get());
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.asamk.signal.json;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import org.asamk.signal.util.Util;
|
||||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||||
|
|
||||||
public class JsonContactAddress {
|
public class JsonContactAddress {
|
||||||
|
@ -33,27 +34,15 @@ public class JsonContactAddress {
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private final String country;
|
private final String country;
|
||||||
|
|
||||||
private String getValueIfActuallyPopulated(String string) {
|
|
||||||
if (string == null || string.isBlank()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonContactAddress(SharedContact.PostalAddress address) {
|
public JsonContactAddress(SharedContact.PostalAddress address) {
|
||||||
type = address.getType();
|
type = address.getType();
|
||||||
label = getValueIfActuallyPopulated(address.getLabel().orNull());
|
label = Util.getStringIfNotBlank(address.getLabel());
|
||||||
street = getValueIfActuallyPopulated(address.getStreet().orNull());
|
street = Util.getStringIfNotBlank(address.getStreet());
|
||||||
pobox = getValueIfActuallyPopulated(address.getPobox().orNull());
|
pobox = Util.getStringIfNotBlank(address.getPobox());
|
||||||
neighborhood = getValueIfActuallyPopulated(address.getNeighborhood().orNull());
|
neighborhood = Util.getStringIfNotBlank(address.getNeighborhood());
|
||||||
city = getValueIfActuallyPopulated(address.getCity().orNull());
|
city = Util.getStringIfNotBlank(address.getCity());
|
||||||
region = getValueIfActuallyPopulated(address.getRegion().orNull());
|
region = Util.getStringIfNotBlank(address.getRegion());
|
||||||
postcode = getValueIfActuallyPopulated(address.getPostcode().orNull());
|
postcode = Util.getStringIfNotBlank(address.getPostcode());
|
||||||
country = getValueIfActuallyPopulated(address.getCountry().orNull());
|
country = Util.getStringIfNotBlank(address.getCountry());
|
||||||
if (country == null) {
|
|
||||||
System.out.println("Is null");
|
|
||||||
} else {
|
|
||||||
System.out.println("Present: " + country);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.asamk.signal.json;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import org.asamk.signal.util.Util;
|
||||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||||
|
|
||||||
public class JsonContactEmail {
|
public class JsonContactEmail {
|
||||||
|
@ -15,16 +16,9 @@ public class JsonContactEmail {
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private final String label;
|
private final String label;
|
||||||
|
|
||||||
private String getValueIfPresent(String string) {
|
|
||||||
if (string == null || string.isBlank()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonContactEmail(SharedContact.Email email) {
|
public JsonContactEmail(SharedContact.Email email) {
|
||||||
value = email.getValue();
|
value = email.getValue();
|
||||||
type = email.getType();
|
type = email.getType();
|
||||||
label = getValueIfPresent(email.getLabel().orNull());
|
label = Util.getStringIfNotBlank(email.getLabel());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
36
src/main/java/org/asamk/signal/json/JsonContactName.java
Normal file
36
src/main/java/org/asamk/signal/json/JsonContactName.java
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package org.asamk.signal.json;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import org.asamk.signal.util.Util;
|
||||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||||
|
|
||||||
public class JsonContactPhone {
|
public class JsonContactPhone {
|
||||||
|
@ -15,16 +16,9 @@ public class JsonContactPhone {
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private final String label;
|
private final String label;
|
||||||
|
|
||||||
private String getValueIfPresent(String string) {
|
|
||||||
if (string == null || string.isBlank()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonContactPhone(SharedContact.Phone phone) {
|
public JsonContactPhone(SharedContact.Phone phone) {
|
||||||
value = phone.getValue();
|
value = phone.getValue();
|
||||||
type = phone.getType();
|
type = phone.getType();
|
||||||
label = getValueIfPresent(phone.getLabel().orNull());
|
label = Util.getStringIfNotBlank(phone.getLabel());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11,7 +11,7 @@ import java.util.stream.Collectors;
|
||||||
public class JsonSharedContact {
|
public class JsonSharedContact {
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
final JsonName name;
|
final JsonContactName name;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
final JsonContactAvatar avatar;
|
final JsonContactAvatar avatar;
|
||||||
|
@ -33,7 +33,7 @@ public class JsonSharedContact {
|
||||||
|
|
||||||
|
|
||||||
public JsonSharedContact(SharedContact contact) {
|
public JsonSharedContact(SharedContact contact) {
|
||||||
name = new JsonName(contact.getName());
|
name = new JsonContactName(contact.getName());
|
||||||
if (contact.getAvatar().isPresent()) {
|
if (contact.getAvatar().isPresent()) {
|
||||||
avatar = new JsonContactAvatar(contact.getAvatar().get());
|
avatar = new JsonContactAvatar(contact.getAvatar().get());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,12 +2,21 @@ package org.asamk.signal.util;
|
||||||
|
|
||||||
import org.asamk.signal.manager.groups.GroupId;
|
import org.asamk.signal.manager.groups.GroupId;
|
||||||
import org.asamk.signal.manager.groups.GroupIdFormatException;
|
import org.asamk.signal.manager.groups.GroupIdFormatException;
|
||||||
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
|
|
||||||
public class Util {
|
public class Util {
|
||||||
|
|
||||||
private 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) {
|
public static String formatSafetyNumber(String digits) {
|
||||||
final int partCount = 12;
|
final int partCount = 12;
|
||||||
int partSize = digits.length() / partCount;
|
int partSize = digits.length() / partCount;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue