diff options
author | 2018-01-05 12:48:04 +0300 | |
---|---|---|
committer | 2018-01-05 12:48:04 +0300 | |
commit | 0dc51d8768cba03ecff82a5c0dc8c7ece695af6b (patch) | |
tree | d25697f4311604b35fdb23f9d67f8d1c0ffb46bb /juick-core | |
parent | a5dd9d33e7ef2acffbf8a7e3c1fc5e32767b377c (diff) |
formatHtml
Diffstat (limited to 'juick-core')
-rw-r--r-- | juick-core/src/main/java/com/juick/util/MessageUtils.java | 27 |
1 files changed, 27 insertions, 0 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 03b677d4..91cc7870 100644 --- a/juick-core/src/main/java/com/juick/util/MessageUtils.java +++ b/juick-core/src/main/java/com/juick/util/MessageUtils.java @@ -143,6 +143,33 @@ public class MessageUtils { return msg; } + public static String formatHtml(Message jmsg) { + StringBuilder sb = new StringBuilder(); + boolean isReply = jmsg.getRid() > 0; + String title = isReply ? "<h3>Reply by @" : "@"; + String subtitle = isReply ? "<q>" + jmsg.getReplyQuote() + "</q>" : "<i>" + jmsg.getTagsString() + "</i>"; + boolean isCode = jmsg.getTags().stream().anyMatch(t -> t.getName().equals("code")); + + sb.append(title).append(jmsg.getUser().getName()).append(":</h3></br/>") + .append(subtitle).append("<br/>") + .append(isCode ? formatMessageCode(jmsg.getText()) : formatMessage(jmsg.getText())).append("<br />"); + if (StringUtils.isNotEmpty(jmsg.getAttachmentType())) { + // FIXME: attachment does not serialized to xml + if (jmsg.getAttachment() == null) { + if (jmsg.getRid() > 0) { + sb.append(String.format("<img src=\"http://i.juick.com/photos-1024/%d-%d.%s\" />", jmsg.getMid(), + jmsg.getRid(), jmsg.getAttachmentType())); + } else { + sb.append(String.format("<img src=\"http://i.juick.com/photos-1024/%d.%s\" />", jmsg.getMid(), + jmsg.getAttachmentType())); + } + } else { + sb.append("<img src=\"").append(jmsg.getAttachment().getMedium().getUrl()).append("\" />"); + } + } + return sb.toString(); + } + public static String getMessageHashTags(final Message jmsg) { StringBuilder hashtags = new StringBuilder(); for (Tag tag : jmsg.getTags()) { |