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
;
9 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceGroup
;
10 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceGroupContext
;
11 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceGroupV2
;
13 import java
.util
.List
;
14 import java
.util
.stream
.Collectors
;
16 class JsonDataMessage
{
25 final Integer expiresInSeconds
;
28 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
29 final Boolean viewOnce
;
32 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
33 final JsonReaction reaction
;
36 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
37 final JsonQuote quote
;
40 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
41 final List
<JsonMention
> mentions
;
44 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
45 final List
<JsonAttachment
> attachments
;
48 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
49 final JsonSticker sticker
;
52 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
53 final JsonRemoteDelete remoteDelete
;
56 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
57 final List
<JsonSharedContact
> contacts
;
60 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
61 final JsonGroupInfo groupInfo
;
63 JsonDataMessage(SignalServiceDataMessage dataMessage
, Manager m
) {
64 this.timestamp
= dataMessage
.getTimestamp();
65 if (dataMessage
.getGroupContext().isPresent()) {
66 final SignalServiceGroupContext groupContext
= dataMessage
.getGroupContext().get();
67 if (groupContext
.getGroupV1().isPresent()) {
68 SignalServiceGroup groupInfo
= groupContext
.getGroupV1().get();
69 this.groupInfo
= new JsonGroupInfo(groupInfo
);
70 } else if (groupContext
.getGroupV2().isPresent()) {
71 SignalServiceGroupV2 groupInfo
= groupContext
.getGroupV2().get();
72 this.groupInfo
= new JsonGroupInfo(groupInfo
);
74 this.groupInfo
= null;
77 this.groupInfo
= null;
79 this.message
= dataMessage
.getBody().orNull();
80 this.expiresInSeconds
= dataMessage
.getExpiresInSeconds();
81 this.viewOnce
= dataMessage
.isViewOnce();
82 this.reaction
= dataMessage
.getReaction().isPresent()
83 ?
new JsonReaction(dataMessage
.getReaction().get(), m
)
85 this.quote
= dataMessage
.getQuote().isPresent() ?
new JsonQuote(dataMessage
.getQuote().get(), m
) : null;
86 if (dataMessage
.getMentions().isPresent()) {
87 this.mentions
= dataMessage
.getMentions()
90 .map(mention
-> new JsonMention(mention
, m
))
91 .collect(Collectors
.toList());
93 this.mentions
= List
.of();
95 remoteDelete
= dataMessage
.getRemoteDelete().isPresent() ?
new JsonRemoteDelete(dataMessage
.getRemoteDelete()
97 if (dataMessage
.getAttachments().isPresent()) {
98 this.attachments
= dataMessage
.getAttachments()
101 .map(JsonAttachment
::new)
102 .collect(Collectors
.toList());
104 this.attachments
= List
.of();
106 this.sticker
= dataMessage
.getSticker().isPresent() ?
new JsonSticker(dataMessage
.getSticker().get()) : null;
108 if (dataMessage
.getSharedContacts().isPresent()) {
109 this.contacts
= dataMessage
.getSharedContacts()
112 .map(JsonSharedContact
::new)
113 .collect(Collectors
.toList());
115 this.contacts
= List
.of();
119 public JsonDataMessage(Signal
.MessageReceived messageReceived
) {
120 timestamp
= messageReceived
.getTimestamp();
121 message
= messageReceived
.getMessage();
122 groupInfo
= messageReceived
.getGroupId().length
> 0 ?
new JsonGroupInfo(messageReceived
.getGroupId()) : null;
123 expiresInSeconds
= null;
126 reaction
= null; // TODO Replace these 5 with the proper commands
131 attachments
= messageReceived
.getAttachments().stream().map(JsonAttachment
::new).collect(Collectors
.toList());
134 public JsonDataMessage(Signal
.SyncMessageReceived messageReceived
) {
135 timestamp
= messageReceived
.getTimestamp();
136 message
= messageReceived
.getMessage();
137 groupInfo
= messageReceived
.getGroupId().length
> 0 ?
new JsonGroupInfo(messageReceived
.getGroupId()) : null;
138 expiresInSeconds
= null;
141 reaction
= null; // TODO Replace these 5 with the proper commands
146 attachments
= messageReceived
.getAttachments().stream().map(JsonAttachment
::new).collect(Collectors
.toList());