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
) JsonPayment payment
,
19 @JsonInclude(JsonInclude
.Include
.NON_NULL
) List
<JsonMention
> mentions
,
20 @JsonInclude(JsonInclude
.Include
.NON_NULL
) List
<JsonAttachment
> attachments
,
21 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonSticker sticker
,
22 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonRemoteDelete remoteDelete
,
23 @JsonInclude(JsonInclude
.Include
.NON_NULL
) List
<JsonSharedContact
> contacts
,
24 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonGroupInfo groupInfo
27 static JsonDataMessage
from(MessageEnvelope
.Data dataMessage
) {
28 final var timestamp
= dataMessage
.timestamp();
29 final var groupInfo
= dataMessage
.groupContext().isPresent() ? JsonGroupInfo
.from(dataMessage
.groupContext()
31 final var message
= dataMessage
.body().orElse(null);
32 final var expiresInSeconds
= dataMessage
.expiresInSeconds();
33 final var viewOnce
= dataMessage
.isViewOnce();
34 final var reaction
= dataMessage
.reaction().map(JsonReaction
::from
).orElse(null);
35 final var quote
= dataMessage
.quote().isPresent() ? JsonQuote
.from(dataMessage
.quote().get()) : null;
36 final var payment
= dataMessage
.payment().isPresent() ? JsonPayment
.from(dataMessage
.payment().get()) : null;
37 final var mentions
= dataMessage
.mentions().size() > 0 ? dataMessage
.mentions()
39 .map(JsonMention
::from
)
40 .collect(Collectors
.toList()) : null;
41 final var remoteDelete
= dataMessage
.remoteDeleteId().isPresent()
42 ?
new JsonRemoteDelete(dataMessage
.remoteDeleteId().get())
44 final var attachments
= dataMessage
.attachments().size() > 0 ? dataMessage
.attachments()
46 .map(JsonAttachment
::from
)
47 .collect(Collectors
.toList()) : null;
48 final var sticker
= dataMessage
.sticker().isPresent() ? JsonSticker
.from(dataMessage
.sticker().get()) : null;
50 final var contacts
= dataMessage
.sharedContacts().size() > 0 ? dataMessage
.sharedContacts()
52 .map(JsonSharedContact
::from
)
53 .collect(Collectors
.toList()) : null;
54 return new JsonDataMessage(timestamp
,
69 static JsonDataMessage
from(Signal
.MessageReceived messageReceived
) {
70 return new JsonDataMessage(messageReceived
.getTimestamp(),
71 messageReceived
.getMessage(),
72 // TODO Replace these with the proper commands
79 messageReceived
.getAttachments().stream().map(JsonAttachment
::from
).collect(Collectors
.toList()),
83 messageReceived
.getGroupId().length
> 0 ? JsonGroupInfo
.from(messageReceived
.getGroupId()) : null);
86 static JsonDataMessage
from(Signal
.SyncMessageReceived messageReceived
) {
87 return new JsonDataMessage(messageReceived
.getTimestamp(),
88 messageReceived
.getMessage(),
89 // TODO Replace these with the proper commands
96 messageReceived
.getAttachments().stream().map(JsonAttachment
::from
).collect(Collectors
.toList()),
100 messageReceived
.getGroupId().length
> 0 ? JsonGroupInfo
.from(messageReceived
.getGroupId()) : null);