import java.util.Set;
import java.util.stream.Collectors;
+import static org.whispersystems.signalservice.internal.push.SignalServiceProtos.BodyRange;
+
public record MessageEnvelope(
Optional<RecipientAddress> sourceAddress,
int sourceDevice,
Optional<Sticker> sticker,
List<SharedContact> sharedContacts,
List<Mention> mentions,
- List<Preview> previews
+ List<Preview> previews,
+ List<TextStyle> textStyles
) {
static Data from(
.orElse(List.of()),
dataMessage.getPreviews()
.map(a -> a.stream().map(preview -> Preview.from(preview, fileProvider)).toList())
+ .orElse(List.of()),
+ dataMessage.getBodyRanges()
+ .map(a -> a.stream().filter(BodyRange::hasStyle).map(TextStyle::from).toList())
.orElse(List.of()));
}
RecipientAddress author,
Optional<String> text,
List<Mention> mentions,
- List<Attachment> attachments
+ List<Attachment> attachments,
+ List<TextStyle> textStyles
) {
static Quote from(
.toList(),
quote.getAttachments() == null
? List.of()
- : quote.getAttachments().stream().map(a -> Attachment.from(a, fileProvider)).toList());
+ : quote.getAttachments().stream().map(a -> Attachment.from(a, fileProvider)).toList(),
+ quote.getBodyRanges() == null
+ ? List.of()
+ : quote.getBodyRanges()
+ .stream()
+ .filter(BodyRange::hasStyle)
+ .map(TextStyle::from)
+ .toList());
}
}
preview.getImage().map(as -> Attachment.from(as, fileProvider)));
}
}
+
+ public record TextStyle(Style style, int start, int length) {
+
+ public enum Style {
+ NONE,
+ BOLD,
+ ITALIC,
+ SPOILER,
+ STRIKETHROUGH,
+ MONOSPACE;
+
+ static Style from(BodyRange.Style style) {
+ return switch (style) {
+ case NONE -> NONE;
+ case BOLD -> BOLD;
+ case ITALIC -> ITALIC;
+ case SPOILER -> SPOILER;
+ case STRIKETHROUGH -> STRIKETHROUGH;
+ case MONOSPACE -> MONOSPACE;
+ };
+ }
+ }
+
+ static TextStyle from(BodyRange bodyRange) {
+ return new TextStyle(Style.from(bodyRange.getStyle()), bodyRange.getStart(), bodyRange.getLength());
+ }
+ }
}
public record Sync(
printMention(writer, mention);
}
}
+ if (message.textStyles().size() > 0) {
+ writer.println("Text styles:");
+ for (var textStyle : message.textStyles()) {
+ printTextStyle(writer, textStyle);
+ }
+ }
if (message.attachments().size() > 0) {
writer.println("Attachments:");
for (var attachment : message.attachments()) {
writer.println("- {}: {} (length: {})", formatContact(mention.recipient()), mention.start(), mention.length());
}
+ private void printTextStyle(
+ PlainTextWriter writer, MessageEnvelope.Data.TextStyle textStyle
+ ) {
+ writer.println("- {}: {} (length: {})", textStyle.style().name(), textStyle.start(), textStyle.length());
+ }
+
private void printAttachment(PlainTextWriter writer, MessageEnvelope.Data.Attachment attachment) {
writer.println("Content-Type: {}", attachment.contentType());
writer.println("Type: {}", attachment.id().isPresent() ? "Pointer" : "Stream");