|
|
|
@ -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);
|
|
|
|
|