package org.asamk.signal.json;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
import org.asamk.signal.manager.Manager;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class JsonQuote {
- long id;
- String author;
- String text;
+ @JsonProperty
+ final long id;
+
+ @JsonProperty
+ @Deprecated
+ final String author;
+
+ @JsonProperty
+ final String authorNumber;
+
+ @JsonProperty
+ final String authorUuid;
+
+ @JsonProperty
+ final String text;
- List<JsonMention> mentions;
- List<JsonQuotedAttachment> attachments;
+ @JsonProperty
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ final List<JsonMention> mentions;
+
+ @JsonProperty
+ final List<JsonQuotedAttachment> attachments;
JsonQuote(SignalServiceDataMessage.Quote quote, Manager m) {
this.id = quote.getId();
- this.author = m.resolveSignalServiceAddress(quote.getAuthor()).getLegacyIdentifier();
+ final var address = m.resolveSignalServiceAddress(quote.getAuthor());
+ this.author = getLegacyIdentifier(address);
+ this.authorNumber = address.getNumber().orNull();
+ this.authorUuid = address.getUuid().toString();
this.text = quote.getText();
- if (quote.getMentions().size() > 0) {
- this.mentions = new ArrayList<>(quote.getMentions().size());
-
- for (SignalServiceDataMessage.Mention quotedMention: quote.getMentions()){
- this.mentions.add(new JsonMention(quotedMention, m));
- }
+ if (quote.getMentions() != null && quote.getMentions().size() > 0) {
+ this.mentions = quote.getMentions()
+ .stream()
+ .map(quotedMention -> new JsonMention(quotedMention, m))
+ .collect(Collectors.toList());
+ } else {
+ this.mentions = null;
}
if (quote.getAttachments().size() > 0) {
- this.attachments = new ArrayList<>(quote.getAttachments().size());
-
- for (SignalServiceDataMessage.Quote.QuotedAttachment quotedAttachment : quote.getAttachments()) {
- this.attachments.add(new JsonQuotedAttachment(quotedAttachment));
- }
+ this.attachments = quote.getAttachments()
+ .stream()
+ .map(JsonQuotedAttachment::new)
+ .collect(Collectors.toList());
} else {
this.attachments = new ArrayList<>();
}
}
-
}