diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java index c87a638..76a4edc 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java @@ -54,12 +54,18 @@ public class SocialMailingUtil { List comments, String commentKey, String ... hashtags) { - String removedMarkup = notification2Save.getDescription().replaceAll("&", "&"); - removedMarkup = convertHTML2Text(removedMarkup); - removedMarkup = removedMarkup.replaceAll("(\r\n|\n)","
"); //preserve new lines - String sender = notification2Save.getSenderFullName(); + //notification2Save uri contains the absoulte path to the feed in the correct channel, e.g. /group/ustore_vre?oid=f1637958-34d0-48fc-b5ad-13b1116e389d + String pathToVRE = siteLandingPagePath + "?"; + if (notification2Save.getUri().split("\\?").length > 0) { + pathToVRE = notification2Save.getUri().split("\\?")[0]; + } + _log.debug("editing hyperlinks for mail client"); + removedMarkup = removedMarkup.replaceAll("href=\"/group/", "href=\""+portalURL + "/group/"); //because there is no indication of the portal (for mentions) + removedMarkup = removedMarkup.replace("href=\"?", "href=\""+portalURL + pathToVRE + "?"); //because there is no indication of the portal (for hashtags) + + String sender = notification2Save.getSenderFullName(); String portalHost = portalURL.replaceAll("https://", ""); portalHost = portalHost.replaceAll("http://", ""); @@ -86,11 +92,9 @@ public class SocialMailingUtil { body.append("
") .append("

").append(sender).append(" ").append(removedMarkup) // has done something - .append("

") .append(getActionLink(notification2Save, portalURL)) //Goto - .append("

") .append(attachmentsNotice) - .append(SocialMailingUtil.buildHtmlDiscussion(notification2Save, feed, comments, commentKey)) // the original discussion + .append(SocialMailingUtil.buildHtmlDiscussion(portalURL, pathToVRE, notification2Save, feed, comments, commentKey)) // the original discussion .append("

") .append("

") .append("

") @@ -376,7 +380,7 @@ public class SocialMailingUtil { if (node instanceof Element) { Element element = (Element) node; if ("a".equals(element.tagName())) { - buffer.append(" "); + buffer.append(" "); } } @@ -393,7 +397,7 @@ public class SocialMailingUtil { Element element = (Element) node; String tagName = element.tagName(); if ("a".equals(element.tagName())) { - buffer.append(" "); + buffer.append(" "); } if ("p".equals(tagName) || "br".equals(tagName)) { buffer.append("\n"); @@ -405,12 +409,12 @@ public class SocialMailingUtil { /** * Build up a discussion given the feed and its comments. * @param notification2Save - * @param feed + * @param post * @param comments * @param commentKey if not null, when building the discussion stop at this comment. * @return an html string representing the discussion */ - protected static String buildHtmlDiscussion(Notification notification2Save, Feed feed, List comments, String commentKey){ + protected static String buildHtmlDiscussion(String portalURL, String pathToVRE, Notification notification2Save, Feed post, List comments, String commentKey){ try{ @@ -424,37 +428,40 @@ public class SocialMailingUtil { Format formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm a"); // escape html - String feedTextNoHtml = convertHTML2Text(feed.getDescription()); - feedTextNoHtml = feedTextNoHtml.replaceAll("(\r\n|\n)","
"); //preserve new lines + String postTextNoHtml = post.getDescription().replaceAll("&", "&"); + postTextNoHtml = postTextNoHtml.replaceAll("href=\"/group/", "href=\""+portalURL + "/group/"); //because there is no indication of the portal (for mentions) + postTextNoHtml = postTextNoHtml.replace("href=\"?", "href=\""+portalURL + pathToVRE + "?"); //because there is no indication of the portal (for hashtags) + + // build up html post + comments if(notification2Save.getType() == NotificationType.POST_ALERT || (comments.size() == 0 && notification2Save.getType() == NotificationType.MENTION)) htmlPost += "
" - + feed.getFullName() + + post.getFullName() + ": " - + (feedTextNoHtml.length() > 100 ? feedTextNoHtml.substring(0, 100) + " ..." : feedTextNoHtml) + + (postTextNoHtml.length() > 200 ? postTextNoHtml.substring(0, 200) + " ..." : postTextNoHtml) + "

" + formatter.format(feed.getTime()) + "

" + + "white-space: nowrap; font-size: smaller; color: #999;\">" + formatter.format(post.getTime()) + "

" +"
"; else htmlPost += "
" - + feed.getFullName() + + post.getFullName() + ": " - + (feedTextNoHtml.length() > 100 ? feedTextNoHtml.substring(0, 100) + " ..." : feedTextNoHtml) + + (postTextNoHtml.length() > 200 ? postTextNoHtml.substring(0, 200) + " ..." : postTextNoHtml) + "

" + formatter.format(feed.getTime()) + "

" + + "white-space: nowrap; font-size: smaller; color: #999;\">" + formatter.format(post.getTime()) + "

" +"
"; if(comments != null) for (int i = 0; i < comments.size(); i++) { String commentTextNoHtml = comments.get(i).getText().replaceAll("&", "&"); - commentTextNoHtml = convertHTML2Text(commentTextNoHtml); - commentTextNoHtml = commentTextNoHtml.replaceAll("(\r\n|\n)","
"); //preserve new lines - + commentTextNoHtml = commentTextNoHtml.replaceAll("href=\"/group/", "href=\""+portalURL + "/group/"); //because there is no indication of the portal (for mentions) + commentTextNoHtml = commentTextNoHtml.replace("href=\"?", "href=\""+portalURL + pathToVRE + "?"); //because there is no indication of the portal (for hashtags) + if((commentKey != null && comments.get(i).getKey().equals(commentKey)) && !(notification2Save.getType() == NotificationType.POST_ALERT)){ htmlPost += "
"