From af449595a0f8bf02d462fd6905fc4c5bda1e1873 Mon Sep 17 00:00:00 2001 From: "massimiliano.assante" Date: Fri, 26 Apr 2013 11:08:59 +0000 Subject: [PATCH] should not send notification if sender and receiver are the same git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerSocial@74109 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../ApplicationNotificationsManager.java | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java index 3c4e69c..0e3648b 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java @@ -57,6 +57,10 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen */ private boolean saveNotification(Notification notification2Save) { _log.trace("Trying to send notification to: " + notification2Save.getUserid() + " Type: " + notification2Save.getType()); + if (notification2Save.getSenderid().compareTo(notification2Save.getUserid()) == 0) { + _log.trace("Sender and Receiver are the same " + notification2Save.getUserid() + " Notification Stopped"); + return true; //I'm not sending notifications to the person who triggered it, pretend I sent it though + } List channels = null; try { channels = getStoreInstance().getUserNotificationChannels(notification2Save.getUserid()); @@ -73,12 +77,13 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen } if (channels.contains(NotificationChannelType.EMAIL)) EmailPlugin.sendNotification(notification2Save, aslSession.getGroupName()); - + if (channels.isEmpty()) { _log.info("Notification was not needed as the user decided not to be notified"); result = true; } return result; + } /** * return the url of the application if exists in the profile @@ -171,7 +176,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen UserManager um = new LiferayUserManager(); for (String userId : newAddedUserIds) addedUsersFullNames.append(um.getUserByScreenName(userId).getFullname()).append(" "); - + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.WP_FOLDER_ADDEDUSER, @@ -187,7 +192,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen return saveNotification(not); } - + return false; } /** @@ -339,22 +344,22 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen @Override public boolean notifyCommentReply(String userIdToNotify, String feedid, String commentText, String feedOwnerFullName) { String notificationText = (aslSession.getUserFullName().compareTo(feedOwnerFullName) == 0) ? - "also commented on his post: " + escapeHtml(commentText) - : + "also commented on his post: " + escapeHtml(commentText) + : "also commented on " + feedOwnerFullName + "'s post: " + escapeHtml(commentText); - Notification not = new Notification( - UUID.randomUUID().toString(), - NotificationType.COMMENT, - userIdToNotify, //user no notify - feedid, //the post - new Date(), - "/group/data-e-infrastructure-gateway?oid="+feedid, - notificationText, - false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); - return saveNotification(not); + Notification not = new Notification( + UUID.randomUUID().toString(), + NotificationType.COMMENT, + userIdToNotify, //user no notify + feedid, //the post + new Date(), + "/group/data-e-infrastructure-gateway?oid="+feedid, + notificationText, + false, + aslSession.getUsername(), + aslSession.getUserFullName(), + aslSession.getUserAvatarId()); + return saveNotification(not); } /** * {@inheritDoc} @@ -465,10 +470,10 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen */ @Override public boolean notifyDocumentWorkflowTaskRequest(String userIdToNotify, String documentWorkflowId, String documentName, String assignedRoleName) { - + String notificationText = "in " + aslSession.getGroupName() + " you are requested to perform a new task in the Document Workflow titled: " + escapeHtml(documentName) + ". Your role is: " + assignedRoleName; - + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.DOCUMENT_WORKFLOW_STEP_REQUEST_TASK, @@ -477,10 +482,10 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen new Date(), getApplicationUrl()+"?oid="+documentWorkflowId, notificationText, - false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + false, + aslSession.getUsername(), + aslSession.getUserFullName(), + aslSession.getUserAvatarId()); return saveNotification(not); @@ -499,11 +504,11 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?oid="+documentWorkflowId, "forwarded the Document Workflow titled: " + escapeHtml(documentName) + - " from status \"" + fromStepName + "\" to status \"" + toStepName +"\". In " + aslSession.getGroupName(), - false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + " from status \"" + fromStepName + "\" to status \"" + toStepName +"\". In " + aslSession.getGroupName(), + false, + aslSession.getUsername(), + aslSession.getUserFullName(), + aslSession.getUserAvatarId()); return saveNotification(not); } @@ -543,10 +548,10 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen new Date(), getApplicationUrl()+"?oid="+documentWorkflowId, notificationText, - false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + false, + aslSession.getUsername(), + aslSession.getUserFullName(), + aslSession.getUserAvatarId()); return saveNotification(not); }