1 package org
.asamk
.signal
.json
;
3 import com
.fasterxml
.jackson
.annotation
.JsonInclude
;
5 import org
.asamk
.Signal
;
6 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
9 import java
.util
.stream
.Collectors
;
11 record JsonDataMessage(
14 Integer expiresInSeconds
,
15 @JsonInclude(JsonInclude
.Include
.NON_NULL
) Boolean viewOnce
,
16 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonReaction reaction
,
17 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonQuote quote
,
18 @JsonInclude(JsonInclude
.Include
.NON_NULL
) List
<JsonMention
> mentions
,
19 @JsonInclude(JsonInclude
.Include
.NON_NULL
) List
<JsonAttachment
> attachments
,
20 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonSticker sticker
,
21 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonRemoteDelete remoteDelete
,
22 @JsonInclude(JsonInclude
.Include
.NON_NULL
) List
<JsonSharedContact
> contacts
,
23 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonGroupInfo groupInfo
26 static JsonDataMessage
from(MessageEnvelope
.Data dataMessage
) {
27 final var timestamp
= dataMessage
.timestamp();
28 final var groupInfo
= dataMessage
.groupContext().isPresent() ? JsonGroupInfo
.from(dataMessage
.groupContext()
30 final var message
= dataMessage
.body().orElse(null);
31 final var expiresInSeconds
= dataMessage
.expiresInSeconds();
32 final var viewOnce
= dataMessage
.isViewOnce();
33 final var reaction
= dataMessage
.reaction().map(JsonReaction
::from
).orElse(null);
34 final var quote
= dataMessage
.quote().isPresent() ? JsonQuote
.from(dataMessage
.quote().get()) : null;
35 final var mentions
= dataMessage
.mentions().size() > 0 ? dataMessage
.mentions()
37 .map(JsonMention
::from
)
38 .collect(Collectors
.toList()) : null;
39 final var remoteDelete
= dataMessage
.remoteDeleteId().isPresent()
40 ?
new JsonRemoteDelete(dataMessage
.remoteDeleteId().get())
42 final var attachments
= dataMessage
.attachments().size() > 0 ? dataMessage
.attachments()
44 .map(JsonAttachment
::from
)
45 .collect(Collectors
.toList()) : null;
46 final var sticker
= dataMessage
.sticker().isPresent() ? JsonSticker
.from(dataMessage
.sticker().get()) : null;
48 final var contacts
= dataMessage
.sharedContacts().size() > 0 ? dataMessage
.sharedContacts()
50 .map(JsonSharedContact
::from
)
51 .collect(Collectors
.toList()) : null;
52 return new JsonDataMessage(timestamp
,
66 static JsonDataMessage
from(Signal
.MessageReceived messageReceived
) {
67 return new JsonDataMessage(messageReceived
.getTimestamp(),
68 messageReceived
.getMessage(),
69 // TODO Replace these with the proper commands
75 messageReceived
.getAttachments().stream().map(JsonAttachment
::from
).collect(Collectors
.toList()),
79 messageReceived
.getGroupId().length
> 0 ? JsonGroupInfo
.from(messageReceived
.getGroupId()) : null);
82 static JsonDataMessage
from(Signal
.SyncMessageReceived messageReceived
) {
83 return new JsonDataMessage(messageReceived
.getTimestamp(),
84 messageReceived
.getMessage(),
85 // TODO Replace these with the proper commands
91 messageReceived
.getAttachments().stream().map(JsonAttachment
::from
).collect(Collectors
.toList()),
95 messageReceived
.getGroupId().length
> 0 ? JsonGroupInfo
.from(messageReceived
.getGroupId()) : null);