diff options
author | Andrew Godwin | 2022-11-28 22:42:40 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-28 22:42:40 -0700 |
commit | c72893372afe255689ff56a618b6c849974569a3 (patch) | |
tree | 47672b39bb34811b9448ffab8e6d373baec83086 /activities/views | |
parent | c857cd026f9b140e5613274a816ec742c7fc3ee4 (diff) | |
download | takahe-c72893372afe255689ff56a618b6c849974569a3.tar.gz takahe-c72893372afe255689ff56a618b6c849974569a3.tar.bz2 takahe-c72893372afe255689ff56a618b6c849974569a3.zip |
Collapse notifications on the same post
Diffstat (limited to 'activities/views')
-rw-r--r-- | activities/views/timelines.py | 20 |
1 files changed, 20 insertions, 0 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 |