[Notice] Announcing the End of Demo Server [Read me]
doortts doortts 2018-04-10
noti: Reset user noti settings when to unwatch a project
@dc4a984280309025d86cc7104350304f8a30841f
app/controllers/WatchProjectApp.java
--- app/controllers/WatchProjectApp.java
+++ app/controllers/WatchProjectApp.java
@@ -22,6 +22,7 @@
 import utils.ErrorViews;
 
 import static models.UserProjectNotification.*;
+import static models.enumeration.ResourceType.PROJECT;
 
 @AnonymousCheck(requiresLogin = true, displaysFlashMessage = true)
 public class WatchProjectApp extends Controller {
@@ -36,9 +37,12 @@
 
     @IsAllowed(Operation.READ)
     @Transactional
-    public static Result unwatch(String userName, String projectName) {
-        Project project = Project.findByOwnerAndProjectName(userName, projectName);
+    public static Result unwatch(String loginId, String projectName) {
+        Project project = Project.findByOwnerAndProjectName(loginId, projectName);
+
         Watch.unwatch(project.asResource());
+
+        UserProjectNotification.deleteUnwatchedProjectNotifications(UserApp.currentUser(), project);
         return ok();
     }
 
app/models/UserProjectNotification.java
--- app/models/UserProjectNotification.java
+++ app/models/UserProjectNotification.java
@@ -165,4 +165,14 @@
         }
         return users;
     }
+
+    public static void deleteUnwatchedProjectNotifications(User user, Project project){
+        List<UserProjectNotification> userProjectNotifications = find.where()
+                .eq("user.id", user.id)
+                .eq("project.id", project.id)
+                .findList();
+        for (UserProjectNotification notification : userProjectNotifications) {
+            notification.delete();
+        }
+    }
 }
Add a comment
List