aboutsummaryrefslogtreecommitdiff
path: root/juick-core/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-01-17 14:38:32 +0300
committerGravatar Vitaly Takmazov2018-01-17 14:38:32 +0300
commitbe8d139d8ea58396107cf1a2b12ad16ac8bda6d6 (patch)
treeb73c449f4a87b16541bc46bd697b1cf632de2c25 /juick-core/src
parentdadfbdb7379ebe9623643902a6a0aa78ca528228 (diff)
api: markdown tags for telegram
Diffstat (limited to 'juick-core/src')
-rw-r--r--juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java6
-rw-r--r--juick-core/src/main/java/com/juick/util/MessageUtils.java5
2 files changed, 10 insertions, 1 deletions
diff --git a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
index 459384fb..0f5e0756 100644
--- a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
+++ b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
@@ -32,10 +32,14 @@ public class PlainTextFormatter {
static PrettyTime pt = new PrettyTime(new Locale("ru"));
public static String formatPost(Message jmsg) {
+ return formatPost(jmsg, false);
+ }
+
+ public static String formatPost(Message jmsg, boolean markdown) {
StringBuilder sb = new StringBuilder();
boolean isReply = jmsg.getRid() > 0;
String title = isReply ? "Reply by @" : "@";
- String subtitle = isReply ? jmsg.getReplyQuote() : jmsg.getTagsString();
+ String subtitle = isReply ? jmsg.getReplyQuote() : markdown ? MessageUtils.getMarkdownTags(jmsg) : jmsg.getTagsString();
sb.append(title).append(jmsg.getUser().getName()).append(":\n")
.append(subtitle).append("\n").append(StringUtils.defaultString(jmsg.getText())).append("\n");
if (StringUtils.isNotEmpty(jmsg.getAttachmentType())) {
diff --git a/juick-core/src/main/java/com/juick/util/MessageUtils.java b/juick-core/src/main/java/com/juick/util/MessageUtils.java
index aba718a5..6e0b47c0 100644
--- a/juick-core/src/main/java/com/juick/util/MessageUtils.java
+++ b/juick-core/src/main/java/com/juick/util/MessageUtils.java
@@ -26,6 +26,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
/**
* Created by aalexeev on 11/13/16.
@@ -178,6 +179,10 @@ public class MessageUtils {
}
return hashtags.toString();
}
+ public static String getMarkdownTags(final Message jmsg) {
+ return jmsg.getTags().stream().map(t -> String.format("[%s](http://juick.com/tag/%s)", t.getName(), percentEncode(t.getName())))
+ .collect(Collectors.joining(", "));
+ }
// TODO: check if it is really needed
public static String percentEncode(final String s) {