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 JsonGroupInfo groupInfo
;
55 JsonDataMessage(SignalServiceDataMessage dataMessage
, Manager m
) {
56 this.timestamp
= dataMessage
.getTimestamp();
57 if (dataMessage
.getGroupContext().isPresent()) {
58 final SignalServiceGroupContext groupContext
= dataMessage
.getGroupContext().get();
59 if (groupContext
.getGroupV1().isPresent()) {
60 SignalServiceGroup groupInfo
= groupContext
.getGroupV1().get();
61 this.groupInfo
= new JsonGroupInfo(groupInfo
);
62 } else if (groupContext
.getGroupV2().isPresent()) {
63 SignalServiceGroupV2 groupInfo
= groupContext
.getGroupV2().get();
64 this.groupInfo
= new JsonGroupInfo(groupInfo
);
66 this.groupInfo
= null;
69 this.groupInfo
= null;
71 this.message
= dataMessage
.getBody().orNull();
72 this.expiresInSeconds
= dataMessage
.getExpiresInSeconds();
73 this.viewOnce
= dataMessage
.isViewOnce();
74 this.reaction
= dataMessage
.getReaction().isPresent()
75 ?
new JsonReaction(dataMessage
.getReaction().get(), m
)
77 this.quote
= dataMessage
.getQuote().isPresent() ?
new JsonQuote(dataMessage
.getQuote().get(), m
) : null;
78 if (dataMessage
.getMentions().isPresent()) {
79 this.mentions
= dataMessage
.getMentions()
82 .map(mention
-> new JsonMention(mention
, m
))
83 .collect(Collectors
.toList());
85 this.mentions
= List
.of();
87 if (dataMessage
.getAttachments().isPresent()) {
88 this.attachments
= dataMessage
.getAttachments()
91 .map(JsonAttachment
::new)
92 .collect(Collectors
.toList());
94 this.attachments
= List
.of();
96 this.sticker
= dataMessage
.getSticker().isPresent() ?
new JsonSticker(dataMessage
.getSticker().get()) : null;
99 public JsonDataMessage(Signal
.MessageReceived messageReceived
) {
100 timestamp
= messageReceived
.getTimestamp();
101 message
= messageReceived
.getMessage();
102 groupInfo
= messageReceived
.getGroupId().length
> 0 ?
new JsonGroupInfo(messageReceived
.getGroupId()) : null;
103 expiresInSeconds
= null;
105 reaction
= null; // TODO Replace these 4 with the proper commands
109 attachments
= messageReceived
.getAttachments().stream().map(JsonAttachment
::new).collect(Collectors
.toList());
112 public JsonDataMessage(Signal
.SyncMessageReceived messageReceived
) {
113 timestamp
= messageReceived
.getTimestamp();
114 message
= messageReceived
.getMessage();
115 groupInfo
= messageReceived
.getGroupId().length
> 0 ?
new JsonGroupInfo(messageReceived
.getGroupId()) : null;
116 expiresInSeconds
= null;
118 reaction
= null; // TODO Replace these 4 with the proper commands
122 attachments
= messageReceived
.getAttachments().stream().map(JsonAttachment
::new).collect(Collectors
.toList());