mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Output "SharedContacts" field from a SignalDataMessage (#529)
* Initial version of SharedContacts from data message. Need to change location of avatar downloaded and fix plain text mode * Made empty strings for json null and fixed plaintext output * Removed old comments, simplified if-statement and added a 'leadingSpaces' field to the print attachments/mentions functions * Added AsamK's changes
This commit is contained in:
parent
9f3276d7e3
commit
237abe431b
10 changed files with 399 additions and 25 deletions
48
src/main/java/org/asamk/signal/json/JsonContactAddress.java
Normal file
48
src/main/java/org/asamk/signal/json/JsonContactAddress.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
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 {
|
||||
|
||||
@JsonProperty
|
||||
private final SharedContact.PostalAddress.Type type;
|
||||
|
||||
@JsonProperty
|
||||
private final String label;
|
||||
|
||||
@JsonProperty
|
||||
private final String street;
|
||||
|
||||
@JsonProperty
|
||||
private final String pobox;
|
||||
|
||||
@JsonProperty
|
||||
private final String neighborhood;
|
||||
|
||||
@JsonProperty
|
||||
private final String city;
|
||||
|
||||
@JsonProperty
|
||||
private final String region;
|
||||
|
||||
@JsonProperty
|
||||
private final String postcode;
|
||||
|
||||
@JsonProperty
|
||||
private final String country;
|
||||
|
||||
public JsonContactAddress(SharedContact.PostalAddress address) {
|
||||
type = address.getType();
|
||||
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());
|
||||
}
|
||||
}
|
19
src/main/java/org/asamk/signal/json/JsonContactAvatar.java
Normal file
19
src/main/java/org/asamk/signal/json/JsonContactAvatar.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||
|
||||
public class JsonContactAvatar {
|
||||
|
||||
@JsonProperty
|
||||
private final JsonAttachment attachment;
|
||||
|
||||
@JsonProperty
|
||||
private final boolean isProfile;
|
||||
|
||||
public JsonContactAvatar(SharedContact.Avatar avatar) {
|
||||
attachment = new JsonAttachment(avatar.getAttachment());
|
||||
isProfile = avatar.isProfile();
|
||||
}
|
||||
}
|
24
src/main/java/org/asamk/signal/json/JsonContactEmail.java
Normal file
24
src/main/java/org/asamk/signal/json/JsonContactEmail.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
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 {
|
||||
|
||||
@JsonProperty
|
||||
private final String value;
|
||||
|
||||
@JsonProperty
|
||||
private final SharedContact.Email.Type type;
|
||||
|
||||
@JsonProperty
|
||||
private final String label;
|
||||
|
||||
public JsonContactEmail(SharedContact.Email email) {
|
||||
value = email.getValue();
|
||||
type = email.getType();
|
||||
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());
|
||||
}
|
||||
}
|
24
src/main/java/org/asamk/signal/json/JsonContactPhone.java
Normal file
24
src/main/java/org/asamk/signal/json/JsonContactPhone.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
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 {
|
||||
|
||||
@JsonProperty
|
||||
private final String value;
|
||||
|
||||
@JsonProperty
|
||||
private final SharedContact.Phone.Type type;
|
||||
|
||||
@JsonProperty
|
||||
private final String label;
|
||||
|
||||
public JsonContactPhone(SharedContact.Phone phone) {
|
||||
value = phone.getValue();
|
||||
type = phone.getType();
|
||||
label = Util.getStringIfNotBlank(phone.getLabel());
|
||||
}
|
||||
}
|
|
@ -52,6 +52,10 @@ class JsonDataMessage {
|
|||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonRemoteDelete remoteDelete;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<JsonSharedContact> contacts;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final JsonGroupInfo groupInfo;
|
||||
|
@ -100,6 +104,16 @@ class JsonDataMessage {
|
|||
this.attachments = List.of();
|
||||
}
|
||||
this.sticker = dataMessage.getSticker().isPresent() ? new JsonSticker(dataMessage.getSticker().get()) : null;
|
||||
|
||||
if (dataMessage.getSharedContacts().isPresent()) {
|
||||
this.contacts = dataMessage.getSharedContacts()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonSharedContact::new)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
this.contacts = List.of();
|
||||
}
|
||||
}
|
||||
|
||||
public JsonDataMessage(Signal.MessageReceived messageReceived) {
|
||||
|
@ -109,10 +123,11 @@ class JsonDataMessage {
|
|||
expiresInSeconds = null;
|
||||
viewOnce = null;
|
||||
remoteDelete = null;
|
||||
reaction = null; // TODO Replace these 4 with the proper commands
|
||||
reaction = null; // TODO Replace these 5 with the proper commands
|
||||
quote = null;
|
||||
mentions = null;
|
||||
sticker = null;
|
||||
contacts = null;
|
||||
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@ -123,10 +138,11 @@ class JsonDataMessage {
|
|||
expiresInSeconds = null;
|
||||
viewOnce = null;
|
||||
remoteDelete = null;
|
||||
reaction = null; // TODO Replace these 4 with the proper commands
|
||||
reaction = null; // TODO Replace these 5 with the proper commands
|
||||
quote = null;
|
||||
mentions = null;
|
||||
sticker = null;
|
||||
contacts = null;
|
||||
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
75
src/main/java/org/asamk/signal/json/JsonSharedContact.java
Normal file
75
src/main/java/org/asamk/signal/json/JsonSharedContact.java
Normal file
|
@ -0,0 +1,75 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JsonSharedContact {
|
||||
|
||||
@JsonProperty
|
||||
final JsonContactName name;
|
||||
|
||||
@JsonProperty
|
||||
final JsonContactAvatar avatar;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<JsonContactPhone> phone;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<JsonContactEmail> email;
|
||||
|
||||
@JsonProperty
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
final List<JsonContactAddress> address;
|
||||
|
||||
@JsonProperty
|
||||
final String organization;
|
||||
|
||||
|
||||
public JsonSharedContact(SharedContact contact) {
|
||||
name = new JsonContactName(contact.getName());
|
||||
if (contact.getAvatar().isPresent()) {
|
||||
avatar = new JsonContactAvatar(contact.getAvatar().get());
|
||||
} else {
|
||||
avatar = null;
|
||||
}
|
||||
|
||||
if (contact.getPhone().isPresent()) {
|
||||
phone = contact.getPhone()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonContactPhone::new)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
phone = null;
|
||||
}
|
||||
|
||||
if (contact.getEmail().isPresent()) {
|
||||
email = contact.getEmail()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonContactEmail::new)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
email = null;
|
||||
}
|
||||
|
||||
if (contact.getAddress().isPresent()) {
|
||||
address = contact.getAddress()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonContactAddress::new)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
address = null;
|
||||
}
|
||||
|
||||
organization = contact.getOrganization().orNull();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue