]>
nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/json/JsonSharedContact.java
1 package org
.asamk
.signal
.json
;
3 import com
.fasterxml
.jackson
.annotation
.JsonInclude
;
5 import org
.whispersystems
.signalservice
.api
.messages
.shared
.SharedContact
;
8 import java
.util
.stream
.Collectors
;
10 public record JsonSharedContact(
12 JsonContactAvatar avatar
,
13 @JsonInclude(JsonInclude
.Include
.NON_NULL
) List
<JsonContactPhone
> phone
,
14 @JsonInclude(JsonInclude
.Include
.NON_NULL
) List
<JsonContactEmail
> email
,
15 @JsonInclude(JsonInclude
.Include
.NON_NULL
) List
<JsonContactAddress
> address
,
19 static JsonSharedContact
from(SharedContact contact
) {
20 final var name
= JsonContactName
.from(contact
.getName());
21 final var avatar
= contact
.getAvatar().isPresent() ? JsonContactAvatar
.from(contact
.getAvatar().get()) : null;
23 final var phone
= contact
.getPhone().isPresent() ? contact
.getPhone()
26 .map(JsonContactPhone
::from
)
27 .collect(Collectors
.toList()) : null;
29 final var email
= contact
.getEmail().isPresent() ? contact
.getEmail()
32 .map(JsonContactEmail
::from
)
33 .collect(Collectors
.toList()) : null;
35 final var address
= contact
.getAddress().isPresent() ? contact
.getAddress()
38 .map(JsonContactAddress
::from
)
39 .collect(Collectors
.toList()) : null;
41 final var organization
= contact
.getOrganization().orNull();
43 return new JsonSharedContact(name
, avatar
, phone
, email
, address
, organization
);