2013-04-18 16:33:45 +02:00
|
|
|
package org.gcube.portlets.user.newsfeed.server;
|
|
|
|
|
2014-04-02 15:29:51 +02:00
|
|
|
import java.util.ArrayList;
|
2013-04-18 16:33:45 +02:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
|
|
|
import org.gcube.portal.databook.server.DatabookStore;
|
|
|
|
import org.gcube.portal.databook.shared.Comment;
|
2014-04-02 15:29:51 +02:00
|
|
|
import org.gcube.portal.databook.shared.Like;
|
2013-04-18 16:33:45 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
|
2013-10-03 12:36:20 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2013-04-18 16:33:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Massimiliano Assante ISTI-CNR
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class CommentNotificationsThread implements Runnable {
|
2013-10-03 12:36:20 +02:00
|
|
|
|
|
|
|
private static final Logger _log = LoggerFactory.getLogger(CommentNotificationsThread.class);
|
2013-04-18 16:33:45 +02:00
|
|
|
|
|
|
|
String commenterUserId;
|
|
|
|
String commentedFeedId;
|
|
|
|
private String commentText;
|
|
|
|
private String feedOwnerId;
|
|
|
|
private NotificationsManager nm;
|
|
|
|
private HashSet<String> userIdsToNotify;
|
2014-04-02 15:29:51 +02:00
|
|
|
//needed to avoid sending notification twice (the user who favorited gets the notification anyways)
|
|
|
|
private ArrayList<Like> favorites;
|
2013-04-18 16:33:45 +02:00
|
|
|
|
|
|
|
|
2014-04-02 15:29:51 +02:00
|
|
|
public CommentNotificationsThread(DatabookStore storeInstance, String commenterUserId,
|
|
|
|
String commentedFeedId, String commentText, NotificationsManager nm, String feedOwnerId, ArrayList<Like> favorites) {
|
2013-04-18 16:33:45 +02:00
|
|
|
super();
|
|
|
|
this.nm = nm;
|
|
|
|
this.commenterUserId = commenterUserId;
|
|
|
|
this.commentedFeedId = commentedFeedId;
|
|
|
|
this.commentText = commentText;
|
|
|
|
this.feedOwnerId = feedOwnerId;
|
2014-04-02 15:29:51 +02:00
|
|
|
this.favorites = favorites;
|
2013-04-18 16:33:45 +02:00
|
|
|
|
|
|
|
userIdsToNotify = new HashSet<String>();
|
|
|
|
List<Comment> feedComments = storeInstance.getAllCommentByFeed(commentedFeedId);
|
|
|
|
for (Comment comment : feedComments) {
|
|
|
|
if (comment.getUserid().compareTo(commenterUserId) != 0) {
|
|
|
|
userIdsToNotify.add(comment.getUserid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//clean
|
|
|
|
//this.comments = comments;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-04-02 15:29:51 +02:00
|
|
|
String feedOwnerFullName = "";
|
2013-04-18 16:33:45 +02:00
|
|
|
UserManager um = new LiferayUserManager();
|
|
|
|
try {
|
|
|
|
feedOwnerFullName = um.getUserByScreenName(feedOwnerId).getFullname();
|
|
|
|
} catch (Exception e) {
|
|
|
|
feedOwnerFullName = feedOwnerId;
|
|
|
|
}
|
2014-04-02 15:29:51 +02:00
|
|
|
//get the list of userid who liked the post
|
|
|
|
ArrayList<String> favoriteUserIds = new ArrayList<>();
|
|
|
|
for (Like favorite : favorites) {
|
|
|
|
favoriteUserIds.add(favorite.getUserid());
|
|
|
|
}
|
|
|
|
|
2013-04-18 16:33:45 +02:00
|
|
|
if (userIdsToNotify != null) {
|
2014-04-02 15:29:51 +02:00
|
|
|
for (String userId : userIdsToNotify) {
|
|
|
|
if (userId.compareTo(feedOwnerId) != 0 && !(favoriteUserIds.contains(userId)) ) { //avoid notifying the owner and the user who liked twice
|
2014-04-04 11:47:10 +02:00
|
|
|
boolean result = nm.notifyCommentReply(userId, commentedFeedId, commentText, feedOwnerFullName, feedOwnerId);
|
2014-04-02 15:29:51 +02:00
|
|
|
_log.trace("Sending Notification for also commented to: " + feedOwnerFullName + " result?"+ result);
|
|
|
|
}
|
2013-04-18 16:33:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|