diff --git a/files/classes/user.py b/files/classes/user.py index f420712e6..ecaa5fc17 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -441,13 +441,23 @@ class User(Base): @property @lazy def notifications_count(self): - notifs = g.db.query(Notification.user_id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0) + notifs = g.db.query(Notification.user_id).join(Comment).filter( + Notification.user_id == self.id, Notification.read == False, + Comment.is_banned == False, Comment.deleted_utc == 0) if not self.shadowbanned and self.admin_level < 3: notifs = notifs.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None) return notifs.count() + @property + @lazy + def normal_notifications_count(self): + return self.notifications_count \ + - self.post_notifications_count \ + - self.modaction_notifications_count \ + - self.reddit_notifications_count + @property @lazy def post_notifications_count(self): @@ -475,11 +485,29 @@ class User(Base): @property @lazy - def normal_count(self): - return self.notifications_count \ - - self.post_notifications_count \ - - self.modaction_notifications_count \ - - self.reddit_notifications_count + def notifications_do(self): + # only meaningful when notifications_count > 0; otherwise falsely '' ~ normal + if self.normal_notifications_count > 0: + return '' + elif self.post_notifications_count > 0: + return 'posts' + elif self.modaction_notifications_count > 0: + return 'modactions' + elif self.reddit_notifications_count > 0: + return 'reddit' + return '' + + @property + @lazy + def notifications_color(self): + colors = { + '': '#dc3545', + 'posts': '#0000ff', + 'modactions': '#e5990d', + 'reddit': '#805ad5', + } + return colors[self.notifications_do] if self.notifications_do \ + else colors[''] @property @lazy diff --git a/files/templates/header.html b/files/templates/header.html index 2d2dacf47..af842c3b7 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -68,7 +68,7 @@ {% if v %} {% if v.notifications_count %} - {{v.notifications_count}} + {{v.notifications_count}} {% else %} {% endif %} @@ -108,7 +108,7 @@ {% if v.notifications_count %} {% else %}