Allow selecting notification types to see

This commit is contained in:
Andrew Godwin 2022-12-05 22:14:50 -07:00
parent 64cea557be
commit b0929214d5
3 changed files with 63 additions and 13 deletions

View file

@ -161,9 +161,6 @@ class Federated(ListView):
@method_decorator(identity_required, name="dispatch") @method_decorator(identity_required, name="dispatch")
@method_decorator(
per_identity_cache_page("cache_timeout_page_timeline"), name="dispatch"
)
class Notifications(ListView): class Notifications(ListView):
template_name = "activities/notifications.html" template_name = "activities/notifications.html"
@ -172,18 +169,30 @@ class Notifications(ListView):
"allows_refresh": True, "allows_refresh": True,
} }
paginate_by = 50 paginate_by = 50
notification_types = {
"followed": TimelineEvent.Types.followed,
"boosted": TimelineEvent.Types.boosted,
"mentioned": TimelineEvent.Types.mentioned,
"liked": TimelineEvent.Types.liked,
}
def get_queryset(self): def get_queryset(self):
# Did they ask to change options?
notification_options = self.request.session.get("notification_options", {})
for type_name in self.notification_types:
notification_options.setdefault(type_name, True)
if self.request.GET.get(type_name) == "true":
notification_options[type_name] = True
elif self.request.GET.get(type_name) == "false":
notification_options[type_name] = False
self.request.session["notification_options"] = notification_options
# Return appropriate events
types = []
for type_name, type in self.notification_types.items():
if notification_options.get(type_name, True):
types.append(type)
return ( return (
TimelineEvent.objects.filter( TimelineEvent.objects.filter(identity=self.request.identity, type__in=types)
identity=self.request.identity,
type__in=[
TimelineEvent.Types.mentioned,
TimelineEvent.Types.boosted,
TimelineEvent.Types.liked,
TimelineEvent.Types.followed,
],
)
.order_by("-created")[:50] .order_by("-created")[:50]
.select_related("subject_post", "subject_post__author", "subject_identity") .select_related("subject_post", "subject_post__author", "subject_identity")
) )
@ -205,5 +214,7 @@ class Notifications(ListView):
): ):
events[-1].collapsed = True events[-1].collapsed = True
events.append(event) events.append(event)
# Retrieve what kinds of things to show
context["events"] = events context["events"] = events
context["notification_options"] = self.request.session["notification_options"]
return context return context

View file

@ -762,7 +762,7 @@ table.metadata td.name {
font-weight: bold; font-weight: bold;
} }
/* Named Timelines */ /* Timelines */
.left-column .timeline-name { .left-column .timeline-name {
margin: 0 0 10px 0; margin: 0 0 10px 0;
@ -774,6 +774,22 @@ table.metadata td.name {
margin-right: 10px margin-right: 10px
} }
.view-options {
margin: 0 0 10px 3px;
}
.view-options a {
margin: 0 10px 0 0;
padding: 4px 7px;
color: var(--color-text-duller);
background: var(--color-bg-box);
border-radius: 3px;
}
.view-options a.selected {
color: var(--color-text-main);
}
/* Posts */ /* Posts */
.post { .post {

View file

@ -3,6 +3,29 @@
{% block title %}Notifications{% endblock %} {% block title %}Notifications{% endblock %}
{% block content %} {% block content %}
<div class="view-options">
{% if notification_options.followed %}
<a href=".?followed=false" class="selected"><i class="fa-solid fa-check"></i> Followers</a>
{% else %}
<a href=".?followed=true"><i class="fa-solid fa-xmark"></i> Followers</a>
{% endif %}
{% if notification_options.boosted %}
<a href=".?boosted=false" class="selected"><i class="fa-solid fa-check"></i> Boosts</a>
{% else %}
<a href=".?boosted=true"><i class="fa-solid fa-xmark"></i> Boosts</a>
{% endif %}
{% if notification_options.liked %}
<a href=".?liked=false" class="selected"><i class="fa-solid fa-check"></i> Likes</a>
{% else %}
<a href=".?liked=true"><i class="fa-solid fa-xmark"></i> Likes</a>
{% endif %}
{% if notification_options.mentioned %}
<a href=".?mentioned=false" class="selected"><i class="fa-solid fa-check"></i> Mentions</a>
{% else %}
<a href=".?mentioned=true"><i class="fa-solid fa-xmark"></i> Mentions</a>
{% endif %}
</div>
{% for event in events %} {% for event in events %}
{% include "activities/_event.html" %} {% include "activities/_event.html" %}
{% empty %} {% empty %}