changeset 5540:786640c577f3

notifications: mark notifications to self "pre-read" When a user e.g. comments on its own pull request, that user receives a notification about its own comment. This is slightly dubious behavior, but at least brings a level of continuity to the notification history. However, at the very least, the notification should not show as unread.
author Søren Løvborg <sorenl@unity3d.com>
date Tue, 08 Sep 2015 19:43:29 +0200
parents 87285c5007fb
children e553602fd5be
files kallithea/model/db.py kallithea/tests/models/test_notifications.py
diffstat 2 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/model/db.py	Thu Oct 08 23:27:41 2015 +0200
+++ b/kallithea/model/db.py	Tue Sep 08 19:43:29 2015 +0200
@@ -2412,11 +2412,15 @@
         notification.type_ = type_
         notification.created_on = datetime.datetime.now()
 
-        for u in recipients:
-            assoc = UserNotification()
-            assoc.notification = notification
-            assoc.user_id = u.user_id
-            Session().add(assoc)
+        for recipient in recipients:
+            un = UserNotification()
+            un.notification = notification
+            un.user_id = recipient.user_id
+            # Mark notifications to self "pre-read" - should perhaps just be skipped
+            if recipient == created_by:
+                un.read = True
+            Session().add(un)
+
         Session().add(notification)
         Session().flush() # assign notificaiton.notification_id
         return notification
--- a/kallithea/tests/models/test_notifications.py	Thu Oct 08 23:27:41 2015 +0200
+++ b/kallithea/tests/models/test_notifications.py	Tue Sep 08 19:43:29 2015 +0200
@@ -144,7 +144,7 @@
         Session().commit()
 
         self.assertEqual(NotificationModel()
-                         .get_unread_cnt_for_user(self.u1), 1)
+                         .get_unread_cnt_for_user(self.u1), 0)
         self.assertEqual(NotificationModel()
                          .get_unread_cnt_for_user(self.u2), 0)
         self.assertEqual(NotificationModel()
@@ -156,7 +156,7 @@
         Session().commit()
 
         self.assertEqual(NotificationModel()
-                         .get_unread_cnt_for_user(self.u1), 2)
+                         .get_unread_cnt_for_user(self.u1), 0)
         self.assertEqual(NotificationModel()
                          .get_unread_cnt_for_user(self.u2), 1)
         self.assertEqual(NotificationModel()