]> nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/json/JsonStoryMessage.java
9fa3ea21a74a00301fb86f73537196cd89d531d6
[signal-cli] / src / main / java / org / asamk / signal / json / JsonStoryMessage.java
1 package org.asamk.signal.json;
2
3 import com.fasterxml.jackson.annotation.JsonInclude;
4
5 import org.asamk.signal.manager.api.Color;
6 import org.asamk.signal.manager.api.MessageEnvelope;
7 import org.asamk.signal.manager.groups.GroupId;
8
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
14 ) {
15
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));
21 }
22
23 public record TextAttachment(
24 String text,
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
31 ) {
32
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));
41 }
42
43 public record Gradient(String startColor, String endColor, Integer angle) {
44
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));
49 }
50 }
51 }
52 }