forked from rDrama/rDrama
Clarify notif color logic, extend to modaction.
Previously, notification bell linking & color logic was interspersed between templates and the user model. It doesn't _really_ belong in the user model, but it's been moved out of the templates to there to at least centralize it. This was also used as an opportunity to make the modactions inbox color the bell appropriately.master
parent
e578108903
commit
564f5b38f1
|
@ -441,13 +441,23 @@ class User(Base):
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def notifications_count(self):
|
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:
|
if not self.shadowbanned and self.admin_level < 3:
|
||||||
notifs = notifs.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
|
notifs = notifs.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
|
||||||
|
|
||||||
return notifs.count()
|
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
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def post_notifications_count(self):
|
def post_notifications_count(self):
|
||||||
|
@ -475,11 +485,29 @@ class User(Base):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def normal_count(self):
|
def notifications_do(self):
|
||||||
return self.notifications_count \
|
# only meaningful when notifications_count > 0; otherwise falsely '' ~ normal
|
||||||
- self.post_notifications_count \
|
if self.normal_notifications_count > 0:
|
||||||
- self.modaction_notifications_count \
|
return ''
|
||||||
- self.reddit_notifications_count
|
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
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
|
|
|
@ -68,7 +68,7 @@
|
||||||
|
|
||||||
{% if v %}
|
{% if v %}
|
||||||
{% if v.notifications_count %}
|
{% if v.notifications_count %}
|
||||||
<a class="mobile-nav-icon d-md-none" href="/notifications{% if v.do_posts %}?posts=true{% elif v.do_reddit %}?reddit=true{% endif %}" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Notifications"><i class="fas fa-bell align-middle text-danger" {% if v.do_posts %}style="color:blue!important"{% elif v.do_reddit %}style="color:#805ad5!important"{% endif %}></i><span class="notif-count ml-1" style="padding-left: 4.5px;{% if v.do_posts %}background:blue{% elif v.do_reddit %}background:#805ad5{% endif %}">{{v.notifications_count}}</span></a>
|
<a class="mobile-nav-icon d-md-none" href="/notifications{% if v.notifications_do %}?{{v.notifications_do}}=true{% endif %}" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Notifications"><i class="fas fa-bell align-middle" style="color: {{v.notifications_color}}"></i><span class="notif-count ml-1" style="padding-left: 4.5px;{% if v.notifications_do %}background:{{v.notifications_color}}{% endif %}">{{v.notifications_count}}</span></a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a class="mobile-nav-icon d-md-none" href="/notifications" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Notifications"><i class="fas fa-bell align-middle text-gray-500 black"></i></a>
|
<a class="mobile-nav-icon d-md-none" href="/notifications" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Notifications"><i class="fas fa-bell align-middle text-gray-500 black"></i></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -108,7 +108,7 @@
|
||||||
|
|
||||||
{% if v.notifications_count %}
|
{% if v.notifications_count %}
|
||||||
<li class="nav-item d-flex align-items-center text-center justify-content-center mx-1">
|
<li class="nav-item d-flex align-items-center text-center justify-content-center mx-1">
|
||||||
<a class="nav-link position-relative" href="/notifications{% if v.do_posts %}?posts=true{% elif v.do_reddit %}?reddit=true{% endif %}" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Notifications"><i class="fas fa-bell text-danger" {% if v.do_posts %}style="color:blue!important"{% elif v.do_reddit %}style="color:#805ad5!important"{% endif %}></i><span class="notif-count ml-1" style="padding-left: 4.5px;{% if v.do_posts %}background:blue{% elif v.do_reddit %}background:#805ad5{% endif %}">{{v.notifications_count}}</span></a>
|
<a class="nav-link position-relative" href="/notifications{% if v.notifications_do %}?{{v.notifications_do}}=true{% endif %}" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Notifications"><i class="fas fa-bell" style="color: {{v.notifications_color}}"></i><span class="notif-count ml-1" style="padding-left: 4.5px;{% if v.notifications_do %}background:{{v.notifications_color}}{% endif %}">{{v.notifications_count}}</span></a>
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="nav-item d-flex align-items-center text-center justify-content-center mx-1">
|
<li class="nav-item d-flex align-items-center text-center justify-content-center mx-1">
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
<ul class="nav settings-nav" style="padding:0 0 0 20px" id="notifications--nav-list">
|
<ul class="nav settings-nav" style="padding:0 0 0 20px" id="notifications--nav-list">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link py-3{% if not '=true' in request.full_path %} active{% endif %}" href="/notifications">
|
<a class="nav-link py-3{% if not '=true' in request.full_path %} active{% endif %}" href="/notifications">
|
||||||
All {% if v.normal_count %} <span class="font-weight-bold" style="color:red">({{v.normal_count}})</span>{% endif %}
|
All {% if v.normal_notifications_count %}<span class="font-weight-bold" style="color:#ff0000">({{v.normal_notifications_count}})</span>{% endif %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link py-3{% if '/notifications?posts=true' in request.full_path %} active{% endif %}" href="/notifications?posts=true">
|
<a class="nav-link py-3{% if '/notifications?posts=true' in request.full_path %} active{% endif %}" href="/notifications?posts=true">
|
||||||
Posts {% if v.post_notifications_count %}<span class="font-weight-bold" style="color:blue">({{v.post_notifications_count}})</span>{% endif %}
|
Posts {% if v.post_notifications_count %}<span class="font-weight-bold" style="color:#0000ff">({{v.post_notifications_count}})</span>{% endif %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
|
|
Loading…
Reference in New Issue