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()