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 JsonGroupInfo groupInfo
;
59 JsonDataMessage(SignalServiceDataMessage dataMessage
, Manager m
) {
60 this.timestamp
= dataMessage
.getTimestamp();
61 if (dataMessage
.getGroupContext().isPresent()) {
62 final SignalServiceGroupContext groupContext
= dataMessage
.getGroupContext().get();
63 if (groupContext
.getGroupV1().isPresent()) {
64 SignalServiceGroup groupInfo
= groupContext
.getGroupV1().get();
65 this.groupInfo
= new JsonGroupInfo(groupInfo
);
66 } else if (groupContext
.getGroupV2().isPresent()) {
67 SignalServiceGroupV2 groupInfo
= groupContext
.getGroupV2().get();
68 this.groupInfo
= new JsonGroupInfo(groupInfo
);
70 this.groupInfo
= null;
73 this.groupInfo
= null;
75 this.message
= dataMessage
.getBody().orNull();
76 this.expiresInSeconds
= dataMessage
.getExpiresInSeconds();
77 this.viewOnce
= dataMessage
.isViewOnce();
78 this.reaction
= dataMessage
.getReaction().isPresent()
79 ?
new JsonReaction(dataMessage
.getReaction().get(), m
)
81 this.quote
= dataMessage
.getQuote().isPresent() ?
new JsonQuote(dataMessage
.getQuote().get(), m
) : null;
82 if (dataMessage
.getMentions().isPresent()) {
83 this.mentions
= dataMessage
.getMentions()
86 .map(mention
-> new JsonMention(mention
, m
))
87 .collect(Collectors
.toList());
89 this.mentions
= List
.of();
91 remoteDelete
= dataMessage
.getRemoteDelete().isPresent() ?
new JsonRemoteDelete(dataMessage
.getRemoteDelete()
93 if (dataMessage
.getAttachments().isPresent()) {
94 this.attachments
= dataMessage
.getAttachments()
97 .map(JsonAttachment
::new)
98 .collect(Collectors
.toList());
100 this.attachments
= List
.of();
102 this.sticker
= dataMessage
.getSticker().isPresent() ?
new JsonSticker(dataMessage
.getSticker().get()) : null;
105 public JsonDataMessage(Signal
.MessageReceived messageReceived
) {
106 timestamp
= messageReceived
.getTimestamp();
107 message
= messageReceived
.getMessage();
108 groupInfo
= messageReceived
.getGroupId().length
> 0 ?
new JsonGroupInfo(messageReceived
.getGroupId()) : null;
109 expiresInSeconds
= null;
112 reaction
= null; // TODO Replace these 4 with the proper commands
116 attachments
= messageReceived
.getAttachments().stream().map(JsonAttachment
::new).collect(Collectors
.toList());
119 public JsonDataMessage(Signal
.SyncMessageReceived 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 4 with the proper commands
130 attachments
= messageReceived
.getAttachments().stream().map(JsonAttachment
::new).collect(Collectors
.toList());