Bug #17181, post editing leads to losing both formatting and mentions

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@181247 82a268e6-3cf1-43bd-a215-b396298e98cf
Feature/26194
Massimiliano Assante 5 years ago
parent 4c6116947f
commit 241486383b

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/news-feed-2.8.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/news-feed-2.8.1-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/news-feed-2.8.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/news-feed-2.8.1-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -41,5 +41,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/news-feed-2.8.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/news-feed-2.8.1-SNAPSHOT/WEB-INF/classes"/>
</classpath>

@ -1,4 +1,4 @@
eclipse.preferences.version=1
lastWarOutDir=/Users/massi/Documents/workspace/news-feed/target/news-feed-2.8.0-SNAPSHOT
lastWarOutDir=/Users/massi/Documents/workspace/news-feed/target/news-feed-2.8.1-SNAPSHOT
warSrcDir=src/main/webapp
warSrcDirIsOutput=false

@ -8,9 +8,6 @@
<dependent-module archiveName="gcube-widgets-2.2.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="social-util-library-1.6.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/social-util-library/social-util-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="pickitem-widget-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/pickitem-widget/pickitem-widget">
<dependency-type>uses</dependency-type>
</dependent-module>

@ -1,23 +1,32 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets-user.news-feed.2-8-0"
date="2019-05-22">
<Change>Bug #16724, Social networking: "See more" seems to reload a post with part of the old look and feel</Change>
<Change>Bug #16673, News Feed: comments with links between parenthesis not recognised</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.news-feed.2-7-2"
date="2019-01-25">
<Change>Feature #16205: News Feed avoid refresh page when user is commenting</Change>
<Changeset
component="org.gcube.portlets-user.news-feed.2-8-1" date="2019-07-17">
<Change>Fixed Bug #17181, post editing leads to losing both formatting and mentions</Change>
</Changeset>
<Changeset
component="org.gcube.portlets-user.news-feed.2-8-0" date="2019-05-22">
<Change>Fixed Bug #16724, Social networking: "See more" seems to reload a
post with part of the old look and feel</Change>
<Change>Fixed Bug #16673, News Feed: comments with links between parenthesis
not recognised</Change>
</Changeset>
<Changeset
component="org.gcube.portlets-user.news-feed.2-7-2" date="2019-01-25">
<Change>Feature #16205: News Feed avoid refresh page when user is
commenting</Change>
<Change>Minor CSS fix for anchors links font size</Change>
<Change>Bug fix #16225 mentions and replies http links not working in some email notifications</Change>
<Change>Bug fix #16225 mentions and replies http links not working in
some email notifications</Change>
<Change>Feature #16452, Revise posts look and feel</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.news-feed.2-6-1"
date="2018-04-12">
<Changeset
component="org.gcube.portlets-user.news-feed.2-6-1" date="2018-04-12">
<Change>Removed previous jquery js load script and useless deprecated
pagebus</Change>
pagebus
</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.news-feed.2-6-0"
date="2018-03-07">
<Changeset
component="org.gcube.portlets-user.news-feed.2-6-0" date="2018-03-07">
<Change>Ported to GWT 2.8.2</Change>
<Change>Fix for Incident #11187 citing a people (with '@') in comments
is not working anymore
@ -29,13 +38,15 @@
<Change>Feature #10192 allow to sort feeds per recent comments
</Change>
<Change>Bug #7841 lack of blank space to separate the query term when
hashtag is used</Change>
hashtag is used
</Change>
<Change>Support for ticket #11139</Change>
<Change>Enhanced efficiency when retrieving mentioned users or groups
in comments</Change>
in comments
</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.news-feed.2-5-0"
date="2017-11-13">
<Changeset
component="org.gcube.portlets-user.news-feed.2-5-0" date="2017-11-13">
<Change>fixes for Incident #10262: Cannot see who liked posts on VREs
of Parthenos
</Change>
@ -44,8 +55,8 @@
</Change>
<Change>Ported to GWT 2.8.1</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.news-feed.2-3-0"
date="2017-02-20">
<Changeset
component="org.gcube.portlets-user.news-feed.2-3-0" date="2017-02-20">
<Change>fixes for changes to the underneath
common-notification-library
</Change>
@ -57,15 +68,15 @@
try to engage the user to post something.
</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.news-feed.2-2-0"
date="2016-12-02">
<Changeset
component="org.gcube.portlets-user.news-feed.2-2-0" date="2016-12-02">
<Change>removed asl session</Change>
<Change>Increased general performance and bugfixes</Change>
<Change>fetching of users list to mention in comments loaded on demand
</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.news-feed.2-1-0"
date="2016-10-29">
<Changeset
component="org.gcube.portlets-user.news-feed.2-1-0" date="2016-10-29">
<Change>Support to show feeds related to user's statistics added
</Change>
<Change>Fixed time for comments/posts: the year is present only if the
@ -73,34 +84,34 @@
was made before the current one
</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.news-feed.2-0-0"
date="2016-06-29">
<Changeset
component="org.gcube.portlets-user.news-feed.2-0-0" date="2016-06-29">
<Change>Updated for Liferay 6.2.5</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.news-feed.1-13-1"
date="2016-02-29">
<Changeset
component="org.gcube.portlets-user.news-feed.1-13-1" date="2016-02-29">
<Change>Full-text search supported</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.news-feed.1-13-0"
date="2016-01-22">
<Changeset
component="org.gcube.portlets-user.news-feed.1-13-0" date="2016-01-22">
<Change>Multi-attachment supported</Change>
<Change>Image preview available</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.newsfeed.1-12-0"
date="2015-11-12">
<Changeset
component="org.gcube.portlets-user.newsfeed.1-12-0" date="2015-11-12">
<Change>Fix for Bug #246, editing changes comment "metadata" namely
data
</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.newsfeed.1-11-0"
date="2015-10-12">
<Changeset
component="org.gcube.portlets-user.newsfeed.1-11-0" date="2015-10-12">
<Change>Integrated workspace explorer widget and replace light tree
</Change>
<Change>Fix for Bug #195, Post dates lack the year
</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.newsfeed.1-10-0"
date="2015-07-15">
<Changeset
component="org.gcube.portlets-user.newsfeed.1-10-0" date="2015-07-15">
<Change>Revised the way we shorten posts' text when this is very long,
better heuristic used
</Change>

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>news-feed</artifactId>
<packaging>war</packaging>
<version>2.8.0-SNAPSHOT</version>
<version>2.8.1-SNAPSHOT</version>
<name>gCube News Feed Portlet</name>
<description>

@ -49,7 +49,7 @@ public interface NewsService extends RemoteService {
HashSet<MentionedDTO> mentionedUsers, String feedOwnerId,
boolean isAppFeed);
OperationResult editComment(Comment toEdit);
OperationResult editComment(String text, Comment toEdit, HashSet<MentionedDTO> mentionedUsers);
ArrayList<Like> getAllLikesByPost(String postid);

@ -48,7 +48,7 @@ public interface NewsServiceAsync {
void deletePost(String feedid, AsyncCallback<Boolean> callback);
void editComment(Comment toEdit, AsyncCallback<OperationResult> callback);
void editComment(String text, Comment toEdit, HashSet<MentionedDTO> mentionedUsers, AsyncCallback<OperationResult> callback);
void getOnlyLikedPosts(AsyncCallback<ArrayList<EnhancedFeed>> callback);

@ -1,7 +1,10 @@
package org.gcube.portlets.user.newsfeed.client.event;
import java.util.HashSet;
import org.gcube.portal.databook.shared.Comment;
import org.gcube.portlets.user.newsfeed.client.ui.TweetTemplate;
import org.gcube.portlets.user.newsfeed.shared.MentionedDTO;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.user.client.ui.HTMLPanel;
@ -13,7 +16,9 @@ public class EditCommentEvent extends GwtEvent<EditCommentEventHandler> {
private TweetTemplate owner;
private Comment edited;
private String text;
private HTMLPanel commentPanel;
private HashSet<MentionedDTO> mentionedUsers;
public TweetTemplate getOwner() {
return owner;
@ -25,12 +30,21 @@ public class EditCommentEvent extends GwtEvent<EditCommentEventHandler> {
public HTMLPanel getCommentPanel() {
return commentPanel;
}
public EditCommentEvent(TweetTemplate owner, Comment editedComment, HTMLPanel commentPanel) {
public EditCommentEvent(TweetTemplate owner, String text, Comment editedComment, HTMLPanel commentPanel, HashSet<MentionedDTO> mentionedUsers) {
this.owner = owner;
this.text = text;
this.edited = editedComment;
this.commentPanel = commentPanel;
this.mentionedUsers = mentionedUsers;
}
public HashSet<MentionedDTO> getMentionedUsers() {
return mentionedUsers;
}
public String getText() {
return text;
}
@Override
public Type<EditCommentEventHandler> getAssociatedType() {
return TYPE;

@ -203,7 +203,7 @@ public class NewsFeedPanel extends Composite {
eventBus.addHandler(EditCommentEvent.TYPE, new EditCommentEventHandler() {
@Override
public void onEditComment(EditCommentEvent event) {
doEditComment(event.getOwner(), event.getCommentInstance(), event.getCommentPanel());
doEditComment(event.getOwner(), event.getText(), event.getCommentInstance(), event.getCommentPanel(), event.getMentionedUsers());
}
});
@ -1361,15 +1361,6 @@ public class NewsFeedPanel extends Composite {
owner.setCommentingDisabled(false);
owner.updateCommentsNumberCount();
owner.showAddCommentForm(false);
// if(owner.isUser()){
// // alert the User statistics portlet to increment the number of comments got
// try {
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsIncrement, "", Defaults.STRING_JSONIZER);
// } catch (PageBusAdapterException e) {
// GWT.log(e.toString());
// }
// }
}
}
else {
@ -1379,8 +1370,8 @@ public class NewsFeedPanel extends Composite {
});
}
private void doEditComment(final TweetTemplate owner, Comment edited, final HTMLPanel commentPanel) {
newsService.editComment(edited, new AsyncCallback<OperationResult>() {
private void doEditComment(final TweetTemplate owner, String text, Comment edited, final HTMLPanel commentPanel, HashSet<MentionedDTO> mentionedUsers) {
newsService.editComment(text, edited, mentionedUsers, new AsyncCallback<OperationResult>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Could not edit this comment: " + caught.getMessage());
@ -1390,7 +1381,7 @@ public class NewsFeedPanel extends Composite {
public void onSuccess(OperationResult result) {
if (result != null) {
if (!result.isSuccess()) {
//CheckSession.showLogoutDialog();
Window.alert("Could not deliver this comment. Please try again in a short while.");
}
else {
Comment comment = (Comment) result.getComment();

@ -83,16 +83,17 @@ public class AddCommentTemplate extends Composite {
isEditing = true;
this.toEdit = toEdit;
String commentText = new HTML(toEdit.getText()).getText();
//replace the < & and >
commentText = commentText.replaceAll("&lt;","<").replaceAll("&gt;",">");
commentText = commentText.replaceAll("&amp;","&");
String commentText = toEdit.getText().replaceAll("<br/>", "\n");
commentText = commentText.replaceAll("&nbsp;", " ");
commentText = new HTML(commentText).getText();
owner = caller;
commentTextArea.setContext(owner.getVREContext());
avatarImage.setPixelSize(30, 30);
avatarImage.setUrl(caller.getMyUserInfo().getAvatarId());
commentTextArea.setText(commentText);
mainPanel.removeStyleName("comment-hidden");
mainPanel.setStyleName("single-comment");
commentTextArea.addStyleName("comment-dark-color");
@ -106,10 +107,10 @@ public class AddCommentTemplate extends Composite {
}
};
handlerRegistration = Window.addWindowClosingHandler(closingHandler);
}
/** Used by AddCommentTemplate to instantiate SuperPosedTextArea */
@UiFactory SuperPosedTextArea build() {
@ -151,7 +152,7 @@ public class AddCommentTemplate extends Composite {
}
if (isEditing) {
toEdit.setText(escapeHtml(commentTextArea.getText()));
eventBus.fireEvent(new EditCommentEvent(owner, toEdit, commentPanel));
eventBus.fireEvent(new EditCommentEvent(owner, escapeHtml(commentTextArea.getText()), toEdit, commentPanel, commentTextArea.getMentionedUsers()));
}
else { //it is ok to add this comment
eventBus.fireEvent(new AddCommentEvent(owner, escapeHtml(commentTextArea.getText()), commentTextArea.getMentionedUsers()));
@ -159,6 +160,7 @@ public class AddCommentTemplate extends Composite {
this.getWidget().setVisible(false);
owner.setCommentingDisabled(false);
handlerRegistration.removeHandler();
GWT.log(" handlerRegistration.removeHandler();");
}

@ -14,7 +14,7 @@
</td>
<td>
<div id="comment-supercontainer">
<div id="comment-supercontainer" style="background-color: #FFF;">
<div id="comment-highlighterContainer">
<w:Div styleName="comment-highlighter" ui:field="highlighterDIV"></w:Div>
</div>

@ -735,9 +735,11 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
@Override
public OperationResult editComment(Comment toEdit) {
public OperationResult editComment(String text, Comment toEdit, HashSet<MentionedDTO> mentionedItemsSet) {
Comment edited = null;
boolean commentCommitResult = false;
try {
_log.debug("in edit Comment ... ");
UserInfo user = getUserSettings().getUserInfo();
if (user.getUsername().compareTo(NewsConstants.TEST_USER) == 0) {
return new OperationResult(false, "Session Expired", null);
@ -748,6 +750,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
// get old hashtags and delete them
String oldText = store.readCommentById(toEdit.getKey()).getText();
_log.debug("Old text for this comment is " + oldText);
System.out.println("Old text for this comment is " + oldText);
List<String> oldHashtags = Utils.getHashTags(Utils.removeHTMLFromText(oldText));
if (oldHashtags != null && !oldHashtags.isEmpty()) {
_log.debug("The comment has hashtags, attempting to delete them ... " + oldHashtags.toString());
@ -755,19 +758,94 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
_log.debug("deletedHashtag? " + deletedHashtag);
}
// get new hashtags
String escapedCommentText = Utils.escapeHtmlAndTransformUrl(toEdit.getText());
List<String> newHashtags = Utils.getHashTags(escapedCommentText);
ArrayList<ItemBean> mentionedUsers = new ArrayList<>();
if (mentionedItemsSet != null && mentionedItemsSet.size() > 0) {
//copy the set into a list
ArrayList<MentionedDTO> mentionedItems = new ArrayList<MentionedDTO>();
mentionedItems.addAll(mentionedItemsSet);
if (mentionedItemsSet != null && ! mentionedItemsSet.isEmpty()) {
mentionedUsers = getMentionsBean(mentionedItems);
}
}
SocialMessageParser messageParser = new SocialMessageParser(text);
String siteLandingPagePath = PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest());
String escapedCommentText = messageParser.getParsedMessage(mentionedUsers, siteLandingPagePath);
List<String> newHashtags = messageParser.getHashtags();
if (newHashtags != null && !newHashtags.isEmpty())
escapedCommentText = Utils.convertHashtagsAnchorHTML(escapedCommentText, newHashtags);
store.saveHashTagsComment(toEdit.getKey(), vreIdFeed, newHashtags);
// // get new hashtags
// String escapedCommentText = Utils.escapeHtmlAndTransformUrl(toEdit.getText());
// List<String> newHashtags = Utils.getHashTags(escapedCommentText);
// if (newHashtags != null && !newHashtags.isEmpty())
// escapedCommentText = Utils.convertHashtagsAnchorHTML(escapedCommentText, newHashtags);
edited = new Comment(toEdit.getKey(), toEdit.getUserid(),
toEdit.getTime(), toEdit.getFeedid(), escapedCommentText, user.getFullName(), user.getAvatarId(), true, new Date());
store.editComment(edited);
commentCommitResult = store.editComment(edited);
if (newHashtags != null && !newHashtags.isEmpty())
store.saveHashTagsComment(edited.getKey(), vreIdFeed, newHashtags);
if (commentCommitResult) {
PortalContext pContext = PortalContext.getConfiguration();
String currScope = pContext.getCurrentScope(getThreadLocalRequest());
NotificationsManager nm = new ApplicationNotificationsManager(
new SocialNetworkingSite(getThreadLocalRequest()),
currScope,
new SocialNetworkingUser(user.getUsername(), user.getEmailaddress(), user.getFullName(), user.getAvatarId()),
APP_ID);
//send the notification to the mentioned users, if any
if (mentionedUsers != null && mentionedUsers.size() > 0) {
ArrayList<GenericItemBean> toPass = new ArrayList<GenericItemBean>();
// among the mentionedUsers there could be groups of people
Map<String, ItemBean> uniqueUsersToNotify = new HashMap<>();
UserManager um = new LiferayUserManager();
for (ItemBean bean : mentionedUsers) {
if(bean.isItemGroup()){
// retrieve the users of this group
try {
List<GCubeUser> teamUsers = um.listUsersByTeam(Long.parseLong(bean.getId()));
for (GCubeUser userTeam : teamUsers) {
if(!uniqueUsersToNotify.containsKey(userTeam.getUsername()))
uniqueUsersToNotify.put(userTeam.getUsername(), new ItemBean(userTeam.getUserId()+"",
userTeam.getUsername(), userTeam.getFullname(), userTeam.getUserAvatarURL()));
}
} catch (NumberFormatException
| UserManagementSystemException
| TeamRetrievalFault | UserRetrievalFault e) {
_log.error("Unable to retrieve team information", e);
}
}else{
// it is a user, just add to the hashmap
if(!uniqueUsersToNotify.containsKey(bean.getName()))
uniqueUsersToNotify.put(bean.getName(), bean);
}
}
// iterate over the hashmap
Iterator<Entry<String, ItemBean>> userMapIterator = uniqueUsersToNotify.entrySet().iterator();
while (userMapIterator.hasNext()) {
Map.Entry<String, ItemBean> userEntry = (Map.Entry<String, ItemBean>) userMapIterator
.next();
ItemBean userBean = userEntry.getValue();
toPass.add(new GenericItemBean(userBean.getId(), userBean.getName(), userBean.getAlternativeName(), userBean.getThumbnailURL()));
}
Thread thread = new Thread(new MentionNotificationsThread(toEdit.getFeedid(), escapedCommentText, nm, null, toPass));
thread.start();
}
}
else {
return new OperationResult(false, "Exception on the server, could not deliver the edited comment to storage", null);
}
} catch (Exception e) {
e.printStackTrace();
return new OperationResult(false, "Exception on the server: " + e.getMessage(), null);

Loading…
Cancel
Save