diff options
author | 2018-03-13 15:18:03 +0300 | |
---|---|---|
committer | 2018-03-13 15:18:03 +0300 | |
commit | f010d75872763547ecbe621ae3e8eb967950453f (patch) | |
tree | 385d3f0a960e10c7fd054fcb71ea280142495d31 /juick-core/src/main/java/com/juick/util/MessageUtils.java | |
parent | cd7e11563721d223b30f9b9edaa8295c2c97c6f7 (diff) |
core: cleanup unused message properties
Diffstat (limited to 'juick-core/src/main/java/com/juick/util/MessageUtils.java')
-rw-r--r-- | juick-core/src/main/java/com/juick/util/MessageUtils.java | 42 |
1 files changed, 41 insertions, 1 deletions
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 ? "<b>Reply by @" : "<b>@"; - String subtitle = isReply ? "<blockquote>" + jmsg.getReplyQuote() + "</blockquote>" : "<i>" + jmsg.getTagsString() + "</i>"; + String subtitle = isReply ? "<blockquote>" + jmsg.getReplyQuote() + "</blockquote>" : "<i>" + getTagsString(jmsg) + "</i>"; boolean isCode = jmsg.getTags().stream().anyMatch(t -> t.getName().equals("code")); sb.append(title).append(jmsg.getUser().getName()).append(":</b></br/>") @@ -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<Tag> parseTags(String strTags) { + List<Tag> tags = new ArrayList<>(); + if (StringUtils.isNotEmpty(strTags)) { + Set<Tag> 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<Tag> 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(); + } } |