From c72893372afe255689ff56a618b6c849974569a3 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Mon, 28 Nov 2022 22:42:40 -0700 Subject: Collapse notifications on the same post --- activities/views/timelines.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'activities') 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 -- cgit v1.2.3