From e377357b00cdb151aa20d96a0ce7a5f1a8bbe9c9 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 12 Jan 2023 11:46:40 +0300 Subject: Telegram: parse_mode=html --- .../juick/util/formatters/PlainTextFormatter.java | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/main/java/com/juick/util/formatters') diff --git a/src/main/java/com/juick/util/formatters/PlainTextFormatter.java b/src/main/java/com/juick/util/formatters/PlainTextFormatter.java index 83feb8a6..b1b1a44a 100644 --- a/src/main/java/com/juick/util/formatters/PlainTextFormatter.java +++ b/src/main/java/com/juick/util/formatters/PlainTextFormatter.java @@ -31,25 +31,20 @@ import java.util.Locale; public class PlainTextFormatter { static PrettyTime pt = new PrettyTime(new Locale("en")); - public static String formatPost(Message jmsg) { - return formatPost(jmsg, false); + public static String formatPost(Message jmsg, String domain) { + return formatPost(jmsg, false, domain); } - public static String formatPost(Message jmsg, boolean markdown) { + public static String formatPost(Message jmsg, boolean compatibleWithDurov, String domain) { StringBuilder sb = new StringBuilder(); String title = MessageUtils.isReply(jmsg) ? "Reply by @" : MessageUtils.isPM(jmsg) ? "Private message from @" : "@"; - String subtitle = MessageUtils.isReply(jmsg) ? markdown ? MessageUtils.escapeMarkdown(StringUtils.defaultString(jmsg.getReplyQuote())) - : jmsg.getReplyQuote() - : markdown ? MessageUtils.getMessageHashTags(jmsg) : MessageUtils.getTagsString(jmsg); - sb.append(title).append(markdown ? MessageUtils.getMarkdownUser(jmsg.getUser()) : jmsg.getUser().getName()).append(":\n") + String subtitle = MessageUtils.isReply(jmsg) ? jmsg.getReplyQuote() + : compatibleWithDurov ? MessageUtils.getMessageHashTags(jmsg) : MessageUtils.getTagsString(jmsg); + sb.append(title).append(compatibleWithDurov ? MessageUtils.getUserHtmlLink(jmsg.getUser(), domain) : jmsg.getUser().getName()).append(":\n") .append(subtitle).append("\n"); - if (markdown) { - sb.append(MessageUtils.formatMarkdownText(jmsg)); - } else { - sb.append(StringUtils.defaultString(jmsg.getText())); - } + sb.append(compatibleWithDurov? MessageUtils.formatMessage(jmsg.getText(), true) : StringUtils.defaultString(jmsg.getText())); sb.append("\n"); - if (!markdown && StringUtils.isNotEmpty(jmsg.getAttachmentType())) { + if (!compatibleWithDurov && StringUtils.isNotEmpty(jmsg.getAttachmentType())) { sb.append(MessageUtils.attachmentUrl(jmsg)); } return sb.toString(); -- cgit v1.2.3