1 package org
.asamk
.signal
.json
;
3 import com
.fasterxml
.jackson
.annotation
.JsonInclude
;
5 import org
.asamk
.signal
.manager
.Manager
;
6 import org
.asamk
.signal
.manager
.api
.GroupId
;
7 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
8 import org
.asamk
.signal
.manager
.api
.RecipientAddress
;
10 import java
.util
.List
;
12 enum JsonSyncMessageType
{
18 record JsonSyncMessage(
19 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonSyncDataMessage sentMessage
,
20 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonSyncStoryMessage sentStoryMessage
,
21 @JsonInclude(JsonInclude
.Include
.NON_NULL
) List
<String
> blockedNumbers
,
22 @JsonInclude(JsonInclude
.Include
.NON_NULL
) List
<String
> blockedGroupIds
,
23 @JsonInclude(JsonInclude
.Include
.NON_NULL
) List
<JsonSyncReadMessage
> readMessages
,
24 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonSyncMessageType type
27 static JsonSyncMessage
from(MessageEnvelope
.Sync syncMessage
, Manager m
) {
28 final var sentMessage
= syncMessage
.sent().isPresent() && syncMessage
.sent().get().story().isEmpty()
29 ? JsonSyncDataMessage
.from(syncMessage
.sent().get(), m
)
31 final var sentStoryMessage
= syncMessage
.sent().isPresent() && syncMessage
.sent().get().story().isPresent()
32 ? JsonSyncStoryMessage
.from(syncMessage
.sent().get())
34 final List
<String
> blockedNumbers
;
35 final List
<String
> blockedGroupIds
;
36 if (syncMessage
.blocked().isPresent()) {
37 blockedNumbers
= syncMessage
.blocked()
41 .map(RecipientAddress
::getLegacyIdentifier
)
43 blockedGroupIds
= syncMessage
.blocked().get().groupIds().stream().map(GroupId
::toBase64
).toList();
45 blockedNumbers
= null;
46 blockedGroupIds
= null;
49 final var readMessages
= !syncMessage
.read().isEmpty() ? syncMessage
.read()
51 .map(JsonSyncReadMessage
::from
)
54 final JsonSyncMessageType type
;
55 if (syncMessage
.contacts().isPresent()) {
56 type
= JsonSyncMessageType
.CONTACTS_SYNC
;
57 } else if (syncMessage
.groups().isPresent()) {
58 type
= JsonSyncMessageType
.GROUPS_SYNC
;
62 return new JsonSyncMessage(sentMessage
, sentStoryMessage
, blockedNumbers
, blockedGroupIds
, readMessages
, type
);