Collapse notifications on the same post
This commit is contained in:
parent
c857cd026f
commit
c72893372a
@ -173,3 +173,23 @@ class Notifications(ListView):
|
|||||||
.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")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
@ -13,21 +13,27 @@
|
|||||||
{{ event.subject_identity.name_or_handle }}
|
{{ event.subject_identity.name_or_handle }}
|
||||||
</a> liked your post
|
</a> liked your post
|
||||||
</div>
|
</div>
|
||||||
|
{% if not event.collapsed %}
|
||||||
{% include "activities/_post.html" with post=event.subject_post %}
|
{% include "activities/_post.html" with post=event.subject_post %}
|
||||||
|
{% endif %}
|
||||||
{% elif event.type == "mentioned" %}
|
{% elif event.type == "mentioned" %}
|
||||||
<div class="mention-banner">
|
<div class="mention-banner">
|
||||||
<a href="{{ event.subject_identity.urls.view }}">
|
<a href="{{ event.subject_identity.urls.view }}">
|
||||||
{{ event.subject_identity.name_or_handle }}
|
{{ event.subject_identity.name_or_handle }}
|
||||||
</a> mentioned you
|
</a> mentioned you
|
||||||
</div>
|
</div>
|
||||||
|
{% if not event.collapsed %}
|
||||||
{% include "activities/_post.html" with post=event.subject_post %}
|
{% include "activities/_post.html" with post=event.subject_post %}
|
||||||
|
{% endif %}
|
||||||
{% elif event.type == "boosted" %}
|
{% elif event.type == "boosted" %}
|
||||||
<div class="boost-banner">
|
<div class="boost-banner">
|
||||||
<a href="{{ event.subject_identity.urls.view }}">
|
<a href="{{ event.subject_identity.urls.view }}">
|
||||||
{{ event.subject_identity.name_or_handle }}
|
{{ event.subject_identity.name_or_handle }}
|
||||||
</a> boosted your post
|
</a> boosted your post
|
||||||
</div>
|
</div>
|
||||||
|
{% if not event.collapsed %}
|
||||||
{% include "activities/_post.html" with post=event.subject_post %}
|
{% include "activities/_post.html" with post=event.subject_post %}
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
Unknown event type {{event.type}}
|
Unknown event type {{event.type}}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{% block title %}Notifications{% endblock %}
|
{% block title %}Notifications{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% for event in page_obj %}
|
{% for event in events %}
|
||||||
{% include "activities/_event.html" %}
|
{% include "activities/_event.html" %}
|
||||||
{% empty %}
|
{% empty %}
|
||||||
No notirications yet.
|
No notirications yet.
|
||||||
|
Reference in New Issue
Block a user