]> nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/json/JsonQuote.java
Trust an identity with its scannable safety numbers from the other device
[signal-cli] / src / main / java / org / asamk / signal / json / JsonQuote.java
1 package org.asamk.signal.json;
2
3 import com.fasterxml.jackson.annotation.JsonInclude;
4 import com.fasterxml.jackson.annotation.JsonProperty;
5
6 import org.asamk.signal.manager.Manager;
7 import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
8
9 import java.util.ArrayList;
10 import java.util.List;
11 import java.util.UUID;
12 import java.util.stream.Collectors;
13
14 import static org.asamk.signal.util.Util.getLegacyIdentifier;
15
16 public class JsonQuote {
17
18 @JsonProperty
19 final long id;
20
21 @JsonProperty
22 @Deprecated
23 final String author;
24
25 @JsonProperty
26 final String authorNumber;
27
28 @JsonProperty
29 final String authorUuid;
30
31 @JsonProperty
32 final String text;
33
34 @JsonProperty
35 @JsonInclude(JsonInclude.Include.NON_NULL)
36 final List<JsonMention> mentions;
37
38 @JsonProperty
39 final List<JsonQuotedAttachment> attachments;
40
41 JsonQuote(SignalServiceDataMessage.Quote quote, Manager m) {
42 this.id = quote.getId();
43 final var address = m.resolveSignalServiceAddress(quote.getAuthor());
44 this.author = getLegacyIdentifier(address);
45 this.authorNumber = address.getNumber().orNull();
46 this.authorUuid = address.getUuid().transform(UUID::toString).orNull();
47 this.text = quote.getText();
48
49 if (quote.getMentions() != null && quote.getMentions().size() > 0) {
50 this.mentions = quote.getMentions()
51 .stream()
52 .map(quotedMention -> new JsonMention(quotedMention, m))
53 .collect(Collectors.toList());
54 } else {
55 this.mentions = null;
56 }
57
58 if (quote.getAttachments().size() > 0) {
59 this.attachments = quote.getAttachments()
60 .stream()
61 .map(JsonQuotedAttachment::new)
62 .collect(Collectors.toList());
63 } else {
64 this.attachments = new ArrayList<>();
65 }
66 }
67 }