From e2e3549ddc640ae58206bb8333dae8e869ba671e Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Wed, 22 May 2019 14:12:23 +0000 Subject: [PATCH] Bug #16673, News Feed: comments with links between parenthesis not recognised and Bug #16724 git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@179511 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 8 +- .project | 11 ++ .../com.gwtplugins.gdt.eclipse.core.prefs | 4 + .settings/org.eclipse.jdt.core.prefs | 1 + .settings/org.eclipse.wst.common.component | 2 +- ....eclipse.wst.common.project.facet.core.xml | 1 + distro/changelog.xml | 5 + pom.xml | 3 +- .../client/ui/AddCommentTemplate.java | 4 - .../newsfeed/client/ui/TweetTemplate.java | 121 +++++++++--------- .../user/newsfeed/server/NewsServiceImpl.java | 40 +++--- src/main/resources/clientlog4j.properties | 2 + 12 files changed, 110 insertions(+), 92 deletions(-) create mode 100644 .settings/com.gwtplugins.gdt.eclipse.core.prefs diff --git a/.classpath b/.classpath index 905334c..47f9d23 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -15,11 +15,13 @@ + + @@ -39,5 +41,5 @@ - + diff --git a/.project b/.project index 2a10994..3bd6a13 100644 --- a/.project +++ b/.project @@ -40,6 +40,16 @@ + + com.gwtplugins.gdt.eclipse.core.webAppProjectValidator + + + + + com.gwtplugins.gwt.eclipse.core.gwtProjectValidator + + + org.eclipse.m2e.core.maven2Builder @@ -56,5 +66,6 @@ org.eclipse.wst.jsdt.core.jsNature com.google.gwt.eclipse.core.gwtNature com.liferay.ide.core.liferayNature + com.gwtplugins.gwt.eclipse.core.gwtNature diff --git a/.settings/com.gwtplugins.gdt.eclipse.core.prefs b/.settings/com.gwtplugins.gdt.eclipse.core.prefs new file mode 100644 index 0000000..b5e46b5 --- /dev/null +++ b/.settings/com.gwtplugins.gdt.eclipse.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +lastWarOutDir=/Users/massi/Documents/workspace/news-feed/target/news-feed-2.8.0-SNAPSHOT +warSrcDir=src/main/webapp +warSrcDirIsOutput=false diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 672496e..8445b6b 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -9,4 +9,5 @@ org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 37ef0e0..ecd5910 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,5 @@ - + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index dade01f..b6f63a3 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -6,4 +6,5 @@ + diff --git a/distro/changelog.xml b/distro/changelog.xml index d12481b..1c63ffc 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,9 @@ + + Bug #16724, Social networking: "See more" seems to reload a post with part of the old look and feel + Bug #16673, News Feed: comments with links between parenthesis not recognised + Feature #16205: News Feed avoid refresh page when user is commenting diff --git a/pom.xml b/pom.xml index b22af09..5394221 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portlets.user news-feed war - 2.7.2-SNAPSHOT + 2.8.0-SNAPSHOT gCube News Feed Portlet @@ -255,7 +255,6 @@ com.sun.mail javax.mail - 1.5.2 provided diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.java index 7ce1b08..a1bc3e4 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.java @@ -144,10 +144,6 @@ public class AddCommentTemplate extends Composite { @UiHandler("submitButton") void onSubmitClick(ClickEvent e) { String userComment = commentTextArea.getText().trim(); - if (! checkTextLength(userComment)) { - Window.alert("We found a single word containing more than 50 chars and it's not a link, is it meaningful?"); - return; - } if (userComment.equals(COMMENT_TEXT) || userComment.equals(ERROR_UPDATE_TEXT) || userComment.equals("")) { commentTextArea.addStyleName("nwfeed-error"); commentTextArea.setText(ERROR_UPDATE_TEXT); diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.java index 472bb11..045d75e 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.java @@ -64,7 +64,7 @@ public class TweetTemplate extends Composite { public static final String loading = GWT.getModuleBaseURL() + "../images/loading-comments.gif"; - private static final int MAX_SHOWTEXT_LENGTH = 512; + private static final int MAX_SHOWTEXT_LENGTH = 612; private EnhancedFeed myPost; private UserInfo myUserInfo; @@ -148,7 +148,7 @@ public class TweetTemplate extends Composite { this.separator.setVisible(false); this.myPost = myPost; isAppPost = myPost.getFeed().isApplicationFeed(); - Feed feed = myPost.getFeed(); + Feed post = myPost.getFeed(); this.eventBus = eventBus; this.isUsers = myPost.isUsers(); this.carousel = new Carousel(); @@ -162,24 +162,24 @@ public class TweetTemplate extends Composite { } // if there is one attachment or a link preview, maintain backward compatibility - if (feed.getUri() != null && feed.getUri().compareTo("") != 0 && feed.getLinkTitle() != null && feed.getLinkTitle().compareTo("") != 0 && !feed.isMultiFileUpload()) { + if (post.getUri() != null && post.getUri().compareTo("") != 0 && post.getLinkTitle() != null && post.getLinkTitle().compareTo("") != 0 && !post.isMultiFileUpload()) { // hide the attachments panel attachmentPreviewPanel.setVisible(false); - LinkPreviewer linkPreviewer = new LinkPreviewer(feed.getLinkTitle(), feed.getLinkDescription(), feed.getLinkHost(), feed.getUriThumbnail(), feed.getUri()); + LinkPreviewer linkPreviewer = new LinkPreviewer(post.getLinkTitle(), post.getLinkDescription(), post.getLinkHost(), post.getUriThumbnail(), post.getUri()); // enable the image previewer if it is an image (mime) - if(feed.getLinkHost().contains("image/")){ + if(post.getLinkHost().contains("image/")){ ArrayList listOfEnhancedImages; EnhancedImage enhancedImage = new EnhancedImage( - feed.getUri(), - feed.getLinkTitle() + - " (" + feed.getLinkDescription() + ", type:" + feed.getLinkHost() +")", - feed.getLinkTitle(), - feed.getUri() + post.getUri(), + post.getLinkTitle() + + " (" + post.getLinkDescription() + ", type:" + post.getLinkHost() +")", + post.getLinkTitle(), + post.getUri() ); listOfEnhancedImages = new ArrayList(); @@ -200,7 +200,7 @@ public class TweetTemplate extends Composite { } // in case there are attachments, we have to fill attachmentPreviewPanel instead of the previewPanel - if(feed.isMultiFileUpload()){ + if(post.isMultiFileUpload()){ // set style to the attachment container attachmentPreviewPanel.setStyleName("attachment-preview-container"); @@ -213,12 +213,12 @@ public class TweetTemplate extends Composite { // remember that one attachment is stored in the fields: uri, uriThumbnail, linkTitle, linkDescription, linkHost Attachment firstAttachment = new Attachment( - feed.getKey(), // it is meaningless but it's needed - feed.getUri(), - feed.getLinkTitle(), - feed.getLinkDescription(), - feed.getUriThumbnail(), - feed.getLinkHost()); + post.getKey(), // it is meaningless but it's needed + post.getUri(), + post.getLinkTitle(), + post.getLinkDescription(), + post.getUriThumbnail(), + post.getLinkHost()); // create first attachment previewer and pass it the carousel AttachmentPreviewer firstAttachmentPreviewer = new AttachmentPreviewer(firstAttachment); @@ -230,11 +230,11 @@ public class TweetTemplate extends Composite { if(firstAttachment.getMimeType().contains("image/")){ EnhancedImage enhancedImage = new EnhancedImage( - feed.getUri(), - feed.getLinkTitle() + - " (" + feed.getLinkDescription() + ", type:" + feed.getLinkHost() +")", - feed.getLinkTitle(), - feed.getUri() + post.getUri(), + post.getLinkTitle() + + " (" + post.getLinkDescription() + ", type:" + post.getLinkHost() +")", + post.getLinkTitle(), + post.getUri() ); listOfEnhancedImages.add(enhancedImage); @@ -258,7 +258,7 @@ public class TweetTemplate extends Composite { EnhancedImage enhancedImage = new EnhancedImage( otherAttachment.getUri(), otherAttachment.getName() + - " (" + otherAttachment.getDescription() + ", type:" + feed.getLinkHost() +")", + " (" + otherAttachment.getDescription() + ", type:" + post.getLinkHost() +")", otherAttachment.getName(), otherAttachment.getUri() ); @@ -296,30 +296,30 @@ public class TweetTemplate extends Composite { commentArea.setHTML("" + NewsFeedPanel.COMMENT_LABEL + ""); - String feedText = feed.getDescription(); - String descWithoutHTML = new HTML(feedText).getText(); + String postText = post.getDescription(); + String descWithoutHTML = new HTML(postText).getText(); - if ( (! feedText.startsWith(" MAX_SHOWTEXT_LENGTH && !displaySingle) { - final int TEXT_TO_SHOW_LENGHT = (descWithoutHTML.length() < 500) ? (feedText.length() - (feedText.length() / 3)) : 500; - feedText = feedText.substring(0, TEXT_TO_SHOW_LENGHT) + "..."; + if ( (! postText.startsWith(" MAX_SHOWTEXT_LENGTH && !displaySingle) { + final int TEXT_TO_SHOW_LENGHT = (descWithoutHTML.length() < 600) ? (postText.length() - (postText.length() / 3)) : 600; + postText = postText.substring(0, TEXT_TO_SHOW_LENGHT) + "..."; seeMore.setHTML(" See More "); } - avatarImage.setUrl(feed.getThumbnailURL()); + avatarImage.setUrl(post.getThumbnailURL()); avatarImage.setPixelSize(40, 40); //replace the < & and > - feedText = feedText.replaceAll("<","<").replaceAll(">",">"); - feedText = feedText.replaceAll("&","&"); + postText = postText.replaceAll("<","<").replaceAll(">",">"); + postText = postText.replaceAll("&","&"); final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + NewsFeedPanel.extractOrgFriendlyURL(Location.getHref()) +GCubePortalConstants.USER_PROFILE_FRIENDLY_URL; - if (showTimelineSource && feed.getVreid() != null && feed.getVreid().compareTo("") != 0) { + if (showTimelineSource && post.getVreid() != null && post.getVreid().compareTo("") != 0) { this.vreSourceInMetadata.setVisible(true); this.separator.setVisible(true); - String vreName = feed.getVreid().substring(feed.getVreid().lastIndexOf("/")+1); + String vreName = post.getVreid().substring(post.getVreid().lastIndexOf("/")+1); vreSourceInMetadata.setText(vreName); vreSourceInMetadata.addClickHandler(new ClickHandler() { @Override @@ -334,32 +334,32 @@ public class TweetTemplate extends Composite { postOwnerArea.setHTML(""+feed.getFullName()+""); - contentArea.setHTML(feedText); + Encoder.encode(post.getEntityId())+"\">"+post.getFullName()+""); + contentArea.setHTML(postText); //check if the user has his own avatar - if (feed.getThumbnailURL().contains("img_id=0") || !feed.getThumbnailURL().contains("?")) { //it means no avatar is set + if (post.getThumbnailURL().contains("img_id=0") || !post.getThumbnailURL().contains("?")) { //it means no avatar is set avatarImage.setVisible(false); String f = "A"; String s = "Z"; - if (feed.getFullName() != null) { - String[] parts = feed.getFullName().split("\\s"); + if (post.getFullName() != null) { + String[] parts = post.getFullName().split("\\s"); if (parts.length > 0) { f = parts[0].toUpperCase(); s = parts[parts.length-1].toUpperCase(); } else { - f = feed.getFullName().substring(0,1); - s = feed.getFullName().substring(1,2); + f = post.getFullName().substring(0,1); + s = post.getFullName().substring(1,2); } } - avatarReplacement.setInitials(feed.getEntityId(), f, s); + avatarReplacement.setInitials(post.getEntityId(), f, s); avatarReplacement.setVisible(true); } } else { // messageSeparator.setVisible(false); - postOwnerArea.setHTML(""+feed.getFullName()+""); - contentArea.setHTML(feedText); + postOwnerArea.setHTML(""+post.getFullName()+""); + contentArea.setHTML(postText); if (isAppPost) { if (myUserInfo.isAdmin()) @@ -374,25 +374,25 @@ public class TweetTemplate extends Composite { Date now = new Date(); String formattedTime; // TODO java.util.Calendar is not yet available in GWT - if(now.getYear() != feed.getTime().getYear()) - formattedTime = DateTimeFormat.getFormat("MMMM dd yyyy, h:mm a").format(feed.getTime()); + if(now.getYear() != post.getTime().getYear()) + formattedTime = DateTimeFormat.getFormat("MMMM dd yyyy, h:mm a").format(post.getTime()); else - formattedTime = DateTimeFormat.getFormat("MMMM dd, h:mm a").format(feed.getTime()); + formattedTime = DateTimeFormat.getFormat("MMMM dd, h:mm a").format(post.getTime()); timeArea.setText(formattedTime); - String formattedTimeWithYear = DateTimeFormat.getFormat("dd MMMM yyyy h:mm a ").format(feed.getTime()); + String formattedTimeWithYear = DateTimeFormat.getFormat("dd MMMM yyyy h:mm a ").format(post.getTime()); timeArea.setTitle(formattedTimeWithYear); - if (! feed.getCommentsNo().equals("0")) { + if (! post.getCommentsNo().equals("0")) { commentsNo.setVisible(true); - commentsNo.setText(feed.getCommentsNo()); - commentsNo.setTitle(feed.getCommentsNo() + " people commented this."); + commentsNo.setText(post.getCommentsNo()); + commentsNo.setTitle(post.getCommentsNo() + " people commented this."); } - if (! feed.getLikesNo().equals("0")) { + if (! post.getLikesNo().equals("0")) { likesNo.setVisible(true); - likesNo.setText(feed.getLikesNo()); + likesNo.setText(post.getLikesNo()); likesNo.setTitle("Show People who have " + NewsFeedPanel.LIKED_LABEL + " this."); } - totalComments = Integer.parseInt(feed.getCommentsNo()); + totalComments = Integer.parseInt(post.getCommentsNo()); } catch (NumberFormatException e) { totalComments = 0; @@ -462,19 +462,12 @@ public class TweetTemplate extends Composite { @UiHandler("seeMore") void onSeeMoreClick(ClickEvent e) { - String feedText = myPost.getFeed().getDescription(); + String postText = myPost.getFeed().getDescription(); //replace the < & and > - feedText = feedText.replaceAll("<","<").replaceAll(">",">"); - feedText = feedText.replaceAll("&","&"); - - final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + NewsFeedPanel.extractOrgFriendlyURL(Location.getHref()) +GCubePortalConstants.USER_PROFILE_FRIENDLY_URL; - - - contentArea.setHTML(""+ - myPost.getFeed().getFullName()+" " + feedText); + postText = postText.replaceAll("<","<").replaceAll(">",">"); + postText = postText.replaceAll("&","&"); + contentArea.setHTML(postText); seeMore.setHTML(""); } diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java index 0ec4849..f334882 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java @@ -55,6 +55,7 @@ import org.gcube.portlets.widgets.pickitem.shared.ItemBean; import org.gcube.social_networking.socialutillibrary.Utils; import org.gcube.socialnetworking.social_data_search_client.ElasticSearchClient; import org.gcube.socialnetworking.social_data_search_client.ElasticSearchClientImpl; +import org.gcube.socialnetworking.socialtoken.SocialMessageParser; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.RoleManager; import org.gcube.vomanagement.usermanagement.UserManager; @@ -390,7 +391,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService List enhancedFeeds = escl.search(query, vres, from, quantity); // retrieve the ids of liked posts by the user - List likedFeeds = store.getAllLikedFeedIdsByUser(userName); + List likedPosts = store.getAllLikedFeedIdsByUser(userName); // update fields "liked" and "isuser" for (EnhancedFeed enhancedFeed : enhancedFeeds) { @@ -398,7 +399,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService if(isUsers(enhancedFeed.getFeed(), userName)) enhancedFeed.setUsers(true); - if(likedFeeds.contains(enhancedFeed.getFeed().getKey())) + if(likedPosts.contains(enhancedFeed.getFeed().getKey())) enhancedFeed.setLiked(true); } @@ -575,7 +576,12 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService currScope, new SocialNetworkingUser(username, user.getEmailaddress(), user.getFullName(), user.getAvatarId()), APP_ID); - boolean nResult = nm.notifyLikedPost(postOwnerId, postid, Utils.escapeHtml(postText)); + + ArrayList mentionedUsers = new ArrayList<>(); + SocialMessageParser messageParser = new SocialMessageParser(postText); + String siteLandingPagePath = PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest()); + String escapedPostText = messageParser.getParsedMessage(mentionedUsers, siteLandingPagePath); + boolean nResult = nm.notifyLikedPost(postOwnerId, postid, escapedPostText); _log.trace("Like Notification added? " + nResult); } } @@ -615,22 +621,20 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService return new OperationResult(false, "Session Expired", null); } - String escapedCommentText = Utils.escapeHtmlAndTransformUrl(commentText); + ArrayList mentionedUsers = new ArrayList<>(); + if (mentionedItemsSet != null && mentionedItemsSet.size() > 0) { + //copy the set into a list + ArrayList mentionedItems = new ArrayList(); + mentionedItems.addAll(mentionedItemsSet); + if (mentionedItemsSet != null && ! mentionedItemsSet.isEmpty()) { + mentionedUsers = getMentionsBean(mentionedItems); + } + } - // get hashtags - List hashtags = Utils.getHashTags(escapedCommentText); - if (hashtags != null && !hashtags.isEmpty()) - escapedCommentText = Utils.convertHashtagsAnchorHTML(escapedCommentText, hashtags); - - //copy the set into a list - ArrayList mentionedItems = new ArrayList(); - mentionedItems.addAll(mentionedItemsSet); - - ArrayList mentionedUsers = null; - if (mentionedItemsSet != null && ! mentionedItemsSet.isEmpty()) { - mentionedUsers = getMentionsBean(mentionedItems); - escapedCommentText = Utils.convertMentionPeopleAnchorHTML(escapedCommentText, mentionedUsers, getThreadLocalRequest()); - } + SocialMessageParser messageParser = new SocialMessageParser(commentText); + String siteLandingPagePath = PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest()); + String escapedCommentText = messageParser.getParsedMessage(mentionedUsers, siteLandingPagePath); + List hashtags = messageParser.getHashtags(); Comment comment = new Comment(UUID.randomUUID().toString(), user.getUsername(), new Date(), feedid, escapedCommentText, user.getFullName(), user.getAvatarId()); diff --git a/src/main/resources/clientlog4j.properties b/src/main/resources/clientlog4j.properties index 03ab7ba..a56e901 100644 --- a/src/main/resources/clientlog4j.properties +++ b/src/main/resources/clientlog4j.properties @@ -26,6 +26,7 @@ log4j.logger.org.apache.jasper.compiler.TldLocationsCache.level=ERROR, CA #AVOID LOGGING EHCACHE Hearbeat problem log4j.logger.net.sf.ehcache.distribution.PayloadUtil=OFF, CA +log4j.logger.org.eclipse.jetty=ERROR, CA log4j.logger.org.gcube.portal.notifications=INFO, CA log4j.logger.org.gcube.common.scope.impl=INFO, CA log4j.logger.org.gcube.common.core.utils.events=INFO, CA @@ -38,3 +39,4 @@ log4j.logger.com.couchbase.client=ERROR, CA log4j.logger.org.gcube.smartgears.handlers=INFO, CA log4j.logger.org.gcube.informationsystem.publisher=INFO, CA log4j.logger.org.gcube.application.framework.core.session=INFO, CA +