ported to git

This commit is contained in:
Massimiliano Assante 2022-06-16 15:55:51 +02:00
parent 30d43b5f39
commit e9b94a5eff
2 changed files with 28 additions and 17 deletions

View File

@ -33,7 +33,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.6.3</version>
<version>3.6.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>

View File

@ -24,30 +24,41 @@ public class CommentNotificationsThread implements Runnable {
String commenterUserId;
String commentedFeedId;
private String commentText;
private String feedOwnerId;
private String postOwnerId;
private NotificationsManager nm;
private String commentKey;
private HashSet<String> userIdsToNotify;
//needed to avoid sending notification twice (the user who favorited gets the notification anyways)
private ArrayList<Like> favorites;
private ArrayList<Like> likes;
private UserManager userManager;
/**
*
* @param storeInstance
* @param userManager
* @param commenterUserId
* @param commentedPostId
* @param commentText
* @param nm
* @param postOwnerId
* @param commentKey
* @param likes
*/
public CommentNotificationsThread(DatabookStore storeInstance, UserManager userManager, String commenterUserId,
String commentedFeedId, String commentText, NotificationsManager nm, String feedOwnerId, String commentKey, ArrayList<Like> favorites) {
String commentedPostId, String commentText, NotificationsManager nm, String postOwnerId, String commentKey, ArrayList<Like> likes) {
super();
this.nm = nm;
this.commenterUserId = commenterUserId;
this.commentedFeedId = commentedFeedId;
this.commentedFeedId = commentedPostId;
this.commentText = commentText;
this.feedOwnerId = feedOwnerId;
this.postOwnerId = postOwnerId;
this.commentKey = commentKey;
this.favorites = favorites;
this.likes = likes;
this.userManager = userManager;
userIdsToNotify = new HashSet<String>();
List<Comment> feedComments = storeInstance.getAllCommentByFeed(commentedFeedId);
for (Comment comment : feedComments) {
List<Comment> postComments = storeInstance.getAllCommentByFeed(commentedPostId);
for (Comment comment : postComments) {
if (comment.getUserid().compareTo(commenterUserId) != 0) {
userIdsToNotify.add(comment.getUserid());
}
@ -59,23 +70,23 @@ public class CommentNotificationsThread implements Runnable {
@Override
public void run() {
String feedOwnerFullName = "";
String postOwnerFullName = "";
try {
feedOwnerFullName = userManager.getUserByUsername(feedOwnerId).getFullname();
postOwnerFullName = userManager.getUserByUsername(postOwnerId).getFullname();
} catch (Exception e) {
feedOwnerFullName = feedOwnerId;
postOwnerFullName = postOwnerId;
}
//get the list of userid who liked the post
ArrayList<String> favoriteUserIds = new ArrayList<>();
for (Like favorite : favorites) {
for (Like favorite : likes) {
favoriteUserIds.add(favorite.getUserid());
}
if (userIdsToNotify != null) {
for (String userId : userIdsToNotify) {
if (userId.compareTo(feedOwnerId) != 0 && !(favoriteUserIds.contains(userId)) ) { //avoid notifying the owner and the user who liked twice
boolean result = nm.notifyCommentReply(userId, commentedFeedId, commentText, feedOwnerFullName, feedOwnerId, commentKey);
_log.trace("Sending Notification for also commented to: " + feedOwnerFullName + " result?"+ result);
if (userId.compareTo(postOwnerId) != 0 && !(favoriteUserIds.contains(userId)) ) { //avoid notifying the owner and the user who liked twice
boolean result = nm.notifyCommentReply(userId, commentedFeedId, commentText, postOwnerFullName, postOwnerId, commentKey);
_log.trace("Sending Notification for also commented to: " + postOwnerFullName + " result?"+ result);
}
}
}