mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Print text styles in plain text output
This commit is contained in:
parent
a4f7632981
commit
15da210de7
3 changed files with 58 additions and 3 deletions
|
@ -39,6 +39,8 @@ import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.whispersystems.signalservice.internal.push.SignalServiceProtos.BodyRange;
|
||||||
|
|
||||||
public record MessageEnvelope(
|
public record MessageEnvelope(
|
||||||
Optional<RecipientAddress> sourceAddress,
|
Optional<RecipientAddress> sourceAddress,
|
||||||
int sourceDevice,
|
int sourceDevice,
|
||||||
|
@ -113,7 +115,8 @@ public record MessageEnvelope(
|
||||||
Optional<Sticker> sticker,
|
Optional<Sticker> sticker,
|
||||||
List<SharedContact> sharedContacts,
|
List<SharedContact> sharedContacts,
|
||||||
List<Mention> mentions,
|
List<Mention> mentions,
|
||||||
List<Preview> previews
|
List<Preview> previews,
|
||||||
|
List<TextStyle> textStyles
|
||||||
) {
|
) {
|
||||||
|
|
||||||
static Data from(
|
static Data from(
|
||||||
|
@ -154,6 +157,9 @@ public record MessageEnvelope(
|
||||||
.orElse(List.of()),
|
.orElse(List.of()),
|
||||||
dataMessage.getPreviews()
|
dataMessage.getPreviews()
|
||||||
.map(a -> a.stream().map(preview -> Preview.from(preview, fileProvider)).toList())
|
.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()));
|
.orElse(List.of()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +222,8 @@ public record MessageEnvelope(
|
||||||
RecipientAddress author,
|
RecipientAddress author,
|
||||||
Optional<String> text,
|
Optional<String> text,
|
||||||
List<Mention> mentions,
|
List<Mention> mentions,
|
||||||
List<Attachment> attachments
|
List<Attachment> attachments,
|
||||||
|
List<TextStyle> textStyles
|
||||||
) {
|
) {
|
||||||
|
|
||||||
static Quote from(
|
static Quote from(
|
||||||
|
@ -237,7 +244,14 @@ public record MessageEnvelope(
|
||||||
.toList(),
|
.toList(),
|
||||||
quote.getAttachments() == null
|
quote.getAttachments() == null
|
||||||
? List.of()
|
? 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,6 +512,33 @@ public record MessageEnvelope(
|
||||||
preview.getImage().map(as -> Attachment.from(as, fileProvider)));
|
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(
|
public record Sync(
|
||||||
|
|
|
@ -177,6 +177,12 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
printMention(writer, mention);
|
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) {
|
if (message.attachments().size() > 0) {
|
||||||
writer.println("Attachments:");
|
writer.println("Attachments:");
|
||||||
for (var attachment : message.attachments()) {
|
for (var attachment : message.attachments()) {
|
||||||
|
@ -555,6 +561,12 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
writer.println("- {}: {} (length: {})", formatContact(mention.recipient()), mention.start(), mention.length());
|
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) {
|
private void printAttachment(PlainTextWriter writer, MessageEnvelope.Data.Attachment attachment) {
|
||||||
writer.println("Content-Type: {}", attachment.contentType());
|
writer.println("Content-Type: {}", attachment.contentType());
|
||||||
writer.println("Type: {}", attachment.id().isPresent() ? "Pointer" : "Stream");
|
writer.println("Type: {}", attachment.id().isPresent() ? "Pointer" : "Stream");
|
||||||
|
|
|
@ -778,6 +778,7 @@ public class DbusManagerImpl implements Manager {
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
List.of(),
|
List.of(),
|
||||||
List.of(),
|
List.of(),
|
||||||
|
List.of(),
|
||||||
List.of())),
|
List.of())),
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
|
@ -852,6 +853,7 @@ public class DbusManagerImpl implements Manager {
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
List.of(),
|
List.of(),
|
||||||
List.of(),
|
List.of(),
|
||||||
|
List.of(),
|
||||||
List.of())),
|
List.of())),
|
||||||
Optional.empty())),
|
Optional.empty())),
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue