diff options
-rw-r--r-- | juick-api/src/main/java/com/juick/api/EmailManager.java | 4 | ||||
-rw-r--r-- | juick-core/src/main/java/com/juick/util/MessageUtils.java | 27 |
2 files changed, 28 insertions, 3 deletions
diff --git a/juick-api/src/main/java/com/juick/api/EmailManager.java b/juick-api/src/main/java/com/juick/api/EmailManager.java index af66466f..2ada6ab9 100644 --- a/juick-api/src/main/java/com/juick/api/EmailManager.java +++ b/juick-api/src/main/java/com/juick/api/EmailManager.java @@ -83,12 +83,10 @@ public class EmailManager implements ApplicationListener<MessageEvent> { StringUtils.isNotEmpty(msg.getText()) ? formatPost(msg) : "", formatUrl(msg)); MimeBodyPart textBodyPart = new MimeBodyPart(); textBodyPart.setContent(plainText, "text/plain; charset=UTF-8"); - boolean isCode = msg.getTags().stream().anyMatch(t -> t.getName().equals("code")); String htmlText = String.format("%s<br /><br />--<br />You are receiving this because you are subscribed to this user " + ", discussion or tag. Reply to this email directly or <a href=\"%s\">view it</a> on Juick." + "<br /><a href=\"https://juick.com/settings?hash=%s\">Configure or disable notifications</a>", - StringUtils.isNotEmpty(msg.getText()) ? isCode ? MessageUtils.formatMessageCode(msg.getText()) - : MessageUtils.formatMessage(msg.getText()) : "", formatUrl(msg), + StringUtils.isNotEmpty(msg.getText()) ? MessageUtils.formatHtml(msg) : "", formatUrl(msg), userService.getHashByUID(userService.getUserByEmail(email).getUid())); MimeBodyPart htmlBodyPart = new MimeBodyPart(); htmlBodyPart.setContent(htmlText, "text/html; charset=UTF-8"); 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()) { |