diff options
author | Vitaly Takmazov | 2024-10-25 07:37:45 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2024-10-25 07:37:45 +0300 |
commit | 27cc7b006ac91be9dc883adaf7ea27c46d511df9 (patch) | |
tree | 67e60b644f1790a915a544684aa5975ac2550e3b /src/main | |
parent | 353e7b8849fa6d76927c695f2bc085e0b44e22f2 (diff) |
Format quotes in the legacy Telegram bot
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/juick/util/MessageUtils.java | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java index 3c8001d8..5418ae64 100644 --- a/src/main/java/com/juick/util/MessageUtils.java +++ b/src/main/java/com/juick/util/MessageUtils.java @@ -42,13 +42,20 @@ public class MessageUtils { } public static String formatQuote(final String quote) { + return formatQuote(quote, false); + } + + public static String formatQuote(final String quote, final boolean isHtml) { String result = quote; + var prefix = isHtml ? "<blockquote>" : ">"; + var suffix = isHtml ? "</blockquote>" : "\n"; + if (quote != null) { if (quote.length() > 50) { - result = ">" + StringUtils.abbreviate(quote, "…", 47).replace('\n', ' ') + "\n"; + result = prefix + StringUtils.abbreviate(quote, "…", 47).replace('\n', ' ') + suffix; } else if (!quote.isEmpty()) { - result = ">" + quote.replace('\n', ' ') + "\n"; + result = prefix + quote.replace('\n', ' ') + suffix; } } @@ -220,11 +227,11 @@ public class MessageUtils { m.appendTail(sb); msg = sb.toString(); + + // > citate + msg = msg.replaceAll(citateRegex, "<blockquote>$1</blockquote>"); + msg = msg.replaceAll("</blockquote><blockquote>", "\n"); if (!compatibleWithDurov) { - // > citate - msg = msg.replaceAll(citateRegex, "<blockquote>$1</blockquote>"); - msg = msg.replaceAll("</blockquote><blockquote>", "\n"); - msg = msg.replaceAll("\n", "<br/>\n"); } return msg; |