1 package org
.asamk
.signal
.json
;
3 import com
.fasterxml
.jackson
.annotation
.JsonInclude
;
4 import com
.fasterxml
.jackson
.annotation
.JsonProperty
;
6 import org
.asamk
.Signal
;
7 import org
.asamk
.signal
.manager
.Manager
;
8 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceDataMessage
;
10 import java
.util
.List
;
11 import java
.util
.stream
.Collectors
;
13 class JsonDataMessage
{
22 final Integer expiresInSeconds
;
25 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
26 final Boolean viewOnce
;
29 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
30 final JsonReaction reaction
;
33 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
34 final JsonQuote quote
;
37 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
38 final List
<JsonMention
> mentions
;
41 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
42 final List
<JsonAttachment
> attachments
;
45 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
46 final JsonSticker sticker
;
49 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
50 final JsonRemoteDelete remoteDelete
;
53 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
54 final List
<JsonSharedContact
> contacts
;
57 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
58 final JsonGroupInfo groupInfo
;
60 JsonDataMessage(SignalServiceDataMessage dataMessage
, Manager m
) {
61 this.timestamp
= dataMessage
.getTimestamp();
62 if (dataMessage
.getGroupContext().isPresent()) {
63 final var groupContext
= dataMessage
.getGroupContext().get();
64 if (groupContext
.getGroupV1().isPresent()) {
65 var groupInfo
= groupContext
.getGroupV1().get();
66 this.groupInfo
= new JsonGroupInfo(groupInfo
);
67 } else if (groupContext
.getGroupV2().isPresent()) {
68 var groupInfo
= groupContext
.getGroupV2().get();
69 this.groupInfo
= new JsonGroupInfo(groupInfo
);
71 this.groupInfo
= null;
74 this.groupInfo
= null;
76 this.message
= dataMessage
.getBody().orNull();
77 this.expiresInSeconds
= dataMessage
.getExpiresInSeconds();
78 this.viewOnce
= dataMessage
.isViewOnce();
79 this.reaction
= dataMessage
.getReaction().isPresent()
80 ?
new JsonReaction(dataMessage
.getReaction().get(), m
)
82 this.quote
= dataMessage
.getQuote().isPresent() ?
new JsonQuote(dataMessage
.getQuote().get(), m
) : null;
83 if (dataMessage
.getMentions().isPresent()) {
84 this.mentions
= dataMessage
.getMentions()
87 .map(mention
-> new JsonMention(mention
, m
))
88 .collect(Collectors
.toList());
90 this.mentions
= List
.of();
92 remoteDelete
= dataMessage
.getRemoteDelete().isPresent() ?
new JsonRemoteDelete(dataMessage
.getRemoteDelete()
94 if (dataMessage
.getAttachments().isPresent()) {
95 this.attachments
= dataMessage
.getAttachments()
98 .map(JsonAttachment
::new)
99 .collect(Collectors
.toList());
101 this.attachments
= List
.of();
103 this.sticker
= dataMessage
.getSticker().isPresent() ?
new JsonSticker(dataMessage
.getSticker().get()) : null;
105 if (dataMessage
.getSharedContacts().isPresent()) {
106 this.contacts
= dataMessage
.getSharedContacts()
109 .map(JsonSharedContact
::new)
110 .collect(Collectors
.toList());
112 this.contacts
= List
.of();
116 public JsonDataMessage(Signal
.MessageReceived messageReceived
) {
117 timestamp
= messageReceived
.getTimestamp();
118 message
= messageReceived
.getMessage();
119 groupInfo
= messageReceived
.getGroupId().length
> 0 ?
new JsonGroupInfo(messageReceived
.getGroupId()) : null;
120 expiresInSeconds
= null;
123 reaction
= null; // TODO Replace these 5 with the proper commands
128 attachments
= messageReceived
.getAttachments().stream().map(JsonAttachment
::new).collect(Collectors
.toList());
131 public JsonDataMessage(Signal
.SyncMessageReceived messageReceived
) {
132 timestamp
= messageReceived
.getTimestamp();
133 message
= messageReceived
.getMessage();
134 groupInfo
= messageReceived
.getGroupId().length
> 0 ?
new JsonGroupInfo(messageReceived
.getGroupId()) : null;
135 expiresInSeconds
= null;
138 reaction
= null; // TODO Replace these 5 with the proper commands
143 attachments
= messageReceived
.getAttachments().stream().map(JsonAttachment
::new).collect(Collectors
.toList());