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
---
src/main/java/com/juick/util/MessageUtils.java | 43 ++++++++++++++++----------
1 file changed, 27 insertions(+), 16 deletions(-)
(limited to 'src/main/java/com/juick/util/MessageUtils.java')
diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java
index 0ece7249..3651540e 100644
--- a/src/main/java/com/juick/util/MessageUtils.java
+++ b/src/main/java/com/juick/util/MessageUtils.java
@@ -149,6 +149,9 @@ public class MessageUtils {
}
public static String formatMessage(String msg) {
+ return formatMessage(msg, false);
+ }
+ public static String formatMessage(String msg, boolean compatibleWithDurov) {
msg = msg.replaceAll("&", "&");
msg = msg.replaceAll("<", "<");
@@ -156,7 +159,9 @@ public class MessageUtils {
// --
// —
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1—$2");
+ if (!compatibleWithDurov) {
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1—$2");
+ }
// http://juick.com/last?page=2
// juick.com
@@ -186,20 +191,28 @@ public class MessageUtils {
// _underline_
// underline
- msg = msg.replaceAll(underlineRegex, "$1$2$3");
+ msg = msg.replaceAll(underlineRegex, "$1$2$3");
// /12
// /12
msg = msg.replaceAll(replyNumberRegex, "$1/$2$3");
+
// @username@mastodon.social
// @username@mastodon.social
- msg = msg.replaceAll(jidRegex, "$1@$2$3");
+ if (compatibleWithDurov) {
+ msg = msg.replaceAll(jidRegex, "$1@$2$3");
+ } else {
+ msg = msg.replaceAll(jidRegex, "$1@$2$3");
+ }
// @username
// @username
- msg = msg.replaceAll(usernameRegex, "$1@$2$3");
-
+ if (compatibleWithDurov) {
+ msg = msg.replaceAll(usernameRegex, "$1@$2$3");
+ } else {
+ msg = msg.replaceAll(usernameRegex, "$1@$2$3");
+ }
// (http://juick.com/last?page=2)
// (juick.com)
Matcher m = regexLinks2.matcher(msg);
@@ -211,11 +224,13 @@ public class MessageUtils {
m.appendTail(sb);
msg = sb.toString();
- // > citate
- msg = msg.replaceAll(citateRegex, "$1
");
- msg = msg.replaceAll("", "\n");
+ if (!compatibleWithDurov) {
+ // > citate
+ msg = msg.replaceAll(citateRegex, "$1
");
+ msg = msg.replaceAll("
", "\n");
- msg = msg.replaceAll("\n", "
\n");
+ msg = msg.replaceAll("\n", "
\n");
+ }
return msg;
}
@@ -259,11 +274,11 @@ public class MessageUtils {
.collect(Collectors.joining(", "));
}
- public static String getMarkdownUser(final User user) {
+ public static String getUserHtmlLink(final User user, final String webDomain) {
if (user.getUri().toASCIIString().length() > 0) {
- return String.format("[%s](%s)", user.getName(), user.getUri());
+ return String.format("%s", user.getUri(), user.getName());
} else {
- return String.format("[%s](https://juick.com/%s/)", user.getName(), user.getName());
+ return String.format("%s", webDomain, user.getName(), user.getName());
}
}
@@ -276,10 +291,6 @@ public class MessageUtils {
return StringUtils.defaultString(msg.getText())
.replaceAll(replyNumberRegex, String.format("$1[/$2](https://juick.com/m/%d#$2)$3", msg.getMid()));
}
- public static String escapeMarkdown(final String s) {
- return s.replace("_", "\\_").replace("*", "\\*")
- .replace("`", "\\`");
- }
public static String attachmentUrl(final Message jmsg) {
if (StringUtils.isEmpty(jmsg.getAttachmentType())) {
return StringUtils.EMPTY;
--
cgit v1.2.3