summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-28 22:42:40 -0700
committerAndrew Godwin2022-11-28 22:42:40 -0700
commitc72893372afe255689ff56a618b6c849974569a3 (patch)
tree47672b39bb34811b9448ffab8e6d373baec83086
parentc857cd026f9b140e5613274a816ec742c7fc3ee4 (diff)
downloadtakahe-c72893372afe255689ff56a618b6c849974569a3.tar.gz
takahe-c72893372afe255689ff56a618b6c849974569a3.tar.bz2
takahe-c72893372afe255689ff56a618b6c849974569a3.zip
Collapse notifications on the same post
-rw-r--r--activities/views/timelines.py20
-rw-r--r--templates/activities/_event.html6
-rw-r--r--templates/activities/notifications.html2
3 files changed, 27 insertions, 1 deletions
diff --git a/activities/views/timelines.py b/activities/views/timelines.py
index 694039e..753add6 100644
--- a/activities/views/timelines.py
+++ b/activities/views/timelines.py
@@ -173,3 +173,23 @@ class Notifications(ListView):
.order_by("-created")[:50]
.select_related("subject_post", "subject_post__author", "subject_identity")
)
+
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data(**kwargs)
+ # Collapse similar notifications into one
+ events = []
+ for event in context["page_obj"]:
+ if (
+ events
+ and event.type
+ in [
+ TimelineEvent.Types.liked,
+ TimelineEvent.Types.boosted,
+ TimelineEvent.Types.mentioned,
+ ]
+ and event.subject_post_id == events[-1].subject_post_id
+ ):
+ events[-1].collapsed = True
+ events.append(event)
+ context["events"] = events
+ return context
diff --git a/templates/activities/_event.html b/templates/activities/_event.html
index c6d30b1..0c94aad 100644
--- a/templates/activities/_event.html
+++ b/templates/activities/_event.html
@@ -13,21 +13,27 @@
{{ event.subject_identity.name_or_handle }}
</a> liked your post
</div>
+ {% if not event.collapsed %}
{% include "activities/_post.html" with post=event.subject_post %}
+ {% endif %}
{% elif event.type == "mentioned" %}
<div class="mention-banner">
<a href="{{ event.subject_identity.urls.view }}">
{{ event.subject_identity.name_or_handle }}
</a> mentioned you
</div>
+ {% if not event.collapsed %}
{% include "activities/_post.html" with post=event.subject_post %}
+ {% endif %}
{% elif event.type == "boosted" %}
<div class="boost-banner">
<a href="{{ event.subject_identity.urls.view }}">
{{ event.subject_identity.name_or_handle }}
</a> boosted your post
</div>
+ {% if not event.collapsed %}
{% include "activities/_post.html" with post=event.subject_post %}
+ {% endif %}
{% else %}
Unknown event type {{event.type}}
{% endif %}
diff --git a/templates/activities/notifications.html b/templates/activities/notifications.html
index a9c51be..f34dc28 100644
--- a/templates/activities/notifications.html
+++ b/templates/activities/notifications.html
@@ -3,7 +3,7 @@
{% block title %}Notifications{% endblock %}
{% block content %}
- {% for event in page_obj %}
+ {% for event in events %}
{% include "activities/_event.html" %}
{% empty %}
No notirications yet.