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
.GroupId
;
7 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
11 record JsonStoryMessage(
12 boolean allowsReplies
,
13 @JsonInclude(JsonInclude
.Include
.NON_NULL
) String groupId
,
14 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonAttachment fileAttachment
,
15 @JsonInclude(JsonInclude
.Include
.NON_NULL
) TextAttachment textAttachment
18 static JsonStoryMessage
from(MessageEnvelope
.Story storyMessage
) {
19 return new JsonStoryMessage(storyMessage
.allowsReplies(),
20 storyMessage
.groupId().map(GroupId
::toBase64
).orElse(null),
21 storyMessage
.fileAttachment().map(JsonAttachment
::from
).orElse(null),
22 storyMessage
.textAttachment().map(TextAttachment
::from
).orElse(null));
25 public record TextAttachment(
27 @JsonInclude(JsonInclude
.Include
.NON_NULL
) String style
,
28 @JsonInclude(JsonInclude
.Include
.NON_NULL
) String textForegroundColor
,
29 @JsonInclude(JsonInclude
.Include
.NON_NULL
) String textBackgroundColor
,
30 @JsonInclude(JsonInclude
.Include
.NON_NULL
) JsonPreview preview
,
31 @JsonInclude(JsonInclude
.Include
.NON_NULL
) Gradient backgroundGradient
,
32 @JsonInclude(JsonInclude
.Include
.NON_NULL
) String backgroundColor
35 static TextAttachment
from(MessageEnvelope
.Story
.TextAttachment textAttachment
) {
36 return new TextAttachment(textAttachment
.text().orElse(null),
37 textAttachment
.style().map(MessageEnvelope
.Story
.TextAttachment
.Style
::name
).orElse(null),
38 textAttachment
.textForegroundColor().map(Color
::toHexColor
).orElse(null),
39 textAttachment
.textBackgroundColor().map(Color
::toHexColor
).orElse(null),
40 textAttachment
.preview().map(JsonPreview
::from
).orElse(null),
41 textAttachment
.backgroundGradient().map(Gradient
::from
).orElse(null),
42 textAttachment
.backgroundColor().map(Color
::toHexColor
).orElse(null));
45 public record Gradient(
46 String startColor
, String endColor
, List
<String
> colors
, List
<Float
> positions
, Integer angle
49 static Gradient
from(MessageEnvelope
.Story
.TextAttachment
.Gradient gradient
) {
50 final var isLegacyGradient
= gradient
.colors().size() == 2
51 && gradient
.positions().size() == 2
52 && gradient
.positions().get(0) == 0f
53 && gradient
.positions().get(1) == 1f;
55 return new Gradient(isLegacyGradient ? gradient
.colors().get(0).toHexColor() : null,
56 isLegacyGradient ? gradient
.colors().get(1).toHexColor() : null,
57 gradient
.colors().stream().map(Color
::toHexColor
).toList(),
59 gradient
.angle().orElse(null));