Changeset - 786640c577f3
[Not reviewed]
default
0 2 0
Søren Løvborg - 10 years ago 2015-09-08 19:43:29
sorenl@unity3d.com
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.
2 files changed with 11 insertions and 7 deletions:
0 comments (0 inline, 0 general)
kallithea/model/db.py
Show inline comments
 
@@ -2412,11 +2412,15 @@ class Notification(Base, BaseModel):
 
        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
kallithea/tests/models/test_notifications.py
Show inline comments
 
@@ -144,7 +144,7 @@ class TestNotifications(BaseTestCase):
 
        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 @@ class TestNotifications(BaseTestCase):
 
        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()
0 comments (0 inline, 0 general)