From f010d75872763547ecbe621ae3e8eb967950453f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 13 Mar 2018 15:18:03 +0300 Subject: core: cleanup unused message properties --- .../src/main/java/com/juick/util/MessageUtils.java | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'juick-core/src/main/java/com/juick/util') 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 9c156c51..ce9415ea 100644 --- a/juick-core/src/main/java/com/juick/util/MessageUtils.java +++ b/juick-core/src/main/java/com/juick/util/MessageUtils.java @@ -24,6 +24,10 @@ import org.apache.commons.lang3.StringUtils; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -148,7 +152,7 @@ public class MessageUtils { 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() + "
" : "" + getTagsString(jmsg) + ""; boolean isCode = jmsg.getTags().stream().anyMatch(t -> t.getName().equals("code")); sb.append(title).append(jmsg.getUser().getName()).append(":

") @@ -217,4 +221,40 @@ public class MessageUtils { public static boolean replyStartsWithQuote(Message msg) { return msg.getRid() > 0 && StringUtils.defaultString(msg.getText()).startsWith(">"); } + public static List parseTags(String strTags) { + List tags = new ArrayList<>(); + if (StringUtils.isNotEmpty(strTags)) { + Set tagSet = new TreeSet<>(tags); + for (String str : strTags.split(" ")) { + Tag tag = new Tag(str); + if (!tagSet.contains(tag)) { + tags.add(tag); + tagSet.add(tag); + } + } + } + return tags; + } + public static String getTagsString(Message msg) { + StringBuilder builder = new StringBuilder(); + List tags = msg.getTags(); + if (!tags.isEmpty()) { + for (Tag Tag : tags) + builder.append(" *").append(Tag.getName()); + + if (msg.FriendsOnly) + builder.append(" *friends"); + + if (msg.getPrivacy() == -2) + builder.append(" *private"); + else if (msg.getPrivacy() == -1) + builder.append(" *friends"); + else if (msg.getPrivacy() == 2) + builder.append(" *public"); + + if (msg.ReadOnly) + builder.append(" *readonly"); + } + return builder.toString(); + } } -- cgit v1.2.3