From 0dc51d8768cba03ecff82a5c0dc8c7ece695af6b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 5 Jan 2018 12:48:04 +0300 Subject: formatHtml --- .../src/main/java/com/juick/util/MessageUtils.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'juick-core/src') 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 ? "

Reply by @" : "@"; + String subtitle = isReply ? "" + jmsg.getReplyQuote() + "" : "" + jmsg.getTagsString() + ""; + boolean isCode = jmsg.getTags().stream().anyMatch(t -> t.getName().equals("code")); + + sb.append(title).append(jmsg.getUser().getName()).append(":


") + .append(subtitle).append("
") + .append(isCode ? formatMessageCode(jmsg.getText()) : formatMessage(jmsg.getText())).append("
"); + if (StringUtils.isNotEmpty(jmsg.getAttachmentType())) { + // FIXME: attachment does not serialized to xml + if (jmsg.getAttachment() == null) { + if (jmsg.getRid() > 0) { + sb.append(String.format("", jmsg.getMid(), + jmsg.getRid(), jmsg.getAttachmentType())); + } else { + sb.append(String.format("", jmsg.getMid(), + jmsg.getAttachmentType())); + } + } else { + sb.append(""); + } + } + return sb.toString(); + } + public static String getMessageHashTags(final Message jmsg) { StringBuilder hashtags = new StringBuilder(); for (Tag tag : jmsg.getTags()) { -- cgit v1.2.3