diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/view/ShareUpdateForm.java b/src/main/java/org/gcube/portlets/user/shareupdates/client/view/ShareUpdateForm.java index fe3165d..354e563 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/client/view/ShareUpdateForm.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/view/ShareUpdateForm.java @@ -61,7 +61,7 @@ public class ShareUpdateForm extends Composite { // the label for all Vres/channels private final static String ALL_VRES = "Share with: your Virtual Research Environments"; - protected final static String SHARE_UPDATE_TEXT = "Share an update or paste a link, use “@” to mention someone"; + protected final static String SHARE_UPDATE_TEXT = "Share an update or a link, use “@” to mention and “#” to categorize"; protected final static String ERROR_UPDATE_TEXT = "Looks like empty to me!"; public final static String NO_TEXT_FILE_SHARE = "_N0_73X7_SH4R3_"; private final static String LISTBOX_LEVEL = " - "; @@ -281,6 +281,7 @@ public class ShareUpdateForm extends Composite { } LinkPreview preview2Share = new LinkPreview(linkTitle, linkDescription, linkUrl, linkHost, null); boolean notifyGroup = notifyListbox.getSelectedIndex() > 0; + shareupdateService.share(toShare, FeedType.TWEET, getPrivacyLevel(), vreId, preview2Share, linkUrlThumbnail, mentionedUsers, fileName, filePath, notifyGroup, new AsyncCallback() { public void onFailure(Throwable caught) { submitButton.setEnabled(true); diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/view/SuperPosedTextArea.java b/src/main/java/org/gcube/portlets/user/shareupdates/client/view/SuperPosedTextArea.java index 416557e..b158682 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/client/view/SuperPosedTextArea.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/view/SuperPosedTextArea.java @@ -51,7 +51,8 @@ public class SuperPosedTextArea extends TextArea { shareupdateService.getPortalUsers(new AsyncCallback>() { @Override public void onSuccess(ArrayList users) { - pickUserDlg = new PickItemsDialog('@', users, eventBus, 525, true); + pickUserDlg = new PickItemsDialog('@', users, eventBus, 525); + pickUserDlg.withPhoto(); } @Override public void onFailure(Throwable caught) { @@ -61,7 +62,8 @@ public class SuperPosedTextArea extends TextArea { shareupdateService.getHashtags(new AsyncCallback>() { @Override public void onSuccess(ArrayList hashtags) { - pickHashtagDlg = new PickItemsDialog('#', hashtags, eventBus, 525, false); + pickHashtagDlg = new PickItemsDialog('#', hashtags, eventBus, 525); + pickHashtagDlg.withTriggerCharIncluded(); } @Override public void onFailure(Throwable caught) { @@ -168,7 +170,6 @@ public class SuperPosedTextArea extends TextArea { String triggerChar = event.getTriggerChar(); String toAdd = event.getSelectedItem().getAlternativeName(); if (triggerChar.compareTo("#") == 0) { //has to be treated differently becase the # char remain present in the text unlike the @ - toAdd = "#"+toAdd; hashtags.add(toAdd); int tPos = getText().lastIndexOf(triggerChar); diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java index 4354d0b..d786fa1 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java @@ -7,9 +7,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -56,7 +54,6 @@ import org.gcube.vomanagement.usermanagement.model.UserModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gwt.core.ext.linker.LinkerOrder.Order; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; @@ -119,7 +116,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar } public String getDevelopmentUser() { String user = TEST_USER; - user = "massimiliano.assante"; + //user = "massimiliano.assante"; return user; } /** @@ -136,7 +133,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar return false; } } - + /** * */ @@ -144,7 +141,11 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar String vreId, LinkPreview preview, String urlThumbnail, ArrayList mentionedUserFullNames,String fileName, String filePathOnServer, boolean notifyGroup) { String escapedFeedText = TextTransfromUtils.escapeHtmlAndTransformUrl(postText); - + + List hashtags = TextTransfromUtils.getHashTags(postText); + if (hashtags != null && !hashtags.isEmpty()) + escapedFeedText = TextTransfromUtils.convertHashtagsAnchorHTML(escapedFeedText, hashtags); + ArrayList mentionedUsers = null; if (mentionedUserFullNames != null && ! mentionedUserFullNames.isEmpty()) { mentionedUsers = getSelectedUserIds(mentionedUserFullNames); @@ -200,7 +201,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar _log.info("Attempting to save Feed with text: " + textToPost + " Level: " + pLevel + " Timeline="+vreScope2Set); boolean result = store.saveUserFeed(toShare); - + //need to put the feed into VRES Timeline too if (pLevel == PrivacyLevel.VRES) { _log.trace("PrivacyLevel was set to VRES attempting to write onto User's VRES Timelines"); @@ -221,6 +222,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar _log.trace("Attempting to write onto " + vreScope2Set); try { store.saveFeedToVRETimeline(toShare.getKey(), vreScope2Set); + store.saveHashTags(toShare.getKey(), vreScope2Set, hashtags); } catch (FeedIDNotFoundException e) { _log.error("Error writing onto VRES Time Line" + vreScope2Set); } //save the feed @@ -599,7 +601,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar Collections.sort(toSort, Collections.reverseOrder()); ArrayList toReturn = new ArrayList<>(); for (HashTagAndOccurrence wrapper : toSort) { - String hashtag = wrapper.getHashtag().substring(1); + String hashtag = wrapper.getHashtag(); toReturn.add(new ItemBean(hashtag, hashtag, hashtag, null)); _log.trace(hashtag); } diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/TextTransfromUtils.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/TextTransfromUtils.java index 8604b0f..97a367d 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/TextTransfromUtils.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/TextTransfromUtils.java @@ -8,6 +8,10 @@ import java.net.URL; import java.net.URLConnection; import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; @@ -56,7 +60,7 @@ public class TextTransfromUtils { * @param taggedPeople * @return */ - protected static String convertMentionPeopleAnchorHTML(String escapedFeedText, ArrayList taggedPeople) { + protected static String convertMentionPeopleAnchorHTML(String escapedFeedText, List taggedPeople) { for (ItemBean tagged : taggedPeople) { String taggedHTML = " getHashTags(String postText) { + List hashtags = new ArrayList<>(); + Pattern MY_PATTERN = Pattern.compile("#(\\w+)"); + Matcher matcher = MY_PATTERN.matcher(postText); + while (matcher.find()) { + hashtags.add("#"+matcher.group(1)); + } + return hashtags; + } + /** + * convert the hashtag in HTML anchor and also Encode the params Base64 + * @param escapedFeedText + * @param hashtags + * @return + */ + protected static String convertHashtagsAnchorHTML(String escapedFeedText, List hashtags) { + for (String hashtag : hashtags) { + String taggedHTML = ""+hashtag+""; + + //dirty trick: double replace because \\boundaries do not accept # char + final String placeholder = "TO_REPLACE_4321234"; + String first = escapedFeedText.replaceAll("(?i)\\b"+hashtag.substring(1)+"\\b", placeholder); + escapedFeedText = first.replaceAll("#"+placeholder, taggedHTML); + } + return escapedFeedText; + } /** * generate the description parsing the content (Best Guess) @@ -102,6 +140,7 @@ public class TextTransfromUtils { toReturn = toReturn.replaceAll("\\s\\s","  "); return toReturn; } + /** * utility method that extract an url ina text when you paste a link * @param feedText @@ -368,4 +407,6 @@ public class TextTransfromUtils { System.out.println("Error" + e); } } + + }