1 package org
.asamk
.signal
.json
;
3 import com
.fasterxml
.jackson
.annotation
.JsonInclude
;
5 import org
.asamk
.signal
.manager
.api
.Color
;
6 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
7 import org
.asamk
.signal
.manager
.groups
.GroupId
;
9 record JsonStoryMessage(
10 boolean allowsReplies
,
11 @JsonInclude(JsonInclude
.Include
.NON_NULL
) String groupId
,
12 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonAttachment fileAttachment
,
13 @JsonInclude(JsonInclude
.Include
.NON_NULL
) TextAttachment textAttachment
16 static JsonStoryMessage
from(MessageEnvelope
.Story storyMessage
) {
17 return new JsonStoryMessage(storyMessage
.allowsReplies(),
18 storyMessage
.groupId().map(GroupId
::toBase64
).orElse(null),
19 storyMessage
.fileAttachment().map(JsonAttachment
::from
).orElse(null),
20 storyMessage
.textAttachment().map(TextAttachment
::from
).orElse(null));
23 public record TextAttachment(
25 @JsonInclude(JsonInclude
.Include
.NON_NULL
) String style
,
26 @JsonInclude(JsonInclude
.Include
.NON_NULL
) String textForegroundColor
,
27 @JsonInclude(JsonInclude
.Include
.NON_NULL
) String textBackgroundColor
,
28 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonPreview preview
,
29 @JsonInclude(JsonInclude
.Include
.NON_NULL
) Gradient backgroundGradient
,
30 @JsonInclude(JsonInclude
.Include
.NON_NULL
) String backgroundColor
33 static TextAttachment
from(MessageEnvelope
.Story
.TextAttachment textAttachment
) {
34 return new TextAttachment(textAttachment
.text().orElse(null),
35 textAttachment
.style().map(MessageEnvelope
.Story
.TextAttachment
.Style
::name
).orElse(null),
36 textAttachment
.textForegroundColor().map(Color
::toHexColor
).orElse(null),
37 textAttachment
.textBackgroundColor().map(Color
::toHexColor
).orElse(null),
38 textAttachment
.preview().map(JsonPreview
::from
).orElse(null),
39 textAttachment
.backgroundGradient().map(Gradient
::from
).orElse(null),
40 textAttachment
.backgroundColor().map(Color
::toHexColor
).orElse(null));
43 public record Gradient(String startColor
, String endColor
, Integer angle
) {
45 static Gradient
from(MessageEnvelope
.Story
.TextAttachment
.Gradient gradient
) {
46 return new Gradient(gradient
.startColor().map(Color
::toHexColor
).orElse(null),
47 gradient
.endColor().map(Color
::toHexColor
).orElse(null),
48 gradient
.angle().orElse(null));