# HG changeset patch # User Søren Løvborg # Date 2015-09-08 19:43:29 # Node ID 786640c577f357f0aca9eba2398b710bdd8cd8c8 # Parent 87285c5007fbf014f7e8b391d8e3af66aa1e6d84 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. diff --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -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 diff --git a/kallithea/tests/models/test_notifications.py b/kallithea/tests/models/test_notifications.py --- a/kallithea/tests/models/test_notifications.py +++ b/kallithea/tests/models/test_notifications.py @@ -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()