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> <dependency>
<groupId>org.gcube.distribution</groupId> <groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId> <artifactId>maven-portal-bom</artifactId>
<version>3.6.3</version> <version>3.6.4</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>

View File

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